Skip to content
Snippets Groups Projects
Commit 3cc2c305 authored by Guy Zana's avatar Guy Zana
Browse files

post-processing: (scheduler) visually view a histogram of threads' time-slices

parent 3109fd93
No related branches found
No related tags found
No related merge requests found
Thread time-slice histogram
===========================
Use this tool to investigate the time-slices of threads in OSv.
HOW-TO:
1. Start OSv with --trace=sched_switch
2. Run your test
3. Connect with gdb and perform:
(gdb) connect
(gdb) logtrace // this will dump the sched_switch tracepoints to gdb.txt
4. Run trace_sched_timings.py, it will analyze gdb.txt and write a new text file for each thread
that was scheduled during the tracepoint snapshot, the new files will contain histogram of
time slices.
5. Run histo.py for to graph the results visually
import sys
import numpy as np
import matplotlib.pyplot as plt
import scipy
from collections import Counter
lines = file(sys.argv[1], "rt").readlines()
s = map(lambda x: int(x.strip("\n")), lines)
avg = np.mean(s)
cnt = len(s)
print "%s avg=%d(us) cnt=%d" % (sys.argv[1], avg, cnt)
plt.hist(s, bins=60)
plt.show()
import re
import os
import sys
l = file("gdb.txt", "rt").readlines()
# thread->[(time, duration), ...]
threads = {}
# thread -> time of schedule-in
sched = {}
for tr in l:
(threadp, cpu, sec, microsec, event, info) = re.match("(0x.*?)\s+([0-9]+)\s+([0-9]+)\.([0-9]+)\s+(\S+)\s+(.*)\n", tr).groups()
sec = int(sec)
microsec = int(microsec)
if (event == "sched_switch"):
fromm = threadp
if (sched.has_key(fromm)):
if (not threads.has_key(fromm)):
threads[fromm] = []
threads[fromm] += [(sec - sched[fromm][0], microsec - sched[fromm][1])]
del sched[fromm]
to = re.match("to (.*)", info).group(1)
assert (not sched.has_key(to))
sched[to] = (sec, microsec)
for tr in threads:
f = file("thread_%s_timings.txt" % tr, "wt")
for timing in threads[tr]:
f.write("%d\n" % (timing[0]*1000000 + timing[1]))
f.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment