/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Maxime Villard.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c)2008 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
fprintf(stderr, "%s op [arguments]\n", getprogname());
fprintf(stderr, "\n");
fprintf(stderr, "\tlist\n");
fprintf(stderr, "\t\tList the available events.\n");
fprintf(stderr, "\tmonitor -e name[:option] [-e ...] [-o outfile]"
" command\n");
fprintf(stderr, "\t\tMonitor the event 'name' with option 'option'\n"
"\t\tcounted during the execution of 'command'.\n");
fprintf(stderr, "\tcount -e name[:option] [-e ...] [-i interval]"
" command\n");
fprintf(stderr, "\t\tSame as monitor, but does not profile,"
" only outputs a counter.\n");
fprintf(stderr, "\tanalyze [-CkLPs] [-p pid] file\n");
fprintf(stderr, "\t\tAnalyze the samples of the file 'file'.\n");
fprintf(stderr, "\ttop [-e name [-e ...]] [-i interval] [-acu]\n");
fprintf(stderr, "\t\tDisplay profiling results in real-time.\n");
exit(EXIT_FAILURE);
}
static int
getncpu(void)
{
size_t size;
int mib[2];
printf("%u events can be counted at the same time.\n", ncounters);
if (defaultevent != NULL)
printf("The default counter for monitor and top command is "
"\"%s\".\n", defaultevent);
tprof_event_list();
}
ret = ioctl(devfd, TPROF_IOC_GETINFO, &tprof_info);
if (ret == -1) {
err(EXIT_FAILURE, "TPROF_IOC_GETINFO");
}
if (tprof_info.ti_version != TPROF_VERSION) {
errx(EXIT_FAILURE, "version mismatch: version=%d, expected=%d",
tprof_info.ti_version, TPROF_VERSION);
}
if (tprof_event_init(tprof_info.ti_ident) == -1) {
errx(EXIT_FAILURE, "cpu not supported");
}
ret = ioctl(devfd, TPROF_IOC_GETNCOUNTERS, &ncounters);
if (ret == -1) {
err(EXIT_FAILURE, "TPROF_IOC_GETNCOUNTERS");
}
if (ncounters == 0) {
errx(EXIT_FAILURE, "no available counters");
}