gperf.c
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*
*
* gperf - host side of profiler tool
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "gperf.h"
#ifdef __sgi
#include <a.out.h>
typedef SYMR SYMENT;
#include <ldfcn.h>
#endif
/*
* G l o b a l s
*/
float Threshold = 1.0; /* % cutoff for printing results */
unsigned int ServerMode = 0; /* app initiates transfer of data */
unsigned int PrintCounts = 0;
unsigned int PrintRealTime = 0;
char *Namelist = "a.out"; /* namelist file */
#ifdef __sgi
LDFILE *Ldptr = NULL;
#endif
/*
* Usage message
*/
void
print_usage( char *prog)
{
printf("usage: %s [-c] [-r] [-s] [-t threshold] a.out\n", prog);
printf("\t-c\t\tprint raw counts\n");
printf("\t-r\t\tprint real time\n");
printf("\t-s\t\tserver mode\n");
printf("\t-t threshold\tminimum %% or count to print, default 1.0\n");
exit(0);
}
/*
* M a i n
*/
main(int argc, char **argv)
{
int i;
int c;
while ((c = getopt(argc, argv, "t:crs")) != EOF) {
switch (c) {
case 't':
Threshold = atof(optarg);
break;
case 's':
ServerMode = 1;
break;
case 'r':
PrintRealTime = 1;
break;
case 'c':
PrintCounts = 1;
break;
case '?':
print_usage(argv[0]);
break;
}
}
if (argc - optind == 1) {
Namelist = argv[optind];
} else {
print_usage(argv[0]);
}
#ifdef __sgi
/*
* Check for input errors
*/
if ((Ldptr = ldopen(Namelist, Ldptr)) == NULL) {
fprintf(stderr,"file = %s\n", Namelist);
error("cannot open a.out file");
exit(1);
}
#endif
if (Threshold < 0.0) {
Threshold = 0.0;
}
/*
* Start profile server
*/
profServerInit();
/*
* Tell application to dump profile data
*/
profServer();
}
/*
* Print error
*/
void
error(char *s)
{
printf("error: %s\n", s);
exit(1);
}