Module Name: src
Committed By: maxv
Date: Fri Jul 13 12:04:50 UTC 2018
Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c tprof_analyze.c
Log Message:
Ask for a file path with the "analyze" command, instead of reading stdin.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/tprof/tprof_analyze.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.7 src/usr.sbin/tprof/tprof.8:1.8
--- src/usr.sbin/tprof/tprof.8:1.7 Fri Jul 13 11:14:14 2018
+++ src/usr.sbin/tprof/tprof.8 Fri Jul 13 12:04:50 2018
@@ -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 @@ The default is
.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 @@ The following command profiles the syste
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
Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.8 src/usr.sbin/tprof/tprof.c:1.9
--- src/usr.sbin/tprof/tprof.c:1.8 Fri Jul 13 11:03:36 2018
+++ src/usr.sbin/tprof/tprof.c Fri Jul 13 12:04:50 2018
@@ -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 @@ usage(void)
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 @@ main(int argc, char *argv[])
break;
}
}
+ if (ct->label == NULL) {
+ usage();
+ }
}
Index: src/usr.sbin/tprof/tprof_analyze.c
diff -u src/usr.sbin/tprof/tprof_analyze.c:1.1 src/usr.sbin/tprof/tprof_analyze.c:1.2
--- src/usr.sbin/tprof/tprof_analyze.c:1.1 Fri Jul 13 11:03:36 2018
+++ src/usr.sbin/tprof/tprof_analyze.c Fri Jul 13 12:04:50 2018
@@ -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 @@ tprof_analyze(int argc, char **argv)
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 @@ tprof_analyze(int argc, char **argv)
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 @@ tprof_analyze(int argc, char **argv)
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 @@ tprof_analyze(int argc, char **argv)
a->nsamples, a->pid, a->lwpid, a->cpuid, a->in_kernel,
a->addr, name);
}
+
+ fclose(f);
}