12 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
14 usage =
"usage: perf script report compaction-times.py -- [-h] [-u] [-p|-pv] [-t | [-m] [-fs] [-ms]] [pid|pid-range|comm-regex]\n" 33 m = self.
re.search(comm)
34 return m ==
None or m.group() ==
"" 38 self.
low = (0
if low ==
"" else int(low))
39 self.
high = (0
if high ==
"" else int(high))
42 return not (pid >= self.
low and (self.
high == 0
or pid <= self.
high))
46 opt_disp = (t
if opt_disp == topt.DISP_ALL
else opt_disp|t)
49 return (sec * 1000000000) + nsec
52 return "%dns" % ns
if opt_ns
else "%dus" % (round(ns, -3) / 1000)
55 def __init__(self, aval, bval, alabel = None, blabel = None):
79 self.
fscan += rhs.fscan
80 self.
mscan += rhs.mscan
86 if (opt_disp & topt.DISP_MIG):
89 if (opt_disp & topt.DISP_ISOLFREE):
90 s +=
"%sfree_scanner: %s" % (
" " if prev
else "", self.
fscan)
92 if (opt_disp & topt.DISP_ISOLMIG):
93 s +=
"%smigration_scanner: %s" % (
" " if prev
else "", self.
mscan)
97 self.
ns =
ns(secs, nsecs) - self.
ns 100 if (migrated !=
None):
121 head = cls.
heads[pid]
122 filtered = head.is_filtered()
126 head = cls.
heads[pid] =
chead(comm, pid, filtered)
129 head.mark_pending(start_secs, start_nsecs)
133 head = cls.
heads[pid]
134 if not head.is_filtered():
135 if head.is_pending():
136 head.do_increment(migrated, fscan, mscan)
138 sys.stderr.write(
"missing start compaction event for pid %d\n" % pid)
142 head = cls.
heads[pid]
143 if not head.is_filtered():
144 if head.is_pending():
145 head.make_complete(secs, nsecs)
147 sys.stderr.write(
"missing start compaction event for pid %d\n" % pid)
151 if opt_proc != popt.DISP_DFL:
176 self.
pending.increment(migrated, fscan, mscan)
179 self.
pending.complete(secs, nsecs)
182 if opt_proc != popt.DISP_DFL:
185 if opt_proc == popt.DISP_PROC_VERBOSE:
190 if opt_proc == popt.DISP_PROC_VERBOSE
and not self.
is_filtered():
192 sys.stdout.write(
"%d[%s].%d: %s\n" % (self.
pid, self.
comm, i+1, pelem))
202 sys.stdout.write(
"%d[%s]: %s\n" % (self.
pid, self.
comm, self.
val))
206 sys.stdout.write(
"total: %s\n" % chead.str())
207 for i
in chead.gen():
212 common_secs, common_nsecs, common_pid, common_comm,
213 common_callchain, nr_migrated, nr_failed):
215 chead.increment_pending(common_pid,
216 pair(nr_migrated, nr_failed),
None,
None)
219 common_secs, common_nsecs, common_pid, common_comm,
220 common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken):
222 chead.increment_pending(common_pid,
223 None,
pair(nr_scanned, nr_taken),
None)
226 common_secs, common_nsecs, common_pid, common_comm,
227 common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken):
229 chead.increment_pending(common_pid,
230 None,
None,
pair(nr_scanned, nr_taken))
233 common_secs, common_nsecs, common_pid, common_comm,
234 common_callchain, zone_start, migrate_start, free_start, zone_end,
237 chead.complete_pending(common_pid, common_secs, common_nsecs)
240 common_secs, common_nsecs, common_pid, common_comm,
241 common_callchain, zone_start, migrate_start, free_start, zone_end,
244 chead.create_pending(common_pid, common_comm, common_secs, common_nsecs)
249 sys.stdout.write(usage)
250 sys.stdout.write(
"\n")
251 sys.stdout.write(
"-h display this help\n")
252 sys.stdout.write(
"-p display by process\n")
253 sys.stdout.write(
"-pv display by process (verbose)\n")
254 sys.stdout.write(
"-t display stall times only\n")
255 sys.stdout.write(
"-m display stats for migration\n")
256 sys.stdout.write(
"-fs display stats for free scanner\n")
257 sys.stdout.write(
"-ms display stats for migration scanner\n")
258 sys.stdout.write(
"-u display results in microseconds (default nanoseconds)\n")
263 pid_regex =
"^(\d*)-(\d*)$|^(\d*)$" 265 opt_proc = popt.DISP_DFL
266 opt_disp = topt.DISP_ALL
270 argc = len(sys.argv) - 1
272 pid_re = re.compile(pid_regex)
274 for i, opt
in enumerate(sys.argv[1:]):
280 opt_proc = popt.DISP_PROC
282 opt_proc = popt.DISP_PROC_VERBOSE
297 m = pid_re.search(opt)
298 if m !=
None and m.group() !=
"":
299 if m.group(3) !=
None:
305 comm_re=re.compile(opt)
307 sys.stderr.write(
"invalid regex '%s'" % opt)
def compaction__mm_compaction_begin(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, zone_start, migrate_start, free_start, zone_end, sync)
def __init__(self, low, high)
def complete_pending(cls, pid, secs, nsecs)
def compaction__mm_compaction_end(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, zone_start, migrate_start, free_start, zone_end, sync, status)
def increment_pending(cls, pid, migrated, fscan, mscan)
def compaction__mm_compaction_isolate_freepages(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken)
def filter(self, pid, comm)
def __init__(self, comm, pid, filtered)
def increment(self, migrated, fscan, mscan)
def do_increment(self, migrated, fscan, mscan)
def complete(self, secs, nsecs)
struct strfilter * filter
def filter(self, pid, comm)
def __init__(self, aval, bval, alabel=None, blabel=None)
def create_pending(cls, pid, comm, start_secs, start_nsecs)
def mark_pending(self, secs, nsecs)
def make_complete(self, secs, nsecs)
def compaction__mm_compaction_isolate_migratepages(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken)
def compaction__mm_compaction_migratepages(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, nr_migrated, nr_failed)
def add_filter(cls, filter)