linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yordan Karadzhov <y.karadz@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH 1/9] trace-cruncher: Refactor the part that wraps ftrace
Date: Wed, 21 Apr 2021 18:41:21 +0300	[thread overview]
Message-ID: <9ee66a06-cdc0-7dd4-8c5f-39493e64aef4@gmail.com> (raw)
In-Reply-To: <20210420221340.65c89491@oasis.local.home>

Hi Steven,

Thanks a lot for the review!

I will add all your fixes in v2.


On 21.04.21 г. 5:13, Steven Rostedt wrote:
>> +}
>> +
>> +static void start_tracing(struct tracefs_instance *instance,
>> +			  char **argv, char **env)
>> +{
>> +	if(tracefs_option_enable(instance, TRACEFS_OPTION_EVENT_FORK) < 0 ||
>> +	   tracefs_option_enable(instance, TRACEFS_OPTION_FUNCTION_FORK) < 0 ||
>> +	   !set_pid(instance, "set_ftrace_pid", getpid()) ||
>> +	   !set_pid(instance, "set_event_pid", getpid()))
>> +		exit(1);
> So trace cruncher will only trace the given process and its children.
> There's no other alternative?
> 

Of course not. This is just a static helper function that is used by the 
trace_shell_process(). It has no exposure to the user of the module.

trace_shell_process() on the other hand is part of the API of the module 
and indeed will trace only one process.

It is just the first method to be implemented. You will see more methods 
for tracing in the incoming patches.

But you are right that I have to rename start_tracing(), so that it 
doesn't sound like something that has a more general use.


Thanks!

Yordan




> -- Steve
> 
> 
> 
>> +
>> +	tracing_ON(instance);
>> +	if (execve(argv[0], argv, env) < 0) {
>> +		PyErr_Format(TFS_ERROR, "Failed to exec \'%s\'",
>> +			     argv[0]);
>> +	}
>> +
>> +	exit(1);
>> +}
>> +
>> +static int callback(struct tep_event *event, struct tep_record *record,
>> +		    int cpu, void *py_func)
>> +{
>> +	record->cpu = cpu; // Remove when the bug in libtracefs is fixed.
>> +
>> +	PyObject *py_tep_event = PyTepEvent_New(event);
>> +	PyObject *py_tep_record = PyTepRecord_New(record);
>> +
>> +	PyObject *arglist = PyTuple_New(2);
>> +	PyTuple_SetItem(arglist, 0, py_tep_event);
>> +	PyTuple_SetItem(arglist, 1, py_tep_record);
>> +
>> +	PyObject_CallObject((PyObject *) py_func, arglist);
>> +
>> +	return 0;
>> +}
>> +
>> +PyObject *PyFtrace_trace_shell_process(PyObject *self, PyObject *args,
>> +						       PyObject *kwargs)
>> +{
>> +	const char *plugin = "__main__", *py_callback = "callback";
>> +	char *process, *instance_name;
>> +	struct tracefs_instance *instance;
>> +	static char *kwlist[] = {"process", "plugin", "callback", "instance", NULL};
>> +	struct tep_handle *tep;
>> +	PyObject *py_func;
>> +	pid_t pid;
>> +
>> +	instance_name = NO_ARG;
>> +	if(!PyArg_ParseTupleAndKeywords(args,
>> +					kwargs,
>> +					"s|sss",
>> +					kwlist,
>> +					&process,
>> +					&plugin,
>> +					&py_callback,
>> +					&instance_name)) {
>> +		return NULL;
>> +	}
>> +
>> +	py_func = get_callback_func(plugin, py_callback);
>> +	if (!py_func)
>> +		return NULL;
>> +
>> +	if (!get_optional_instance(instance_name, &instance))
>> +		return NULL;
>> +
>> +	tep = tracefs_local_events(tracefs_instance_get_dir(instance));
>> +
>> +	char *argv[] = {getenv("SHELL"), "-c", process, NULL};
>> +	char *env[] = {NULL};
>> +
>> +	pid = fork();
>> +	if (pid < 0) {
>> +		PyErr_SetString(TFS_ERROR, "Failed to fork");
>> +		return NULL;
>> +	}
>> +
>> +	if (pid == 0)
>> +		start_tracing(instance, argv, env);
>> +
>> +	do {
>> +		tracefs_iterate_raw_events(tep, instance, NULL, 0, callback, py_func);
>> +	} while (waitpid(pid, NULL, WNOHANG) != pid);
>> +
>> +	Py_RETURN_NONE;
>> +}
>> +

  reply	other threads:[~2021-04-21 15:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 13:01 [PATCH 0/9] Build trace-cruncher as Python pakage Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 1/9] trace-cruncher: Refactor the part that wraps ftrace Yordan Karadzhov (VMware)
2021-04-21  2:13   ` Steven Rostedt
2021-04-21 15:41     ` Yordan Karadzhov [this message]
2021-04-19 13:01 ` [PATCH 2/9] trace-cruncher: Refactor the part that wraps libkshark Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 3/9] trace-cruncher: Add "utils" Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 4/9] trace-cruncher: Refactor the examples Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 5/9] trace-cruncher: Add Makefile Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 6/9] trace-cruncher: Update README.md Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 7/9] trace-cruncher: Remove all leftover files Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 8/9] trace-cruncher: Add testing Yordan Karadzhov (VMware)
2021-04-19 13:01 ` [PATCH 9/9] trace-cruncher: Add github workflow for CI testing Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ee66a06-cdc0-7dd4-8c5f-39493e64aef4@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).