Lines Matching +full:toggle +full:- +full:mode
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2008, Joseph Koshy
73 * the system-wide and per-process variety. Each of these could be in
74 * 'counting mode' or in 'sampling mode'.
76 * For 'counting mode' PMCs, pmcstat(8) will periodically issue a
80 * For 'sampling mode' PMCs it can log to a file for offline analysis,
90 * - parent creates a socketpair for two way communication and
92 * - subsequently:
96 * - Wait for child's token.
97 * - Sends token.
98 * - Awaits signal to start.
99 * - Attaches PMCs to the child's pid
102 * - Signals child to start.
103 * - Receives signal, attempts exec().
148 if (ev->ev_pmcid != PMC_ID_INVALID) { in pmcstat_cleanup()
149 if (pmc_stop(ev->ev_pmcid) < 0) in pmcstat_cleanup()
152 ev->ev_pmcid, ev->ev_name); in pmcstat_cleanup()
153 if (pmc_release(ev->ev_pmcid) < 0) in pmcstat_cleanup()
156 ev->ev_pmcid, ev->ev_name); in pmcstat_cleanup()
159 /* de-configure the log file if present. */ in pmcstat_cleanup()
161 (void) pmc_configure_logfile(-1); in pmcstat_cleanup()
186 pt->pt_pid = pid; in pmcstat_find_targets()
211 if ((rv = regexec(®, kp->ki_comm, 1, ®match, 0)) == 0) { in pmcstat_find_targets()
214 pt->pt_pid = kp->ki_pid; in pmcstat_find_targets()
241 * in the list, before any other processes specified by -t. in pmcstat_kill_process()
246 if (kill(pt->pt_pid, SIGINT) != 0) in pmcstat_kill_process()
257 assert(ev->ev_pmcid != PMC_ID_INVALID); in pmcstat_start_pmcs()
259 if (pmc_start(ev->ev_pmcid) < 0) { in pmcstat_start_pmcs()
261 ev->ev_pmcid, ev->ev_name); in pmcstat_start_pmcs()
277 if (PMC_IS_SAMPLING_MODE(ev->ev_mode)) in pmcstat_print_headers()
280 c = PMC_IS_SYSTEM_MODE(ev->ev_mode) ? 's' : 'p'; in pmcstat_print_headers()
282 if (ev->ev_fieldskip != 0) in pmcstat_print_headers()
284 ev->ev_fieldskip, ""); in pmcstat_print_headers()
285 w = ev->ev_fieldwidth - ev->ev_fieldskip - 2; in pmcstat_print_headers()
288 (void) fprintf(args.pa_printfile, "s/%02d/%-*s ", in pmcstat_print_headers()
289 ev->ev_cpu, w-3, ev->ev_name); in pmcstat_print_headers()
292 ev->ev_name); in pmcstat_print_headers()
305 extra_width = sizeof(PRINT_HEADER_PREFIX) - 1; in pmcstat_print_counters()
309 /* skip sampling mode counters */ in pmcstat_print_counters()
310 if (PMC_IS_SAMPLING_MODE(ev->ev_mode)) in pmcstat_print_counters()
313 if (pmc_read(ev->ev_pmcid, &value) < 0) in pmcstat_print_counters()
315 ev->ev_name); in pmcstat_print_counters()
318 ev->ev_fieldwidth + extra_width, in pmcstat_print_counters()
319 (uintmax_t) ev->ev_cumulative ? value : in pmcstat_print_counters()
320 (value - ev->ev_saved)); in pmcstat_print_counters()
322 if (ev->ev_cumulative == 0) in pmcstat_print_counters()
323 ev->ev_saved = value; in pmcstat_print_counters()
359 "\t -C\t\t (toggle) show cumulative counts\n" in pmcstat_show_usage()
360 "\t -D path\t create profiles in directory \"path\"\n" in pmcstat_show_usage()
361 "\t -E\t\t (toggle) show counts at process exit\n" in pmcstat_show_usage()
362 "\t -F file\t write a system-wide callgraph (Kcachegrind format)" in pmcstat_show_usage()
364 "\t -G file\t write a system-wide callgraph to \"file\"\n" in pmcstat_show_usage()
365 "\t -I\t\t don't resolve leaf function name, show address instead\n" in pmcstat_show_usage()
366 "\t -L\t\t list all counters available on this host\n" in pmcstat_show_usage()
367 "\t -M file\t print executable/gmon file map to \"file\"\n" in pmcstat_show_usage()
368 "\t -N\t\t (toggle) capture callchains\n" in pmcstat_show_usage()
369 "\t -O file\t send log output to \"file\"\n" in pmcstat_show_usage()
370 "\t -P spec\t allocate a process-private sampling PMC\n" in pmcstat_show_usage()
371 "\t -R file\t read events from \"file\"\n" in pmcstat_show_usage()
372 "\t -S spec\t allocate a system-wide sampling PMC\n" in pmcstat_show_usage()
373 "\t -T\t\t start in top mode\n" in pmcstat_show_usage()
374 "\t -U \t\t merged user kernel stack capture\n" in pmcstat_show_usage()
375 "\t -W\t\t (toggle) show counts per context switch\n" in pmcstat_show_usage()
376 "\t -a file\t print sampled PCs and callgraph to \"file\"\n" in pmcstat_show_usage()
377 "\t -c cpu-list\t set cpus for subsequent system-wide PMCs\n" in pmcstat_show_usage()
378 "\t -d\t\t (toggle) track descendants\n" in pmcstat_show_usage()
379 "\t -e\t\t use wide history counter for gprof(1) output\n" in pmcstat_show_usage()
380 "\t -f spec\t pass \"spec\" to as plugin option\n" in pmcstat_show_usage()
381 "\t -g\t\t produce gprof(1) compatible profiles\n" in pmcstat_show_usage()
382 "\t -i lwp\t\t filter on thread id \"lwp\" in post-processing\n" in pmcstat_show_usage()
383 "\t -l secs\t set duration time\n" in pmcstat_show_usage()
384 "\t -m file\t print sampled PCs to \"file\"\n" in pmcstat_show_usage()
385 "\t -n rate\t set sampling rate\n" in pmcstat_show_usage()
386 "\t -o file\t send print output to \"file\"\n" in pmcstat_show_usage()
387 "\t -p spec\t allocate a process-private counting PMC\n" in pmcstat_show_usage()
388 "\t -q\t\t suppress verbosity\n" in pmcstat_show_usage()
389 "\t -r fsroot\t specify FS root directory\n" in pmcstat_show_usage()
390 "\t -s spec\t allocate a system-wide counting PMC\n" in pmcstat_show_usage()
391 "\t -t process-spec attach to running processes matching " in pmcstat_show_usage()
392 "\"process-spec\"\n" in pmcstat_show_usage()
393 "\t -u spec \t provide short description of counters matching spec\n" in pmcstat_show_usage()
394 "\t -v\t\t increase verbosity\n" in pmcstat_show_usage()
395 "\t -w secs\t set printing time interval\n" in pmcstat_show_usage()
396 "\t -z depth\t limit callchain display depth" in pmcstat_show_usage()
401 * At exit handler for top mode
477 graphfilename = "-"; in main()
481 args.pa_logfd = -1; in main()
509 if (sysctlbyname("vm.ndomains", &domains, &len, NULL, 0) == -1) in main()
516 if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, in main()
517 sizeof(rootmask), &rootmask) == -1) in main()
522 "ACD:EF:G:ILM:NO:P:R:S:TUWZa:c:def:gi:k:l:m:n:o:p:qr:s:t:u:vw:z:")) != -1) in main()
562 case 'd': /* toggle descendents */ in main()
577 case 'F': /* produce a system-wide calltree */ in main()
585 err(EX_USAGE, "ERROR: Need -g/-G/-m/-T."); in main()
589 case 'G': /* produce a system-wide callgraph */ in main()
611 warnx("WARNING: -k is obsolete, has no effect " in main()
644 case 's': /* system-wide counting PMC */ in main()
646 case 'S': /* system-wide sampling PMC */ in main()
652 case 'p': ev->ev_mode = PMC_MODE_TC; break; in main()
653 case 's': ev->ev_mode = PMC_MODE_SC; break; in main()
654 case 'P': ev->ev_mode = PMC_MODE_TS; break; in main()
655 case 'S': ev->ev_mode = PMC_MODE_SS; break; in main()
676 ev->ev_spec = strdup(optarg); in main()
677 if (ev->ev_spec == NULL) in main()
681 …ev->ev_count = current_sampling_count ? current_sampling_count : pmc_pmu_sample_rate_get(ev->ev_sp… in main()
683 ev->ev_count = 0; in main()
686 ev->ev_cpu = CPU_FFS(&cpumask) - 1; in main()
688 ev->ev_cpu = PMC_CPU_ANY; in main()
690 ev->ev_flags = 0; in main()
692 ev->ev_flags |= PMC_F_CALLCHAIN; in main()
694 ev->ev_flags |= PMC_F_USERCALLCHAIN; in main()
697 ev->ev_flags |= PMC_F_DESCENDANTS; in main()
699 ev->ev_flags |= PMC_F_LOG_PROCEXIT; in main()
701 ev->ev_flags |= PMC_F_LOG_PROCCSW; in main()
703 ev->ev_cumulative = use_cumulative_counts; in main()
705 ev->ev_saved = 0LL; in main()
706 ev->ev_pmcid = PMC_ID_INVALID; in main()
710 ev->ev_name = malloc(c + 1); in main()
711 if (ev->ev_name == NULL) in main()
713 (void) strncpy(ev->ev_name, optarg, c); in main()
714 *(ev->ev_name + c) = '\0'; in main()
725 if (pmc_allocate(ev->ev_spec, ev->ev_mode, in main()
726 ev->ev_flags, ev->ev_cpu, &ev->ev_pmcid, in main()
727 ev->ev_count) < 0) in main()
729 "system-mode pmc with specification" in main()
730 " \"%s\"", ev->ev_spec); in main()
731 if (pmc_capabilities(ev->ev_pmcid, &caps)) { in main()
732 pmc_release(ev->ev_pmcid); in main()
741 pmc_release(ev->ev_pmcid); in main()
742 ev->ev_pmcid = PMC_ID_INVALID; in main()
761 CPU_SET(CPU_FFS(&dommask) - 1, &cpumask); in main()
766 CPU_CLR(ev->ev_cpu, &cpumask); in main()
768 CPU_SET(ev->ev_cpu, &cpumask); in main()
797 "ERROR: option -O may only be specified once."); in main()
802 case 'q': /* quiet mode */ in main()
813 "ERROR: option -R may only be specified once."); in main()
827 case 'T': /* top mode */ in main()
840 case 'U': /* toggle user-space callchain capture */ in main()
858 case 'W': /* toggle LOG_CSW */ in main()
891 args.pa_argc = (argc -= optind); in main()
901 args.pa_cpumask = cpumask; /* For selecting CPUs using -R. */ in main()
914 /* disallow -O and -R together */ in main()
917 "ERROR: options -O and -R are mutually exclusive."); in main()
919 /* disallow -T and -l together */ in main()
922 errx(EX_USAGE, "ERROR: options -T and -l are mutually " in main()
925 /* -a and -m require -R */ in main()
928 args.pa_plugin == PMCSTAT_PL_ANNOTATE ? "-m" : "-a"); in main()
930 /* -m option is not allowed combined with -g or -G. */ in main()
934 "ERROR: option -m and -g | -G are mutually exclusive"); in main()
941 errmsg = "option -t"; in main()
946 "ERROR: option -R may not be used with %s.", in main()
952 /* check for -t pid without a process PMC spec */ in main()
957 "ERROR: option -t requires a process mode PMC to be specified." in main()
960 /* check for process-mode options without a command or -t pid */ in main()
964 "ERROR: options -d, -E, -p, -P, and -W require a command line or target process." in main()
967 /* check for -p | -P without a target process of some sort */ in main()
971 "ERROR: options -P and -p require a target process or a command line." in main()
974 /* check for process-mode options without a process-mode PMC */ in main()
978 "ERROR: options -d, -E, -t, and -W require a process mode PMC to be specified." in main()
981 /* check for -c cpu with no system mode PMCs or logfile. */ in main()
986 "ERROR: option -c requires at least one system mode PMC to be specified." in main()
989 /* check for counting mode options without a counting PMC */ in main()
993 "ERROR: options -C, -W and -o require at least one counting mode PMC to be specified." in main()
996 /* check for sampling mode options without a sampling PMC spec */ in main()
1000 "ERROR: options -N, -n and -O require at least one sampling mode PMC to be specified." in main()
1003 /* check if -g/-G/-m/-T are being used correctly */ in main()
1007 "ERROR: options -g/-G/-m/-T require sampling PMCs or -R to be specified." in main()
1010 /* check if -e was specified without -g */ in main()
1014 "ERROR: option -e requires gprof mode to be specified." in main()
1017 /* check if -O was spuriously specified */ in main()
1021 "ERROR: option -O is used only with options -E, -P, -S and -W." in main()
1024 /* -D only applies to gprof output mode (-g) */ in main()
1027 errx(EX_USAGE, "ERROR: option -D is only used with -g."); in main()
1029 /* -M mapfile requires -g or -R */ in main()
1033 errx(EX_USAGE, "ERROR: option -M is only used with -g/-R."); in main()
1044 "ERROR: option -O is required if counting and sampling PMCs are specified together." in main()
1051 if (strcmp(graphfilename, "-") == 0) in main()
1144 if (pmc_allocate(ev->ev_spec, ev->ev_mode, in main()
1145 ev->ev_flags, ev->ev_cpu, &ev->ev_pmcid, in main()
1146 ev->ev_count) < 0) in main()
1148 "ERROR: Cannot allocate %s-mode pmc with specification \"%s\"", in main()
1149 PMC_IS_SYSTEM_MODE(ev->ev_mode) ? in main()
1150 "system" : "process", ev->ev_spec); in main()
1152 if (PMC_IS_SAMPLING_MODE(ev->ev_mode) && in main()
1153 pmc_set(ev->ev_pmcid, ev->ev_count) < 0) in main()
1156 ev->ev_name); in main()
1165 (void) pmc_width(ev->ev_pmcid, &counter_width); in main()
1166 header_width = strlen(ev->ev_name) + 2; /* prefix '%c/' */ in main()
1169 if (PMC_IS_SYSTEM_MODE(ev->ev_mode)) in main()
1173 ev->ev_fieldskip = 0; in main()
1174 ev->ev_fieldwidth = header_width; in main()
1176 ev->ev_fieldskip = display_width - in main()
1178 ev->ev_fieldwidth = display_width; in main()
1192 pmcstat_displayheight = ws.ws_row - 1; in main()
1193 pmcstat_displaywidth = ws.ws_col - 1; in main()
1205 * Listen to key input in top mode. in main()
1232 * Setup a timer if we have counting mode PMCs needing to be printed or in main()
1233 * top mode plugin is active. in main()
1247 * Setup a duration timer if we have sampling mode PMCs and in main()
1300 * Setup the top mode display. in main()
1329 pmcstat_displayheight--; pmcstat_displaywidth--; in main()
1396 pmcstat_displayheight = ws.ws_row - 1; in main()
1397 pmcstat_displaywidth = ws.ws_col - 1; in main()
1455 ds_end.pm_intr_bufferfull - in main()
1457 ((ds_end.pm_intr_bufferfull - in main()
1466 ds_end.pm_buffer_requests_failed - in main()
1468 ((ds_end.pm_buffer_requests_failed - in main()