Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/pmcstat/pmcstat.c
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
cpuset_t cpumask, rootmask; | cpuset_t cpumask, rootmask; | ||||
double interval; | double interval; | ||||
double duration; | double duration; | ||||
int option, npmc; | int option, npmc; | ||||
int c, check_driver_stats, current_sampling_count; | int c, check_driver_stats; | ||||
uint64_t current_sampling_count; | |||||
int do_callchain, do_descendants, do_logproccsw, do_logprocexit; | int do_callchain, do_descendants, do_logproccsw, do_logprocexit; | ||||
int do_print, do_read; | int do_print, do_read; | ||||
size_t len; | size_t len; | ||||
int graphdepth; | int graphdepth; | ||||
int pipefd[2], rfd; | int pipefd[2], rfd; | ||||
int use_cumulative_counts; | int use_cumulative_counts; | ||||
short cf, cb; | short cf, cb; | ||||
char *end, *tmp; | char *end, *tmp; | ||||
const char *errmsg, *graphfilename; | const char *errmsg, *graphfilename; | ||||
enum pmcstat_state runstate; | enum pmcstat_state runstate; | ||||
struct pmc_driverstats ds_start, ds_end; | struct pmc_driverstats ds_start, ds_end; | ||||
struct pmcstat_ev *ev; | struct pmcstat_ev *ev; | ||||
struct sigaction sa; | struct sigaction sa; | ||||
struct kevent kev; | struct kevent kev; | ||||
struct winsize ws; | struct winsize ws; | ||||
struct stat sb; | struct stat sb; | ||||
char buffer[PATH_MAX]; | char buffer[PATH_MAX]; | ||||
check_driver_stats = 0; | check_driver_stats = 0; | ||||
current_sampling_count = DEFAULT_SAMPLE_COUNT; | current_sampling_count = 0; | ||||
do_callchain = 1; | do_callchain = 1; | ||||
do_descendants = 0; | do_descendants = 0; | ||||
do_logproccsw = 0; | do_logproccsw = 0; | ||||
do_logprocexit = 0; | do_logprocexit = 0; | ||||
use_cumulative_counts = 0; | use_cumulative_counts = 0; | ||||
graphfilename = "-"; | graphfilename = "-"; | ||||
args.pa_required = 0; | args.pa_required = 0; | ||||
args.pa_flags = 0; | args.pa_flags = 0; | ||||
Show All 38 Lines | main(int argc, char **argv) | ||||
* which is usually all CPUs in the system. | * which is usually all CPUs in the system. | ||||
*/ | */ | ||||
if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, | if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, | ||||
sizeof(rootmask), &rootmask) == -1) | sizeof(rootmask), &rootmask) == -1) | ||||
err(EX_OSERR, "ERROR: Cannot determine the root set of CPUs"); | err(EX_OSERR, "ERROR: Cannot determine the root set of CPUs"); | ||||
CPU_COPY(&rootmask, &cpumask); | CPU_COPY(&rootmask, &cpumask); | ||||
while ((option = getopt(argc, argv, | while ((option = getopt(argc, argv, | ||||
"CD:EF:G:M:NO:P:R:S:TWa:c:def:gk:l:m:n:o:p:qr:s:t:vw:z:")) != -1) | "CD:EF:G:IM:NO:P:R:S:TWa:c:def:gk:l:m:n:o:p:qr:s:t:vw:z:")) != -1) | ||||
switch (option) { | switch (option) { | ||||
case 'a': /* Annotate + callgraph */ | case 'a': /* Annotate + callgraph */ | ||||
args.pa_flags |= FLAG_DO_ANNOTATE; | args.pa_flags |= FLAG_DO_ANNOTATE; | ||||
args.pa_plugin = PMCSTAT_PL_ANNOTATE_CG; | args.pa_plugin = PMCSTAT_PL_ANNOTATE_CG; | ||||
graphfilename = optarg; | graphfilename = optarg; | ||||
break; | break; | ||||
case 'C': /* cumulative values */ | case 'C': /* cumulative values */ | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | case 'G': /* produce a system-wide callgraph */ | ||||
break; | break; | ||||
case 'g': /* produce gprof compatible profiles */ | case 'g': /* produce gprof compatible profiles */ | ||||
args.pa_flags |= FLAG_DO_GPROF; | args.pa_flags |= FLAG_DO_GPROF; | ||||
args.pa_pplugin = PMCSTAT_PL_CALLGRAPH; | args.pa_pplugin = PMCSTAT_PL_CALLGRAPH; | ||||
args.pa_plugin = PMCSTAT_PL_GPROF; | args.pa_plugin = PMCSTAT_PL_GPROF; | ||||
break; | break; | ||||
case 'I': | |||||
args.pa_flags |= FLAG_SKIP_TOP_FN_RES; | |||||
break; | |||||
case 'k': /* pathname to the kernel */ | case 'k': /* pathname to the kernel */ | ||||
free(args.pa_kernel); | free(args.pa_kernel); | ||||
args.pa_kernel = strdup(optarg); | args.pa_kernel = strdup(optarg); | ||||
if (args.pa_kernel == NULL) | if (args.pa_kernel == NULL) | ||||
errx(EX_SOFTWARE, "ERROR: Out of memory"); | errx(EX_SOFTWARE, "ERROR: Out of memory"); | ||||
args.pa_required |= FLAG_DO_ANALYSIS; | args.pa_required |= FLAG_DO_ANALYSIS; | ||||
args.pa_flags |= FLAG_HAS_KERNELPATH; | args.pa_flags |= FLAG_HAS_KERNELPATH; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | case 'S': /* system-wide sampling PMC */ | ||||
if (option == 's' || option == 'S') | if (option == 's' || option == 'S') | ||||
args.pa_flags |= FLAG_HAS_SYSTEM_PMCS; | args.pa_flags |= FLAG_HAS_SYSTEM_PMCS; | ||||
ev->ev_spec = strdup(optarg); | ev->ev_spec = strdup(optarg); | ||||
if (ev->ev_spec == NULL) | if (ev->ev_spec == NULL) | ||||
errx(EX_SOFTWARE, "ERROR: Out of memory."); | errx(EX_SOFTWARE, "ERROR: Out of memory."); | ||||
if (option == 'S' || option == 'P') | if (option == 'S' || option == 'P') | ||||
ev->ev_count = current_sampling_count; | ev->ev_count = current_sampling_count ? current_sampling_count : pmu_sample_rate_get(ev->ev_spec); | ||||
else | else | ||||
ev->ev_count = -1; | ev->ev_count = -1; | ||||
if (option == 'S' || option == 's') | if (option == 'S' || option == 's') | ||||
ev->ev_cpu = CPU_FFS(&cpumask) - 1; | ev->ev_cpu = CPU_FFS(&cpumask) - 1; | ||||
else | else | ||||
ev->ev_cpu = PMC_CPU_ANY; | ev->ev_cpu = PMC_CPU_ANY; | ||||
▲ Show 20 Lines • Show All 760 Lines • Show Last 20 Lines |