Skip to content

Instantly share code, notes, and snippets.

@giraldeau
Created December 5, 2016 20:35
Show Gist options
  • Save giraldeau/c1d3cf44df317d83d7bf44956887c5d1 to your computer and use it in GitHub Desktop.
Save giraldeau/c1d3cf44df317d83d7bf44956887c5d1 to your computer and use it in GitHub Desktop.
#!/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)
@shashwatpandey221091
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment