]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms | |
5 | * of the Common Development and Distribution License | |
6 | * (the "License"). You may not use this file except | |
7 | * in compliance with the License. | |
8 | * | |
9 | * You can obtain a copy of the license at | |
10 | * src/OPENSOLARIS.LICENSE | |
11 | * or http://www.opensolaris.org/os/licensing. | |
12 | * See the License for the specific language governing | |
13 | * permissions and limitations under the License. | |
14 | * | |
15 | * When distributing Covered Code, include this CDDL | |
16 | * HEADER in each file and include the License file at | |
17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, | |
18 | * add the following below this CDDL HEADER, with the | |
19 | * fields enclosed by brackets "[]" replaced with your | |
20 | * own identifying information: Portions Copyright [yyyy] | |
21 | * [name of copyright owner] | |
22 | * | |
23 | * CDDL HEADER END | |
24 | */ | |
25 | ||
26 | /* | |
27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | */ | |
30 | ||
31 | #include <unistd.h> | |
32 | #include <stdio.h> | |
33 | #include <stdlib.h> | |
34 | #include <string.h> | |
35 | #include <sys/time.h> | |
36 | #include <time.h> | |
37 | #include <tattle.h> | |
38 | #include "libmicro.h" | |
39 | #include <math.h> | |
40 | ||
41 | ||
42 | #ifdef USE_RDTSC | |
43 | #ifdef __GNUC__ | |
44 | #define ENABLE_RDTSC 1 | |
45 | #endif | |
46 | #endif | |
47 | ||
48 | /* | |
49 | * dummy so we can link w/ libmicro | |
50 | */ | |
51 | ||
52 | /*ARGSUSED*/ | |
53 | int | |
54 | benchmark(void *tsd, result_t *res) | |
55 | { | |
56 | return (0); | |
57 | } | |
58 | ||
59 | static void | |
60 | cleanup(char *s) | |
61 | { | |
62 | char *o = s; | |
63 | char *e; | |
64 | ||
65 | while (*s == ' ') | |
66 | s++; | |
67 | ||
68 | if (o != s) | |
69 | (void) strcpy(o, s); | |
70 | ||
71 | e = o; | |
72 | ||
73 | while (*e != 0) | |
74 | e++; | |
75 | ||
76 | e--; | |
77 | ||
78 | while (*e == ' ' && e > o) | |
79 | *e-- = 0; | |
80 | ||
81 | } | |
82 | ||
83 | ||
84 | int | |
85 | main(int argc, char *argv[]) | |
86 | { | |
87 | int c; | |
88 | ||
89 | if (strlen(compiler_version) > 30) | |
90 | compiler_version[30] = 0; | |
91 | ||
92 | cleanup(compiler_version); | |
93 | cleanup(extra_compiler_flags); | |
94 | ||
95 | while ((c = getopt(argc, argv, "vcfrsVTR")) != -1) { | |
96 | switch (c) { | |
97 | case 'V': | |
98 | (void) printf("%s\n", LIBMICRO_VERSION); | |
99 | break; | |
100 | case 'v': | |
101 | (void) printf("%s\n", compiler_version); | |
102 | break; | |
103 | case 'c': | |
104 | (void) printf("%s\n", CC); | |
105 | break; | |
106 | case 'f': | |
107 | if (strlen(extra_compiler_flags) == 0) | |
108 | (void) printf("[none]\n"); | |
109 | else | |
110 | (void) printf("%s\n", extra_compiler_flags); | |
111 | break; | |
112 | ||
113 | case 's': | |
114 | (void) printf("%d\n", sizeof (long)); | |
115 | break; | |
116 | ||
117 | case 'r': | |
118 | ||
119 | (void) printf("%lld nsecs\n", get_nsecs_resolution()); | |
120 | break; | |
121 | ||
122 | case 'R': | |
123 | #ifdef ENABLE_RDTSC | |
124 | { | |
125 | struct timeval s; | |
126 | struct timeval f; | |
127 | long long start_nsecs; | |
128 | long long end_nsecs; | |
129 | long elapsed_usecs; | |
130 | ||
131 | gettimeofday(&s, NULL); | |
132 | start_nsecs = rdtsc(); | |
133 | for (;;) { | |
134 | gettimeofday(&f, NULL); | |
135 | elapsed_usecs = (f.tv_sec - s.tv_sec) * | |
136 | 1000000 + (f.tv_usec - s.tv_usec); | |
137 | if (elapsed_usecs > 1000000) | |
138 | break; | |
139 | } | |
140 | end_nsecs = rdtsc(); | |
141 | (void) printf("LIBMICRO_HZ=%lld\n", | |
142 | (long long)elapsed_usecs * | |
143 | (end_nsecs - start_nsecs) / 1000000LL); | |
144 | } | |
145 | #else | |
146 | (void) printf("\n"); | |
147 | #endif | |
148 | break; | |
149 | } | |
150 | } | |
151 | ||
152 | exit(0); | |
153 | return (0); | |
154 | } |