-
-
Save abenbachir/999a77833e07eb767100a9fcc96b67ac to your computer and use it in GitHub Desktop.
add list, show and status features
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 | |
import sh | |
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") | |
def show_trace(args): | |
print sh.cat(t+"/trace") | |
def list_options(args): | |
print sh.ls(t) | |
def status(args): | |
current_tracer = sh.cat(t+"/current_tracer").strip() | |
is_enabled = sh.cat(t+"/tracing_on").strip() == "1" | |
print "current_tracer", current_tracer, ("enabled" if is_enabled else "disabled") | |
def main(): | |
cmds = { "enable": enable_ftrace, | |
"disable": disable_ftrace, | |
"show": show_trace, | |
"list": list_options, | |
"status": status | |
} | |
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) | |
if __name__=="__main__": | |
if os.getuid() != 0: | |
print("Administrator privilege required, please use sudo") | |
else: | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment