Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/tprof Ask for a file path with the "analyze" comman...



details:   https://anonhg.NetBSD.org/src/rev/bc61cd75ced7
branches:  trunk
changeset: 833811:bc61cd75ced7
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Jul 13 12:04:50 2018 +0000

description:
Ask for a file path with the "analyze" command, instead of reading stdin.

diffstat:

 usr.sbin/tprof/tprof.8         |  10 ++++++----
 usr.sbin/tprof/tprof.c         |  11 +++++++----
 usr.sbin/tprof/tprof_analyze.c |  22 +++++++++++++++++-----
 3 files changed, 30 insertions(+), 13 deletions(-)

diffs (138 lines):

diff -r 5fd98fe69dc6 -r bc61cd75ced7 usr.sbin/tprof/tprof.8
--- a/usr.sbin/tprof/tprof.8    Fri Jul 13 11:14:14 2018 +0000
+++ b/usr.sbin/tprof/tprof.8    Fri Jul 13 12:04:50 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: tprof.8,v 1.7 2018/07/13 11:14:14 maxv Exp $
+.\"    $NetBSD: tprof.8,v 1.8 2018/07/13 12:04:50 maxv Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -90,11 +90,13 @@
 .Op Fl P
 .Op Fl p Ar pid
 .Op Fl s
+.Ar file
 .Xc
 Analyze the samples produced by a previous run of
 .Nm tprof ,
-and generate a plain text
-representation.
+stored in
+.Ar file ,
+and generate a plain text representation of them.
 .It Fl C
 Don't distinguish CPUs.
 All samples are treated as its CPU number is 0.
@@ -119,7 +121,7 @@
 samples into the file myfile.out.
 .Dl # tprof monitor -e llc-misses:k -o myfile.out sleep 20
 The following command displays the results of the sampling.
-.Dl # tprof analyze < myfile.out
+.Dl # tprof analyze myfile.out
 .Ed
 .Sh DIAGNOSTICS
 The
diff -r 5fd98fe69dc6 -r bc61cd75ced7 usr.sbin/tprof/tprof.c
--- a/usr.sbin/tprof/tprof.c    Fri Jul 13 11:14:14 2018 +0000
+++ b/usr.sbin/tprof/tprof.c    Fri Jul 13 12:04:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof.c,v 1.8 2018/07/13 11:03:36 maxv Exp $   */
+/*     $NetBSD: tprof.c,v 1.9 2018/07/13 12:04:50 maxv Exp $   */
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.8 2018/07/13 11:03:36 maxv Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.9 2018/07/13 12:04:50 maxv Exp $");
 #endif /* not lint */
 
 #include <sys/ioctl.h>
@@ -109,8 +109,8 @@
        fprintf(stderr, "\tmonitor -e name:option [-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, "\tanalyze [-C] [-k] [-L] [-P] [-p pid] [-s]\n");
-       fprintf(stderr, "\t\tAnalyze the samples from stdin.\n");
+       fprintf(stderr, "\tanalyze [-C] [-k] [-L] [-P] [-p pid] [-s] file\n");
+       fprintf(stderr, "\t\tAnalyze the samples of the file 'file'.\n");
 
        exit(EXIT_FAILURE);
 }
@@ -298,4 +298,7 @@
                        break;
                }
        }
+       if (ct->label == NULL) {
+               usage();
+       }
 }
diff -r 5fd98fe69dc6 -r bc61cd75ced7 usr.sbin/tprof/tprof_analyze.c
--- a/usr.sbin/tprof/tprof_analyze.c    Fri Jul 13 11:14:14 2018 +0000
+++ b/usr.sbin/tprof/tprof_analyze.c    Fri Jul 13 12:04:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof_analyze.c,v 1.1 2018/07/13 11:03:36 maxv Exp $   */
+/*     $NetBSD: tprof_analyze.c,v 1.2 2018/07/13 12:04:50 maxv Exp $   */
 
 /*
  * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tprof_analyze.c,v 1.1 2018/07/13 11:03:36 maxv Exp $");
+__RCSID("$NetBSD: tprof_analyze.c,v 1.2 2018/07/13 12:04:50 maxv Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -283,6 +283,7 @@
        bool kernel_only = false;
        extern char *optarg;
        extern int optind;
+       FILE *f;
 
        while ((ch = getopt(argc, argv, "CkLPp:s")) != -1) {
                uintmax_t val;
@@ -321,6 +322,15 @@
        argc -= optind;
        argv += optind;
 
+       if (argc == 0) {
+               errx(EXIT_FAILURE, "missing file name");
+       }
+
+       f = fopen(argv[0], "rb");
+       if (f == NULL) {
+               errx(EXIT_FAILURE, "fopen");
+       }
+
        ksymload();
        rb_tree_init(&addrtree, &addrtree_ops);
 
@@ -332,14 +342,14 @@
        while (/*CONSTCOND*/true) {
                struct addr *o;
                tprof_sample_t sample;
-               size_t n = fread(&sample, sizeof(sample), 1, stdin);
+               size_t n = fread(&sample, sizeof(sample), 1, f);
                bool in_kernel;
 
                if (n == 0) {
-                       if (feof(stdin)) {
+                       if (feof(f)) {
                                break;
                        }
-                       if (ferror(stdin)) {
+                       if (ferror(f)) {
                                err(EXIT_FAILURE, "fread");
                        }
                }
@@ -434,4 +444,6 @@
                    a->nsamples, a->pid, a->lwpid, a->cpuid, a->in_kernel,
                    a->addr, name);
        }
+
+       fclose(f);
 }



Home | Main Index | Thread Index | Old Index