Lines Matching +full:up +full:- +full:samples
1 // SPDX-License-Identifier: GPL-2.0
50 int *samples; member
68 * osnoise_free_histogram - free runtime data
76 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_free_histogram()
77 if (data->hist[cpu].samples) in osnoise_free_histogram()
78 free(data->hist[cpu].samples); in osnoise_free_histogram()
82 if (data->hist) in osnoise_free_histogram()
83 free(data->hist); in osnoise_free_histogram()
89 * osnoise_alloc_histogram - alloc runtime data
101 data->entries = entries; in osnoise_alloc_histogram()
102 data->bucket_size = bucket_size; in osnoise_alloc_histogram()
103 data->nr_cpus = nr_cpus; in osnoise_alloc_histogram()
105 data->hist = calloc(1, sizeof(*data->hist) * nr_cpus); in osnoise_alloc_histogram()
106 if (!data->hist) in osnoise_alloc_histogram()
110 data->hist[cpu].samples = calloc(1, sizeof(*data->hist->samples) * (entries + 1)); in osnoise_alloc_histogram()
111 if (!data->hist[cpu].samples) in osnoise_alloc_histogram()
117 data->hist[cpu].min_sample = ~0; in osnoise_alloc_histogram()
129 struct osnoise_hist_params *params = tool->params; in osnoise_hist_update_multiple()
130 struct osnoise_hist_data *data = tool->data; in osnoise_hist_update_multiple()
132 int entries = data->entries; in osnoise_hist_update_multiple()
136 if (params->output_divisor) in osnoise_hist_update_multiple()
137 duration = duration / params->output_divisor; in osnoise_hist_update_multiple()
139 bucket = duration / data->bucket_size; in osnoise_hist_update_multiple()
143 hist = data->hist[cpu].samples; in osnoise_hist_update_multiple()
144 data->hist[cpu].count += count; in osnoise_hist_update_multiple()
145 update_min(&data->hist[cpu].min_sample, &duration); in osnoise_hist_update_multiple()
146 update_sum(&data->hist[cpu].sum_sample, &total_duration); in osnoise_hist_update_multiple()
147 update_max(&data->hist[cpu].max_sample, &duration); in osnoise_hist_update_multiple()
156 * osnoise_destroy_trace_hist - disable events used to collect histogram
160 struct osnoise_hist_data *data = tool->data; in osnoise_destroy_trace_hist()
162 tracefs_hist_pause(tool->trace.inst, data->trace_hist); in osnoise_destroy_trace_hist()
163 tracefs_hist_destroy(tool->trace.inst, data->trace_hist); in osnoise_destroy_trace_hist()
167 * osnoise_init_trace_hist - enable events used to collect histogram
171 struct osnoise_hist_params *params = tool->params; in osnoise_init_trace_hist()
172 struct osnoise_hist_data *data = tool->data; in osnoise_init_trace_hist()
180 bucket_size = params->output_divisor * params->bucket_size; in osnoise_init_trace_hist()
183 data->trace_hist = tracefs_hist_alloc(tool->trace.tep, "osnoise", "sample_threshold", in osnoise_init_trace_hist()
185 if (!data->trace_hist) in osnoise_init_trace_hist()
188 retval = tracefs_hist_add_key(data->trace_hist, "cpu", 0); in osnoise_init_trace_hist()
192 retval = tracefs_hist_start(tool->trace.inst, data->trace_hist); in osnoise_init_trace_hist()
204 * osnoise_read_trace_hist - parse histogram file and file osnoise histogram
208 struct osnoise_hist_data *data = tool->data; in osnoise_read_trace_hist()
212 tracefs_hist_pause(tool->trace.inst, data->trace_hist); in osnoise_read_trace_hist()
214 content = tracefs_event_file_read(tool->trace.inst, "osnoise", in osnoise_read_trace_hist()
227 if (duration == -1) in osnoise_read_trace_hist()
235 if (cpu == -1) in osnoise_read_trace_hist()
243 if (counter == -1) in osnoise_read_trace_hist()
252 * osnoise_hist_header - print the header of the tracer to the output
256 struct osnoise_hist_params *params = tool->params; in osnoise_hist_header()
257 struct osnoise_hist_data *data = tool->data; in osnoise_hist_header()
258 struct trace_seq *s = tool->trace.seq; in osnoise_hist_header()
262 if (params->no_header) in osnoise_hist_header()
265 get_duration(tool->start_time, duration, sizeof(duration)); in osnoise_hist_header()
268 params->output_divisor == 1 ? "nanoseconds" : "microseconds", in osnoise_hist_header()
269 params->output_divisor == 1 ? "ns" : "us"); in osnoise_hist_header()
273 if (!params->no_index) in osnoise_hist_header()
276 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_hist_header()
277 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_hist_header()
280 if (!data->hist[cpu].count) in osnoise_hist_header()
283 trace_seq_printf(s, " CPU-%03d", cpu); in osnoise_hist_header()
292 * osnoise_print_summary - print the summary of the hist data to the output
301 if (params->no_summary) in osnoise_print_summary()
304 if (!params->no_index) in osnoise_print_summary()
305 trace_seq_printf(trace->seq, "count:"); in osnoise_print_summary()
307 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_summary()
308 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_summary()
311 if (!data->hist[cpu].count) in osnoise_print_summary()
314 trace_seq_printf(trace->seq, "%9d ", data->hist[cpu].count); in osnoise_print_summary()
316 trace_seq_printf(trace->seq, "\n"); in osnoise_print_summary()
318 if (!params->no_index) in osnoise_print_summary()
319 trace_seq_printf(trace->seq, "min: "); in osnoise_print_summary()
321 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_summary()
322 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_summary()
325 if (!data->hist[cpu].count) in osnoise_print_summary()
328 trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].min_sample); in osnoise_print_summary()
331 trace_seq_printf(trace->seq, "\n"); in osnoise_print_summary()
333 if (!params->no_index) in osnoise_print_summary()
334 trace_seq_printf(trace->seq, "avg: "); in osnoise_print_summary()
336 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_summary()
337 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_summary()
340 if (!data->hist[cpu].count) in osnoise_print_summary()
343 if (data->hist[cpu].count) in osnoise_print_summary()
344 trace_seq_printf(trace->seq, "%9.2f ", in osnoise_print_summary()
345 ((double) data->hist[cpu].sum_sample) / data->hist[cpu].count); in osnoise_print_summary()
347 trace_seq_printf(trace->seq, " - "); in osnoise_print_summary()
349 trace_seq_printf(trace->seq, "\n"); in osnoise_print_summary()
351 if (!params->no_index) in osnoise_print_summary()
352 trace_seq_printf(trace->seq, "max: "); in osnoise_print_summary()
354 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_summary()
355 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_summary()
358 if (!data->hist[cpu].count) in osnoise_print_summary()
361 trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].max_sample); in osnoise_print_summary()
364 trace_seq_printf(trace->seq, "\n"); in osnoise_print_summary()
365 trace_seq_do_printf(trace->seq); in osnoise_print_summary()
366 trace_seq_reset(trace->seq); in osnoise_print_summary()
370 * osnoise_print_stats - print data for all CPUs
375 struct osnoise_hist_data *data = tool->data; in osnoise_print_stats()
376 struct trace_instance *trace = &tool->trace; in osnoise_print_stats()
383 for (bucket = 0; bucket < data->entries; bucket++) { in osnoise_print_stats()
386 if (!params->no_index) in osnoise_print_stats()
387 trace_seq_printf(trace->seq, "%-6d", in osnoise_print_stats()
388 bucket * data->bucket_size); in osnoise_print_stats()
390 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_stats()
391 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_stats()
394 if (!data->hist[cpu].count) in osnoise_print_stats()
397 total += data->hist[cpu].samples[bucket]; in osnoise_print_stats()
398 trace_seq_printf(trace->seq, "%9d ", data->hist[cpu].samples[bucket]); in osnoise_print_stats()
401 if (total == 0 && !params->with_zeros) { in osnoise_print_stats()
402 trace_seq_reset(trace->seq); in osnoise_print_stats()
406 /* There are samples above the threshold */ in osnoise_print_stats()
408 trace_seq_printf(trace->seq, "\n"); in osnoise_print_stats()
409 trace_seq_do_printf(trace->seq); in osnoise_print_stats()
410 trace_seq_reset(trace->seq); in osnoise_print_stats()
414 * If no samples were recorded, skip calculations, print zeroed statistics in osnoise_print_stats()
418 trace_seq_reset(trace->seq); in osnoise_print_stats()
419 trace_seq_printf(trace->seq, "over: 0\ncount: 0\nmin: 0\navg: 0\nmax: 0\n"); in osnoise_print_stats()
420 trace_seq_do_printf(trace->seq); in osnoise_print_stats()
421 trace_seq_reset(trace->seq); in osnoise_print_stats()
425 if (!params->no_index) in osnoise_print_stats()
426 trace_seq_printf(trace->seq, "over: "); in osnoise_print_stats()
428 for (cpu = 0; cpu < data->nr_cpus; cpu++) { in osnoise_print_stats()
429 if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) in osnoise_print_stats()
432 if (!data->hist[cpu].count) in osnoise_print_stats()
435 trace_seq_printf(trace->seq, "%9d ", in osnoise_print_stats()
436 data->hist[cpu].samples[data->entries]); in osnoise_print_stats()
438 trace_seq_printf(trace->seq, "\n"); in osnoise_print_stats()
439 trace_seq_do_printf(trace->seq); in osnoise_print_stats()
440 trace_seq_reset(trace->seq); in osnoise_print_stats()
446 * osnoise_hist_usage - prints osnoise hist usage message
454 " usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", in osnoise_hist_usage()
455 " [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\", in osnoise_hist_usage()
456 " [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\", in osnoise_hist_usage()
457 " [--no-index] [--with-zeros] [-C[=cgroup_name]] [--warm-up]", in osnoise_hist_usage()
459 " -h/--help: print this menu", in osnoise_hist_usage()
460 " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", in osnoise_hist_usage()
461 " -p/--period us: osnoise period in us", in osnoise_hist_usage()
462 " -r/--runtime us: osnoise runtime in us", in osnoise_hist_usage()
463 " -s/--stop us: stop trace if a single sample is higher than the argument in us", in osnoise_hist_usage()
464 " -S/--stop-total us: stop trace if the total sample is higher than the argument in us", in osnoise_hist_usage()
465 " -T/--threshold us: the minimum delta to be considered a noise", in osnoise_hist_usage()
466 " -c/--cpus cpu-list: list of cpus to run osnoise threads", in osnoise_hist_usage()
467 " -H/--house-keeping cpus: run rtla control threads only on the given cpus", in osnoise_hist_usage()
468 …" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be … in osnoise_hist_usage()
469 " -d/--duration time[s|m|h|d]: duration of the session", in osnoise_hist_usage()
470 " -D/--debug: print debug info", in osnoise_hist_usage()
471 " -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]", in osnoise_hist_usage()
472 …" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", in osnoise_hist_usage()
473 " --filter <filter>: enable a trace event filter to the previous -e event", in osnoise_hist_usage()
474 " --trigger <trigger>: enable a trace event trigger to the previous -e event", in osnoise_hist_usage()
475 " -b/--bucket-size N: set the histogram bucket size (default 1)", in osnoise_hist_usage()
476 " -E/--entries N: set the number of entries of the histogram (default 256)", in osnoise_hist_usage()
477 " --no-header: do not print header", in osnoise_hist_usage()
478 " --no-summary: do not print summary", in osnoise_hist_usage()
479 " --no-index: do not print index", in osnoise_hist_usage()
480 " --with-zeros: print zero only entries", in osnoise_hist_usage()
481 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period: set scheduling parameters", in osnoise_hist_usage()
482 " o:prio - use SCHED_OTHER with prio", in osnoise_hist_usage()
483 " r:prio - use SCHED_RR with prio", in osnoise_hist_usage()
484 " f:prio - use SCHED_FIFO with prio", in osnoise_hist_usage()
485 " d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period", in osnoise_hist_usage()
487 " --warm-up: let the workload run for s seconds before collecting data", in osnoise_hist_usage()
488 " --trace-buffer-size kB: set the per-cpu trace buffer size in kB", in osnoise_hist_usage()
495 fprintf(stderr, "rtla osnoise hist: a per-cpu histogram of the OS noise (version %s)\n", in osnoise_hist_usage()
508 * osnoise_hist_parse_args - allocs, parse and fill the cmd line parameters
523 params->output_divisor = 1000; in osnoise_hist_parse_args()
524 params->bucket_size = 1; in osnoise_hist_parse_args()
525 params->entries = 256; in osnoise_hist_parse_args()
530 {"bucket-size", required_argument, 0, 'b'}, in osnoise_hist_parse_args()
536 {"house-keeping", required_argument, 0, 'H'}, in osnoise_hist_parse_args()
542 {"stop-total", required_argument, 0, 'S'}, in osnoise_hist_parse_args()
546 {"no-header", no_argument, 0, '0'}, in osnoise_hist_parse_args()
547 {"no-summary", no_argument, 0, '1'}, in osnoise_hist_parse_args()
548 {"no-index", no_argument, 0, '2'}, in osnoise_hist_parse_args()
549 {"with-zeros", no_argument, 0, '3'}, in osnoise_hist_parse_args()
552 {"warm-up", required_argument, 0, '6'}, in osnoise_hist_parse_args()
553 {"trace-buffer-size", required_argument, 0, '7'}, in osnoise_hist_parse_args()
564 if (c == -1) in osnoise_hist_parse_args()
570 params->stop_us = get_llong_from_str(optarg); in osnoise_hist_parse_args()
573 params->threshold = 1; in osnoise_hist_parse_args()
576 params->trace_output = "osnoise_trace.txt"; in osnoise_hist_parse_args()
580 params->bucket_size = get_llong_from_str(optarg); in osnoise_hist_parse_args()
581 if ((params->bucket_size == 0) || (params->bucket_size >= 1000000)) in osnoise_hist_parse_args()
585 retval = parse_cpu_set(optarg, ¶ms->monitored_cpus); in osnoise_hist_parse_args()
587 osnoise_hist_usage("\nInvalid -c cpu list\n"); in osnoise_hist_parse_args()
588 params->cpus = optarg; in osnoise_hist_parse_args()
591 params->cgroup = 1; in osnoise_hist_parse_args()
594 params->cgroup_name = NULL; in osnoise_hist_parse_args()
597 params->cgroup_name = ++optarg; in osnoise_hist_parse_args()
604 params->duration = parse_seconds_duration(optarg); in osnoise_hist_parse_args()
605 if (!params->duration) in osnoise_hist_parse_args()
606 osnoise_hist_usage("Invalid -D duration\n"); in osnoise_hist_parse_args()
615 if (params->events) in osnoise_hist_parse_args()
616 tevent->next = params->events; in osnoise_hist_parse_args()
618 params->events = tevent; in osnoise_hist_parse_args()
621 params->entries = get_llong_from_str(optarg); in osnoise_hist_parse_args()
622 if ((params->entries < 10) || (params->entries > 9999999)) in osnoise_hist_parse_args()
630 params->hk_cpus = 1; in osnoise_hist_parse_args()
631 retval = parse_cpu_set(optarg, ¶ms->hk_cpu_set); in osnoise_hist_parse_args()
638 params->period = get_llong_from_str(optarg); in osnoise_hist_parse_args()
639 if (params->period > 10000000) in osnoise_hist_parse_args()
643 retval = parse_prio(optarg, ¶ms->sched_param); in osnoise_hist_parse_args()
644 if (retval == -1) in osnoise_hist_parse_args()
645 osnoise_hist_usage("Invalid -P priority"); in osnoise_hist_parse_args()
646 params->set_sched = 1; in osnoise_hist_parse_args()
649 params->runtime = get_llong_from_str(optarg); in osnoise_hist_parse_args()
650 if (params->runtime < 100) in osnoise_hist_parse_args()
654 params->stop_us = get_llong_from_str(optarg); in osnoise_hist_parse_args()
657 params->stop_total_us = get_llong_from_str(optarg); in osnoise_hist_parse_args()
660 params->threshold = get_llong_from_str(optarg); in osnoise_hist_parse_args()
665 params->trace_output = &optarg[1]; in osnoise_hist_parse_args()
667 params->trace_output = &optarg[0]; in osnoise_hist_parse_args()
669 params->trace_output = argv[optind]; in osnoise_hist_parse_args()
671 params->trace_output = "osnoise_trace.txt"; in osnoise_hist_parse_args()
674 params->no_header = 1; in osnoise_hist_parse_args()
677 params->no_summary = 1; in osnoise_hist_parse_args()
680 params->no_index = 1; in osnoise_hist_parse_args()
683 params->with_zeros = 1; in osnoise_hist_parse_args()
686 if (params->events) { in osnoise_hist_parse_args()
687 retval = trace_event_add_trigger(params->events, optarg); in osnoise_hist_parse_args()
693 osnoise_hist_usage("--trigger requires a previous -e\n"); in osnoise_hist_parse_args()
697 if (params->events) { in osnoise_hist_parse_args()
698 retval = trace_event_add_filter(params->events, optarg); in osnoise_hist_parse_args()
704 osnoise_hist_usage("--filter requires a previous -e\n"); in osnoise_hist_parse_args()
708 params->warmup = get_llong_from_str(optarg); in osnoise_hist_parse_args()
711 params->buffer_size = get_llong_from_str(optarg); in osnoise_hist_parse_args()
723 if (params->no_index && !params->with_zeros) in osnoise_hist_parse_args()
724 osnoise_hist_usage("no-index set and with-zeros not set - it does not make sense"); in osnoise_hist_parse_args()
730 * osnoise_hist_apply_config - apply the hist configs to the initialized tool
737 if (!params->sleep_time) in osnoise_hist_apply_config()
738 params->sleep_time = 1; in osnoise_hist_apply_config()
740 if (params->cpus) { in osnoise_hist_apply_config()
741 retval = osnoise_set_cpus(tool->context, params->cpus); in osnoise_hist_apply_config()
748 if (params->runtime || params->period) { in osnoise_hist_apply_config()
749 retval = osnoise_set_runtime_period(tool->context, in osnoise_hist_apply_config()
750 params->runtime, in osnoise_hist_apply_config()
751 params->period); in osnoise_hist_apply_config()
758 if (params->stop_us) { in osnoise_hist_apply_config()
759 retval = osnoise_set_stop_us(tool->context, params->stop_us); in osnoise_hist_apply_config()
766 if (params->stop_total_us) { in osnoise_hist_apply_config()
767 retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); in osnoise_hist_apply_config()
774 if (params->threshold) { in osnoise_hist_apply_config()
775 retval = osnoise_set_tracing_thresh(tool->context, params->threshold); in osnoise_hist_apply_config()
782 if (params->hk_cpus) { in osnoise_hist_apply_config()
783 retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), in osnoise_hist_apply_config()
784 ¶ms->hk_cpu_set); in osnoise_hist_apply_config()
785 if (retval == -1) { in osnoise_hist_apply_config()
789 } else if (params->cpus) { in osnoise_hist_apply_config()
791 * Even if the user do not set a house-keeping CPU, try to in osnoise_hist_apply_config()
797 auto_house_keeping(¶ms->monitored_cpus); in osnoise_hist_apply_config()
803 return -1; in osnoise_hist_apply_config()
807 * osnoise_init_hist - initialize a osnoise hist tool with parameters
821 tool->data = osnoise_alloc_histogram(nr_cpus, params->entries, params->bucket_size); in osnoise_init_hist()
822 if (!tool->data) in osnoise_init_hist()
825 tool->params = params; in osnoise_init_hist()
841 * osnoise_hist_set_signals - handles the signal to stop the tool
847 if (params->duration) { in osnoise_hist_set_signals()
849 alarm(params->duration); in osnoise_hist_set_signals()
878 trace = &tool->trace; in osnoise_hist_main()
890 if (params->set_sched) { in osnoise_hist_main()
891 retval = set_comm_sched_attr("osnoise/", ¶ms->sched_param); in osnoise_hist_main()
898 if (params->cgroup) { in osnoise_hist_main()
899 retval = set_comm_cgroup("timerlat/", params->cgroup_name); in osnoise_hist_main()
906 if (params->trace_output) { in osnoise_hist_main()
913 if (params->events) { in osnoise_hist_main()
914 retval = trace_events_enable(&record->trace, params->events); in osnoise_hist_main()
919 if (params->buffer_size > 0) { in osnoise_hist_main()
920 retval = trace_set_buffer_size(&record->trace, params->buffer_size); in osnoise_hist_main()
933 if (params->trace_output) in osnoise_hist_main()
934 trace_instance_start(&record->trace); in osnoise_hist_main()
937 if (params->warmup > 0) { in osnoise_hist_main()
938 debug_msg("Warming up for %d seconds\n", params->warmup); in osnoise_hist_main()
939 sleep(params->warmup); in osnoise_hist_main()
944 * Clean up the buffer. The osnoise workload do not run in osnoise_hist_main()
948 retval = tracefs_instance_file_write(trace->inst, "trace", ""); in osnoise_hist_main()
950 debug_msg("Error cleaning up the buffer"); in osnoise_hist_main()
956 tool->start_time = time(NULL); in osnoise_hist_main()
960 sleep(params->sleep_time); in osnoise_hist_main()
962 retval = tracefs_iterate_raw_events(trace->tep, in osnoise_hist_main()
963 trace->inst, in osnoise_hist_main()
973 if (trace_is_off(&tool->trace, &record->trace)) in osnoise_hist_main()
983 if (trace_is_off(&tool->trace, &record->trace)) { in osnoise_hist_main()
985 if (params->trace_output) { in osnoise_hist_main()
986 printf(" Saving trace to %s\n", params->trace_output); in osnoise_hist_main()
987 save_trace_to_file(record->trace.inst, params->trace_output); in osnoise_hist_main()
992 trace_events_destroy(&record->trace, params->events); in osnoise_hist_main()
993 params->events = NULL; in osnoise_hist_main()
995 osnoise_free_histogram(tool->data); in osnoise_hist_main()