Created
December 5, 2016 20:35
-
-
Save giraldeau/c1d3cf44df317d83d7bf44956887c5d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import os | |
t = "/sys/kernel/debug/tracing" | |
def write_to(base, name, data): | |
with open(os.path.join(base, name), "w") as f: | |
f.write(data) | |
def enable_ftrace(args): | |
write_to(t, "current_tracer", "function_graph") | |
write_to(t, "set_graph_function", "vfs_fstat") | |
write_to(t, "tracing_on", "1") | |
def disable_ftrace(args): | |
write_to(t, "tracing_on", "0") | |
if __name__=="__main__": | |
cmds = { "enable": enable_ftrace, | |
"disable": disable_ftrace, | |
} | |
def not_a_command(args): | |
print("unkown command") | |
parser = argparse.ArgumentParser() | |
parser.add_argument("cmd") | |
args = parser.parse_args() | |
c = cmds.get(args.cmd, not_a_command) | |
c(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
while executing this "python ftrace_in_python.py ls", I am getting unknown command. I am willing to ftrace the "ls" command.
Little help will be appreciated, thanks in advance.