-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a read_trace_fields() Python function #149
Comments
Add trace_readline_fields helper to parse the output of trace_pipe Add field parsing support to trace_print. Addresses #149. Fix typo in trace_open s/trace/tracefile/ Make nonblocking=False the default in trace_readline Use IOError vs BlockingIOError for greater compatibility (untested) Fixes: #149 Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
I added the suggested change, as well as an option to trace_print: b.trace_print(fmt='{{"pid":{1}, "msg":"{5}"}}') sudo ./hello_world.py
{"pid":1118, "msg":"Hello, World!"}
{"pid":1118, "msg":"Hello, World!"}
{"pid":8696, "msg":"Hello, World!"} |
Thanks, trace_readline_fields() works for me. I'm not sure about the fmt= option's stability. Eg, the number of fields have changed in the past, which if it happened again would break indexes. But that's probably very unlikely... Here's an example of using the new function (disksnoop.py): Before: while 1:
try:
line = trace.readline().rstrip()
except KeyboardInterrupt:
pass; exit()
prolog, time_s, colon, bytes_s, flags_s, us_s = \
line.rsplit(" ", 5)
time_s = time_s[:-1] # strip trailing ":" After: while 1:
(task, pid, cpu, flags, ts, msg) = b.trace_readline_fields()
(bytes_s, bflags_s, us_s) = msg.split() So that's getting much better. And this should be commonly used. Maybe as a follow on issue, we could have trace_readline_fields() split the msg on whitespace, so the above could be one line. I also think this may be better called just trace_fields(). |
Shortening to trace_fields is fine to me. Splitting msg doesn't seem right to me, since the formatting of msg is completely up to the user...trace_fields() can't know to split or not to split. |
* Per suggestion in #149 Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
* Per suggestion in iovisor#149 Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
As a follow on from #136, a function could be added that returned the fields printed by bpf_trace_printk(). Eg, so one can use:
This is slightly harder than it sounds: I believe the task name can contain spaces.
The text was updated successfully, but these errors were encountered: