new file mode 100755
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+
+""" The license to be determined !!!!
+"""
+
+import json
+import sys
+
+import matplotlib.pyplot as plt
+import scipy.stats as st
+import numpy as np
+
+import ksharkpy as ks
+
+fname = str(sys.argv[1])
+
+ks.open_file(fname)
+
+# We do not need the Process Ids of the records.
+# Do not load the "pid" data.
+data = ks.load_data(pid_data=False)
+
+tasks = ks.get_tasks()
+task_pid = tasks['pulseaudio']
+
+# Get the Event Ids of the sched_switch and sched_waking events.
+ss_eid = ks.event_id('sched', 'sched_switch')
+w_eid = ks.event_id('sched', 'sched_waking')
+
+# Gey the size of the data.
+i = data['offset'].size
+
+dt = []
+delta_max = i_ss_max = i_sw_max = 0
+
+while i > 0:
+ i = i - 1
+ if data['event'][i] == ss_eid:
+ next_pid = ks.read_event_field(offset=data['offset'][i],
+ event_id=ss_eid,
+ field='next_pid')
+
+ if next_pid == task_pid:
+ time_ss = data['time'][i]
+ index_ss = i
+
+ while i > 0:
+ i = i - 1
+ if (data['event'][i] == w_eid):
+ waking_pid = ks.read_event_field(offset=data['offset'][i],
+ event_id=w_eid,
+ field='pid')
+
+ if waking_pid == task_pid:
+ delta = (time_ss - data['time'][i]) / 1000.
+ # print(delta)
+ dt.append(delta)
+ if delta > delta_max:
+ print('lat. max: ', delta)
+ i_ss_max = index_ss
+ i_sw_max = i
+ delta_max = delta
+
+ break
+
+desc = st.describe(np.array(dt))
+print(desc)
+
+fig, ax = plt.subplots(nrows=1, ncols=1)
+fig.set_figheight(6)
+fig.set_figwidth(7)
+
+rect = fig.patch
+rect.set_facecolor('white')
+
+ax.set_xlabel('latency [$\mu$s]')
+plt.yscale('log')
+ax.hist(dt, bins=(200), histtype='step')
+plt.show()
+
+sname = 'sched.json'
+ks.new_session(fname, sname)
+
+with open(sname, 'r+') as s:
+ session = json.load(s)
+ session['TaskPlots'] = [task_pid]
+ session['CPUPlots'] = [
+ int(data['cpu'][i_sw_max]),
+ int(data['cpu'][i_ss_max])]
+
+ delta = data['time'][i_ss_max] - data['time'][i_sw_max]
+ tmin = int(data['time'][i_sw_max] - delta)
+ tmax = int(data['time'][i_ss_max] + delta)
+ session['Model']['range'] = [tmin, tmax]
+
+ session['Markers']['markA']['isSet'] = True
+ session['Markers']['markA']['row'] = int(i_sw_max)
+
+ session['Markers']['markB']['isSet'] = True
+ session['Markers']['markB']['row'] = int(i_ss_max)
+
+ session['ViewTop'] = int(i_sw_max) - 5
+
+ ks.save_session(session, s)
+
+ks.close()
The example script plots the distribution (histogram) of the pulseaudio wake-up times and finds the biggest latency. The script also generates a KernelShark session descriptor file (JSON). The session descriptor file can be used by the KernelSherk GUI to open a session which will directly visualize the largest wake-up latency. Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com> --- kernel-shark/bin/sched_wakeup.py | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 kernel-shark/bin/sched_wakeup.py