Deleted Added
full compact
pmcstat.c (224698) pmcstat.c (226514)
1/*-
2 * Copyright (c) 2003-2008, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003-2008, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/usr.sbin/pmcstat/pmcstat.c 224698 2011-08-07 18:37:05Z attilio $");
32__FBSDID("$FreeBSD: head/usr.sbin/pmcstat/pmcstat.c 226514 2011-10-18 15:25:43Z fabient $");
33
34#include <sys/param.h>
35#include <sys/cpuset.h>
36#include <sys/event.h>
37#include <sys/queue.h>
38#include <sys/socket.h>
39#include <sys/stat.h>
40#include <sys/sysctl.h>

--- 506 unchanged lines hidden (view full) ---

547int
548main(int argc, char **argv)
549{
550 cpuset_t cpumask;
551 double interval;
552 int hcpu, option, npmc, ncpu;
553 int c, check_driver_stats, current_cpu, current_sampling_count;
554 int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
33
34#include <sys/param.h>
35#include <sys/cpuset.h>
36#include <sys/event.h>
37#include <sys/queue.h>
38#include <sys/socket.h>
39#include <sys/stat.h>
40#include <sys/sysctl.h>

--- 506 unchanged lines hidden (view full) ---

547int
548main(int argc, char **argv)
549{
550 cpuset_t cpumask;
551 double interval;
552 int hcpu, option, npmc, ncpu;
553 int c, check_driver_stats, current_cpu, current_sampling_count;
554 int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
555 int do_print;
555 int do_print, do_read;
556 size_t dummy;
557 int graphdepth;
558 int pipefd[2], rfd;
559 int use_cumulative_counts;
560 short cf, cb;
561 char *end, *tmp;
562 const char *errmsg, *graphfilename;
563 enum pmcstat_state runstate;

--- 759 unchanged lines hidden (view full) ---

1323 }
1324 }
1325
1326 /*
1327 * loop till either the target process (if any) exits, or we
1328 * are killed by a SIGINT.
1329 */
1330 runstate = PMCSTAT_RUNNING;
556 size_t dummy;
557 int graphdepth;
558 int pipefd[2], rfd;
559 int use_cumulative_counts;
560 short cf, cb;
561 char *end, *tmp;
562 const char *errmsg, *graphfilename;
563 enum pmcstat_state runstate;

--- 759 unchanged lines hidden (view full) ---

1323 }
1324 }
1325
1326 /*
1327 * loop till either the target process (if any) exits, or we
1328 * are killed by a SIGINT.
1329 */
1330 runstate = PMCSTAT_RUNNING;
1331 do_print = 0;
1331 do_print = do_read = 0;
1332 do {
1333 if ((c = kevent(pmcstat_kq, NULL, 0, &kev, 1, NULL)) <= 0) {
1334 if (errno != EINTR)
1335 err(EX_OSERR, "ERROR: kevent failed");
1336 else
1337 continue;
1338 }
1339

--- 6 unchanged lines hidden (view full) ---

1346 do_print = 1;
1347 break;
1348
1349 case EVFILT_READ: /* log file data is present */
1350 if (kev.ident == (unsigned)fileno(stdin) &&
1351 (args.pa_flags & FLAG_DO_TOP)) {
1352 if (pmcstat_keypress_log())
1353 runstate = pmcstat_close_log();
1332 do {
1333 if ((c = kevent(pmcstat_kq, NULL, 0, &kev, 1, NULL)) <= 0) {
1334 if (errno != EINTR)
1335 err(EX_OSERR, "ERROR: kevent failed");
1336 else
1337 continue;
1338 }
1339

--- 6 unchanged lines hidden (view full) ---

1346 do_print = 1;
1347 break;
1348
1349 case EVFILT_READ: /* log file data is present */
1350 if (kev.ident == (unsigned)fileno(stdin) &&
1351 (args.pa_flags & FLAG_DO_TOP)) {
1352 if (pmcstat_keypress_log())
1353 runstate = pmcstat_close_log();
1354 } else
1354 } else {
1355 do_read = 0;
1355 runstate = pmcstat_process_log();
1356 runstate = pmcstat_process_log();
1357 }
1356 break;
1357
1358 case EVFILT_SIGNAL:
1359 if (kev.ident == SIGCHLD) {
1360 /*
1361 * The child process sends us a
1362 * SIGCHLD if its exec() failed. We
1363 * wait for it to exit and then exit

--- 8 unchanged lines hidden (view full) ---

1372 * writes encounter an error.
1373 */
1374 runstate = pmcstat_close_log();
1375 do_print = 1; /* print PMCs at exit */
1376 } else if (kev.ident == SIGINT) {
1377 /* Kill the child process if we started it */
1378 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
1379 pmcstat_kill_process();
1358 break;
1359
1360 case EVFILT_SIGNAL:
1361 if (kev.ident == SIGCHLD) {
1362 /*
1363 * The child process sends us a
1364 * SIGCHLD if its exec() failed. We
1365 * wait for it to exit and then exit

--- 8 unchanged lines hidden (view full) ---

1374 * writes encounter an error.
1375 */
1376 runstate = pmcstat_close_log();
1377 do_print = 1; /* print PMCs at exit */
1378 } else if (kev.ident == SIGINT) {
1379 /* Kill the child process if we started it */
1380 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
1381 pmcstat_kill_process();
1380 /* Close the pipe to self, if present. */
1381 if (args.pa_flags & FLAG_HAS_PIPE)
1382 (void) close(pipefd[READPIPEFD]);
1383 runstate = pmcstat_close_log();
1384 } else if (kev.ident == SIGWINCH) {
1385 if (ioctl(fileno(args.pa_printfile),
1386 TIOCGWINSZ, &ws) < 0)
1387 err(EX_OSERR, "ERROR: Cannot determine "
1388 "window size");
1389 pmcstat_displayheight = ws.ws_row - 1;
1390 pmcstat_displaywidth = ws.ws_col - 1;
1391 } else
1392 assert(0);
1393
1394 break;
1395
1396 case EVFILT_TIMER: /* print out counting PMCs */
1382 runstate = pmcstat_close_log();
1383 } else if (kev.ident == SIGWINCH) {
1384 if (ioctl(fileno(args.pa_printfile),
1385 TIOCGWINSZ, &ws) < 0)
1386 err(EX_OSERR, "ERROR: Cannot determine "
1387 "window size");
1388 pmcstat_displayheight = ws.ws_row - 1;
1389 pmcstat_displaywidth = ws.ws_col - 1;
1390 } else
1391 assert(0);
1392
1393 break;
1394
1395 case EVFILT_TIMER: /* print out counting PMCs */
1396 if ((args.pa_flags & FLAG_DO_TOP) &&
1397 pmc_flush_logfile() != ENOBUFS)
1398 do_read = 1;
1397 do_print = 1;
1398 break;
1399
1400 }
1401
1399 do_print = 1;
1400 break;
1401
1402 }
1403
1402 if (do_print) {
1404 if (do_print && !do_read) {
1403 if ((args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) == 0) {
1404 pmcstat_print_pmcs();
1405 if (runstate == PMCSTAT_FINISHED && /* final newline */
1406 (args.pa_flags & FLAG_DO_PRINT) == 0)
1407 (void) fprintf(args.pa_printfile, "\n");
1408 }
1409 if (args.pa_flags & FLAG_DO_TOP)
1410 pmcstat_display_log();

--- 4 unchanged lines hidden (view full) ---

1415
1416 if ((args.pa_flags & FLAG_DO_TOP) && args.pa_toptty) {
1417 pmcstat_topexit();
1418 args.pa_toptty = 0;
1419 }
1420
1421 /* flush any pending log entries */
1422 if (args.pa_flags & (FLAG_HAS_OUTPUT_LOGFILE | FLAG_HAS_PIPE))
1405 if ((args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) == 0) {
1406 pmcstat_print_pmcs();
1407 if (runstate == PMCSTAT_FINISHED && /* final newline */
1408 (args.pa_flags & FLAG_DO_PRINT) == 0)
1409 (void) fprintf(args.pa_printfile, "\n");
1410 }
1411 if (args.pa_flags & FLAG_DO_TOP)
1412 pmcstat_display_log();

--- 4 unchanged lines hidden (view full) ---

1417
1418 if ((args.pa_flags & FLAG_DO_TOP) && args.pa_toptty) {
1419 pmcstat_topexit();
1420 args.pa_toptty = 0;
1421 }
1422
1423 /* flush any pending log entries */
1424 if (args.pa_flags & (FLAG_HAS_OUTPUT_LOGFILE | FLAG_HAS_PIPE))
1423 pmc_flush_logfile();
1425 pmc_close_logfile();
1424
1425 pmcstat_cleanup();
1426
1427 free(args.pa_kernel);
1428
1429 /* check if the driver lost any samples or events */
1430 if (check_driver_stats) {
1431 if (pmc_get_driver_stats(&ds_end) < 0)

--- 17 unchanged lines hidden ---
1426
1427 pmcstat_cleanup();
1428
1429 free(args.pa_kernel);
1430
1431 /* check if the driver lost any samples or events */
1432 if (check_driver_stats) {
1433 if (pmc_get_driver_stats(&ds_end) < 0)

--- 17 unchanged lines hidden ---