Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
perf scriptでオレオレスクリプトを走らせるサンプル
# perf script event handlers, generated by perf script -g python
# Licensed under the terms of the GNU GPL License version 2
# The common_* event handler fields are the most useful fields common to
# all events. They don't necessarily correspond to the 'common_*' fields
# in the format files. Those fields not available as handler params can
# be retrieved using Python functions of the form common_*(context).
# See the perf-trace-python Documentation for the list of available functions.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
trace_start_time = -1
trace_end_time = -1
log = {}
def convert_time(sec, nsec):
return float("{sec}.{nsec}".format(sec=sec, nsec=nsec))
class RuntimeAggregator:
def __init__(self,core_id, pid, comm):
self.core_id = core_id
self.pid = pid
self.comm = comm
self.total_runtime = 0
self.average_runtime = 0
def update_runtime(self,runtime):
self.total_runtime += runtime
def update_average_runtime(self,duration):
self.average_runtime = self.total_runtime / 10e6 / duration
def print_result(self):
print "{comm}(pid={pid}): total_runtime = {total} ms, average_runtime = {avg} ms".format( \
comm=self.comm, pid=self.pid, total=self.total_runtime / 10e6, avg=self.average_runtime)
def trace_begin():
print "in trace_begin"
def trace_end():
global trace_start_time, trace_end_time, log
for k, v in log.items():
v.update_average_runtime(trace_end_time - trace_start_time)
v.print_result()
print "in trace_end", "total duration = {sec}sec".format(sec=trace_end_time-trace_start_time)
def sched__sched_stat_runtime(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, comm, pid, runtime, vruntime):
global trace_start_time, trace_end_time, log
tmp = convert_time(common_secs, common_nsecs)
if trace_start_time == -1:
trace_start_time = tmp
if trace_end_time == -1:
trace_end_time = tmp
else:
trace_end_time = tmp if trace_end_time < tmp else trace_end_time
agg = log.get(pid, RuntimeAggregator(common_cpu, pid, comm))
agg.update_runtime(runtime)
log[pid] = agg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.