Lines Matching +full:min +full:- +full:sample +full:- +full:time +full:- +full:ns
1 # task-analyzer.py - comprehensive perf tasks analysis
2 # SPDX-License-Identifier: GPL-2.0
8 # perf record -e sched:sched_switch -a -- sleep 10
9 # perf script report task-analyzer
21 os.environ["PERF_EXEC_PATH"] + "/scripts/python/Perf-Trace-Util/lib/Perf/Trace"
44 LEN_COMM = len("max-comms-length") # 16
75 """user enforced no-color or if stdout is no tty we disable colors"""
93 "--time-limit",
96 "print tasks only in time[s] window e.g"
97 " --time-limit 123.111:789.222(print all between 123.111 and 789.222)"
98 " --time-limit 123: (print all from 123)"
99 " --time-limit :456 (print all until incl. 456)",
102 "--summary", action="store_true", help="print addtional runtime information"
105 "--summary-only", action="store_true", help="print only summary without traces"
108 "--summary-extended",
114 "--ns", action="store_true", help="show timestamps in nanoseconds"
117 "--ms", action="store_true", help="show timestamps in milliseconds"
120 "--extended-times",
127 "--filter-tasks",
130 " E.g --filter-task 1337,/sbin/init ",
133 "--limit-to-tasks",
136 " E.g --limit-to-tasks 1337,/sbin/init",
139 "--highlight-tasks",
142 " E.g. --highlight-tasks 1:red,mutt:yellow"
146 "--rename-comms-by-tids",
150 " process. E.g --rename 1337:my-python-app",
153 "--stdio-color",
160 "--csv",
162 help="Write trace to file selected by user. Options, like --ns or --extended"
163 "-times are used.",
166 "--csv-summary",
168 help="Write summary to file selected by user. Options, like --ns or"
169 " --summary-extended are used.",
183 "ns": 1e9,
198 # min values for summary depending on the header
206 db["runtime_info"]["min"] = len("Min")
211 db["inter_times"]["out_in"] = len("Out-In")
213 db["inter_times"]["out_out"] = len("Out-Out")
214 db["inter_times"]["in_in"] = len("In-In")
215 db["inter_times"]["in_out"] = len("In-Out")
219 """phython3 hat statistics module - we have nothing"""
224 return sum(sorted(numbers)[index - 1 : index + 1]) / 2
233 The elapsed time between two occurrences of the same task is being tracked with the
234 help of this class. There are 4 of those Timespans Out-Out, In-Out, Out-In and
235 In-In.
236 The first half of the name signals the first time point of the
244 self.out_out = -1
245 self.in_out = -1
246 self.out_in = -1
247 self.in_in = -1
249 self._time_in = -1
250 self.max_out_in = -1
251 self.max_at = -1
252 self.max_in_out = -1
253 self.max_in_in = -1
254 self.max_out_out = -1
268 self.in_in = time_in - self._last_start
269 self.out_in = time_in - self._last_finish
270 self.in_out = time_out - self._last_start
271 self.out_out = time_out - self._last_finish
305 median, min, max, max_at): argument
313 self.min = min
329 decimal_precision = 6 if not args.ns else 9
332 sum(db["runtime_info"].values()) - 2 * decimal_precision
338 sum(db["inter_times"].values()) - 4 * decimal_precision
362 separator, (db["runtime_info"]["min"] - decimal_precision) * fix_csv_align
365 separator, (db["runtime_info"]["max"] - decimal_precision) * fix_csv_align
368 separator, (db["runtime_info"]["max_at"] - time_precision) * fix_csv_align
372 column_titles += ("Runs", "Accumulated", "Mean", "Median", "Min", "Max")
378 (db["inter_times"]["out_in"] - decimal_precision) * fix_csv_align
382 (db["inter_times"]["inter_at"] - time_precision) * fix_csv_align
386 (db["inter_times"]["out_out"] - decimal_precision) * fix_csv_align
390 (db["inter_times"]["in_in"] - decimal_precision) * fix_csv_align
394 (db["inter_times"]["in_out"] - decimal_precision) * fix_csv_align
397 column_titles += ("Out-In", _COLORS["grey"], "Max At", _COLORS["reset"],
398 "Out-Out", "In-In", "In-Out")
423 time_min = min(runtimes)
439 self._body[-1].extend([timespans.max_out_in,
461 len_min = (db["runtime_info"]["min"] - decimal_precision) * fix_csv_align
462 len_max = (db["runtime_info"]["max"] - decimal_precision) * fix_csv_align
463 len_max_at = (db["runtime_info"]["max_at"] - time_precision) * fix_csv_align
466 db["inter_times"]["out_in"] - decimal_precision
469 db["inter_times"]["inter_at"] - time_precision
472 db["inter_times"]["out_out"] - decimal_precision
474 len_in_in = (db["inter_times"]["in_in"] - decimal_precision) * fix_csv_align
476 db["inter_times"]["in_out"] - decimal_precision
543 def schedule_in_at(self, time): argument
544 """set the time where the task was scheduled in"""
545 self._time_in = time
547 def schedule_out_at(self, time): argument
548 """set the time where the task was scheduled out"""
549 self._time_out = time
552 """return time where a given task was scheduled out"""
557 """return time where a given task was scheduled in"""
563 return (self._time_out - self._time_in) * decimal.Decimal(factor)
570 """returns a "unique-enough" identifier, please do not change"""
571 return "{}-{}".format(pid, cpu)
629 header = ("Switched-In", "Switched-Out", "CPU", "PID", "TID", "Comm", "Runtime",
630 "Time Out-In")
632 header += ("Time Out-Out", "Time In-In", "Time In-Out")
641 out_in = -1
642 out_out = -1
643 in_in = -1
644 in_out = -1
654 # grey-out entries if PID == TID, they
664 last_tid_task = db["tid"][task.tid][-1]
693 no need to store more then one element if --summarize
697 _list = _list[len(_list) - 1 :]
722 def _handle_task_finish(tid, cpu, time, perf_sample_dict): argument
728 # event. Seen in combination with --exclude-perf
730 # switched in. Probably a bug in exclude-perf
734 task.schedule_out_at(time)
738 pid = int(perf_sample_dict["sample"]["pid"])
752 def _handle_task_start(tid, cpu, comm, time): argument
760 # are switched-to again - saw this via --exclude-perf
766 task.schedule_in_at(time)
792 sys.exit("Error: Filter and Limit at the same time active.")
797 "Error: No bound set for time limit. Please set bound by ':' e.g :123."
800 sys.exit("Error: Cannot set time limit and print summary")
806 sys.exit("Error: No file chosen to write summary to. Choose with --csv-summary "
809 sys.exit("Error: --csv chosen and --summary-only. Standard task would not be"
840 if args.ns:
841 time_unit = "ns"
861 def _is_within_timelimit(time): argument
863 Check if a time limit was given by parameter, if so ignore the rest. If not,
872 if time >= decimal.Decimal(lower_time_limit):
876 if time <= decimal.Decimal(upper_time_limit):
878 # quit if time exceeds upper limit. Good for big datasets
882 if (time >= decimal.Decimal(lower_time_limit) and
883 time <= decimal.Decimal(upper_time_limit)):
885 # quit if time exceeds upper limit. Good for big datasets
886 elif time > decimal.Decimal(upper_time_limit):
892 if args.ns:
927 time = _time_to_internal(perf_sample_dict["sample"]["time"])
928 if not _is_within_timelimit(time):
929 # user specific --time-limit a:b set
933 _handle_task_finish(prev_pid, common_cpu, time, perf_sample_dict)
934 _handle_task_start(next_pid, common_cpu, next_comm, time)