Skip to content

Instantly share code, notes, and snippets.

@tiran
Created August 30, 2019 11:43
Show Gist options
  • Select an option

  • Save tiran/68e7e741cbe4f493ee990011ea0d0881 to your computer and use it in GitHub Desktop.

Select an option

Save tiran/68e7e741cbe4f493ee990011ea0d0881 to your computer and use it in GitHub Desktop.
Python import time SystemTap
# Christian Heimes <christian@python.org>
# https://docs.python.org/3/howto/instrumentation.html?highlight=dtrace#c.import__find__load__start
# https://speakerdeck.com/tiran/europython-2019-introduction-to-low-level-profiling-and-tracing?slide=64
global depths = 0;
global timing
probe process("python3").library("libpython3.7m.so.1.0").mark("import__find__load__start") {
modname = user_string($arg1);
now = local_clock_ns()
timing[tid(), depths] = now
printf("[%ld] %*s* Importing '%s' ...\n", now, 2*depths, "", modname);
depths++;
}
probe process("python3").library("libpython3.7m.so.1.0").mark("import__find__load__done") {
modname = user_string($arg1);
found = $arg2;
depths--;
now = local_clock_ns()
dur = now - timing[tid(), depths]
if (found)
printf("[%ld] %*s+ Imported '%s' in %ldus\n", local_clock_ns(), 2*depths, "", modname, dur/1000);
else
printf("[%ld] %*s- Failed '%s' in %ldus\n", local_clock_ns(), 2*depths, "", modname, dur/1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment