tprof_analyze.c revision 1.3.4.2 1 1.3.4.2 christos /* $NetBSD: tprof_analyze.c,v 1.3.4.2 2019/06/10 22:10:43 christos Exp $ */
2 1.3.4.2 christos
3 1.3.4.2 christos /*
4 1.3.4.2 christos * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
5 1.3.4.2 christos * All rights reserved.
6 1.3.4.2 christos *
7 1.3.4.2 christos * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 christos * modification, are permitted provided that the following conditions
9 1.3.4.2 christos * are met:
10 1.3.4.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 christos * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 christos * documentation and/or other materials provided with the distribution.
15 1.3.4.2 christos *
16 1.3.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.3.4.2 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.3.4.2 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.3.4.2 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.3.4.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.3.4.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.3.4.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.3.4.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.3.4.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.3.4.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.3.4.2 christos * SUCH DAMAGE.
27 1.3.4.2 christos */
28 1.3.4.2 christos
29 1.3.4.2 christos #include <sys/cdefs.h>
30 1.3.4.2 christos #ifndef lint
31 1.3.4.2 christos __RCSID("$NetBSD: tprof_analyze.c,v 1.3.4.2 2019/06/10 22:10:43 christos Exp $");
32 1.3.4.2 christos #endif /* not lint */
33 1.3.4.2 christos
34 1.3.4.2 christos #include <assert.h>
35 1.3.4.2 christos #include <err.h>
36 1.3.4.2 christos #include <errno.h>
37 1.3.4.2 christos #include <fcntl.h>
38 1.3.4.2 christos #include <gelf.h>
39 1.3.4.2 christos #include <inttypes.h>
40 1.3.4.2 christos #include <libelf.h>
41 1.3.4.2 christos #include <stdbool.h>
42 1.3.4.2 christos #include <stdlib.h>
43 1.3.4.2 christos #include <stdio.h>
44 1.3.4.2 christos #include <unistd.h>
45 1.3.4.2 christos #include <string.h>
46 1.3.4.2 christos #include <util.h>
47 1.3.4.2 christos #include <dev/tprof/tprof_ioctl.h>
48 1.3.4.2 christos #include "tprof.h"
49 1.3.4.2 christos
50 1.3.4.2 christos #define _PATH_KSYMS "/dev/ksyms"
51 1.3.4.2 christos
52 1.3.4.2 christos #include <sys/rbtree.h>
53 1.3.4.2 christos
54 1.3.4.2 christos static bool filter_by_pid;
55 1.3.4.2 christos static pid_t target_pid;
56 1.3.4.2 christos static bool per_symbol;
57 1.3.4.2 christos
58 1.3.4.2 christos struct addr {
59 1.3.4.2 christos struct rb_node node;
60 1.3.4.2 christos uint64_t addr; /* address */
61 1.3.4.2 christos uint32_t pid; /* process id */
62 1.3.4.2 christos uint32_t lwpid; /* lwp id */
63 1.3.4.2 christos uint32_t cpuid; /* cpu id */
64 1.3.4.2 christos bool in_kernel; /* if addr is in the kernel address space */
65 1.3.4.2 christos unsigned int nsamples; /* number of samples taken for the address */
66 1.3.4.2 christos };
67 1.3.4.2 christos
68 1.3.4.2 christos static rb_tree_t addrtree;
69 1.3.4.2 christos
70 1.3.4.2 christos struct sym {
71 1.3.4.2 christos char *name;
72 1.3.4.2 christos uint64_t value;
73 1.3.4.2 christos uint64_t size;
74 1.3.4.2 christos };
75 1.3.4.2 christos
76 1.3.4.2 christos static struct sym **syms = NULL;
77 1.3.4.2 christos static size_t nsyms = 0;
78 1.3.4.2 christos
79 1.3.4.2 christos static int
80 1.3.4.2 christos compare_value(const void *p1, const void *p2)
81 1.3.4.2 christos {
82 1.3.4.2 christos const struct sym *s1 = *(const struct sym * const *)p1;
83 1.3.4.2 christos const struct sym *s2 = *(const struct sym * const *)p2;
84 1.3.4.2 christos
85 1.3.4.2 christos if (s1->value > s2->value) {
86 1.3.4.2 christos return -1;
87 1.3.4.2 christos } else if (s1->value < s2->value) {
88 1.3.4.2 christos return 1;
89 1.3.4.2 christos }
90 1.3.4.2 christos /*
91 1.3.4.2 christos * to produce a stable result, it's better not to return 0
92 1.3.4.2 christos * even for __strong_alias.
93 1.3.4.2 christos */
94 1.3.4.2 christos if (s1->size > s2->size) {
95 1.3.4.2 christos return -1;
96 1.3.4.2 christos } else if (s1->size < s2->size) {
97 1.3.4.2 christos return 1;
98 1.3.4.2 christos }
99 1.3.4.2 christos return strcmp(s1->name, s2->name);
100 1.3.4.2 christos }
101 1.3.4.2 christos
102 1.3.4.2 christos static void
103 1.3.4.2 christos ksymload(void)
104 1.3.4.2 christos {
105 1.3.4.2 christos Elf *e;
106 1.3.4.2 christos Elf_Scn *s;
107 1.3.4.2 christos GElf_Shdr sh_store;
108 1.3.4.2 christos GElf_Shdr *sh;
109 1.3.4.2 christos Elf_Data *d;
110 1.3.4.2 christos int fd;
111 1.3.4.2 christos size_t size, i;
112 1.3.4.2 christos
113 1.3.4.2 christos fd = open(_PATH_KSYMS, O_RDONLY);
114 1.3.4.2 christos if (fd == -1) {
115 1.3.4.2 christos err(EXIT_FAILURE, "open");
116 1.3.4.2 christos }
117 1.3.4.2 christos if (elf_version(EV_CURRENT) == EV_NONE) {
118 1.3.4.2 christos goto elffail;
119 1.3.4.2 christos }
120 1.3.4.2 christos e = elf_begin(fd, ELF_C_READ, NULL);
121 1.3.4.2 christos if (e == NULL) {
122 1.3.4.2 christos goto elffail;
123 1.3.4.2 christos }
124 1.3.4.2 christos for (s = elf_nextscn(e, NULL); s != NULL; s = elf_nextscn(e, s)) {
125 1.3.4.2 christos sh = gelf_getshdr(s, &sh_store);
126 1.3.4.2 christos if (sh == NULL) {
127 1.3.4.2 christos goto elffail;
128 1.3.4.2 christos }
129 1.3.4.2 christos if (sh->sh_type == SHT_SYMTAB) {
130 1.3.4.2 christos break;
131 1.3.4.2 christos }
132 1.3.4.2 christos }
133 1.3.4.2 christos if (s == NULL) {
134 1.3.4.2 christos errx(EXIT_FAILURE, "no symtab");
135 1.3.4.2 christos }
136 1.3.4.2 christos d = elf_getdata(s, NULL);
137 1.3.4.2 christos if (d == NULL) {
138 1.3.4.2 christos goto elffail;
139 1.3.4.2 christos }
140 1.3.4.2 christos assert(sh->sh_size == d->d_size);
141 1.3.4.2 christos size = sh->sh_size / sh->sh_entsize;
142 1.3.4.2 christos for (i = 1; i < size; i++) {
143 1.3.4.2 christos GElf_Sym st_store;
144 1.3.4.2 christos GElf_Sym *st;
145 1.3.4.2 christos struct sym *sym;
146 1.3.4.2 christos
147 1.3.4.2 christos st = gelf_getsym(d, (int)i, &st_store);
148 1.3.4.2 christos if (st == NULL) {
149 1.3.4.2 christos goto elffail;
150 1.3.4.2 christos }
151 1.3.4.2 christos if (ELF_ST_TYPE(st->st_info) != STT_FUNC) {
152 1.3.4.2 christos continue;
153 1.3.4.2 christos }
154 1.3.4.2 christos sym = emalloc(sizeof(*sym));
155 1.3.4.2 christos sym->name = estrdup(elf_strptr(e, sh->sh_link, st->st_name));
156 1.3.4.2 christos sym->value = (uint64_t)st->st_value;
157 1.3.4.2 christos sym->size = st->st_size;
158 1.3.4.2 christos nsyms++;
159 1.3.4.2 christos syms = erealloc(syms, sizeof(*syms) * nsyms);
160 1.3.4.2 christos syms[nsyms - 1] = sym;
161 1.3.4.2 christos }
162 1.3.4.2 christos qsort(syms, nsyms, sizeof(*syms), compare_value);
163 1.3.4.2 christos return;
164 1.3.4.2 christos elffail:
165 1.3.4.2 christos errx(EXIT_FAILURE, "libelf: %s", elf_errmsg(elf_errno()));
166 1.3.4.2 christos }
167 1.3.4.2 christos
168 1.3.4.2 christos static const char *
169 1.3.4.2 christos ksymlookup(uint64_t value, uint64_t *offset)
170 1.3.4.2 christos {
171 1.3.4.2 christos size_t hi;
172 1.3.4.2 christos size_t lo;
173 1.3.4.2 christos size_t i;
174 1.3.4.2 christos
175 1.3.4.2 christos /*
176 1.3.4.2 christos * try to find the smallest i for which syms[i]->value <= value.
177 1.3.4.2 christos * syms[] is ordered by syms[]->value in the descending order.
178 1.3.4.2 christos */
179 1.3.4.2 christos
180 1.3.4.2 christos hi = nsyms - 1;
181 1.3.4.2 christos lo = 0;
182 1.3.4.2 christos while (lo < hi) {
183 1.3.4.2 christos const size_t mid = (lo + hi) / 2;
184 1.3.4.2 christos const struct sym *sym = syms[mid];
185 1.3.4.2 christos
186 1.3.4.2 christos assert(syms[lo]->value >= sym->value);
187 1.3.4.2 christos assert(sym->value >= syms[hi]->value);
188 1.3.4.2 christos if (sym->value <= value) {
189 1.3.4.2 christos hi = mid;
190 1.3.4.2 christos continue;
191 1.3.4.2 christos }
192 1.3.4.2 christos lo = mid + 1;
193 1.3.4.2 christos }
194 1.3.4.2 christos assert(lo == nsyms - 1 || syms[lo]->value <= value);
195 1.3.4.2 christos assert(lo == 0 || syms[lo - 1]->value > value);
196 1.3.4.2 christos for (i = lo; i < nsyms; i++) {
197 1.3.4.2 christos const struct sym *sym = syms[i];
198 1.3.4.2 christos
199 1.3.4.2 christos if (sym->value <= value &&
200 1.3.4.2 christos (sym->size == 0 || value - sym->value <= sym->size )) {
201 1.3.4.2 christos *offset = value - sym->value;
202 1.3.4.2 christos return sym->name;
203 1.3.4.2 christos }
204 1.3.4.2 christos if (sym->size != 0 && sym->value + sym->size < value) {
205 1.3.4.2 christos break;
206 1.3.4.2 christos }
207 1.3.4.2 christos }
208 1.3.4.2 christos return NULL;
209 1.3.4.2 christos }
210 1.3.4.2 christos
211 1.3.4.2 christos static signed int
212 1.3.4.2 christos addrtree_compare_key(void *ctx, const void *n1, const void *keyp)
213 1.3.4.2 christos {
214 1.3.4.2 christos const struct addr *a1 = n1;
215 1.3.4.2 christos const struct addr *a2 = (const struct addr *)keyp;
216 1.3.4.2 christos
217 1.3.4.2 christos if (a1->addr > a2->addr) {
218 1.3.4.2 christos return 1;
219 1.3.4.2 christos } else if (a1->addr < a2->addr) {
220 1.3.4.2 christos return -1;
221 1.3.4.2 christos }
222 1.3.4.2 christos if (a1->pid > a2->pid) {
223 1.3.4.2 christos return -1;
224 1.3.4.2 christos } else if (a1->pid < a2->pid) {
225 1.3.4.2 christos return 1;
226 1.3.4.2 christos }
227 1.3.4.2 christos if (a1->lwpid > a2->lwpid) {
228 1.3.4.2 christos return -1;
229 1.3.4.2 christos } else if (a1->lwpid < a2->lwpid) {
230 1.3.4.2 christos return 1;
231 1.3.4.2 christos }
232 1.3.4.2 christos if (a1->cpuid > a2->cpuid) {
233 1.3.4.2 christos return -1;
234 1.3.4.2 christos } else if (a1->cpuid < a2->cpuid) {
235 1.3.4.2 christos return 1;
236 1.3.4.2 christos }
237 1.3.4.2 christos if (a1->in_kernel > a2->in_kernel) {
238 1.3.4.2 christos return -1;
239 1.3.4.2 christos } else if (a1->in_kernel < a2->in_kernel) {
240 1.3.4.2 christos return 1;
241 1.3.4.2 christos }
242 1.3.4.2 christos return 0;
243 1.3.4.2 christos }
244 1.3.4.2 christos
245 1.3.4.2 christos static signed int
246 1.3.4.2 christos addrtree_compare_nodes(void *ctx, const void *n1, const void *n2)
247 1.3.4.2 christos {
248 1.3.4.2 christos const struct addr *a2 = n2;
249 1.3.4.2 christos
250 1.3.4.2 christos return addrtree_compare_key(ctx, n1, a2);
251 1.3.4.2 christos }
252 1.3.4.2 christos
253 1.3.4.2 christos static const rb_tree_ops_t addrtree_ops = {
254 1.3.4.2 christos .rbto_compare_nodes = addrtree_compare_nodes,
255 1.3.4.2 christos .rbto_compare_key = addrtree_compare_key,
256 1.3.4.2 christos };
257 1.3.4.2 christos
258 1.3.4.2 christos static int
259 1.3.4.2 christos compare_nsamples(const void *p1, const void *p2)
260 1.3.4.2 christos {
261 1.3.4.2 christos const struct addr *a1 = *(const struct addr * const *)p1;
262 1.3.4.2 christos const struct addr *a2 = *(const struct addr * const *)p2;
263 1.3.4.2 christos
264 1.3.4.2 christos if (a1->nsamples > a2->nsamples) {
265 1.3.4.2 christos return -1;
266 1.3.4.2 christos } else if (a1->nsamples < a2->nsamples) {
267 1.3.4.2 christos return 1;
268 1.3.4.2 christos }
269 1.3.4.2 christos return 0;
270 1.3.4.2 christos }
271 1.3.4.2 christos
272 1.3.4.2 christos void
273 1.3.4.2 christos tprof_analyze(int argc, char **argv)
274 1.3.4.2 christos {
275 1.3.4.2 christos struct addr *a;
276 1.3.4.2 christos struct addr **l;
277 1.3.4.2 christos struct addr **p;
278 1.3.4.2 christos size_t naddrs, nsamples, i;
279 1.3.4.2 christos float perc;
280 1.3.4.2 christos int ch;
281 1.3.4.2 christos bool distinguish_processes = true;
282 1.3.4.2 christos bool distinguish_cpus = true;
283 1.3.4.2 christos bool distinguish_lwps = true;
284 1.3.4.2 christos bool kernel_only = false;
285 1.3.4.2 christos extern char *optarg;
286 1.3.4.2 christos extern int optind;
287 1.3.4.2 christos FILE *f;
288 1.3.4.2 christos
289 1.3.4.2 christos while ((ch = getopt(argc, argv, "CkLPp:s")) != -1) {
290 1.3.4.2 christos uintmax_t val;
291 1.3.4.2 christos char *ep;
292 1.3.4.2 christos
293 1.3.4.2 christos switch (ch) {
294 1.3.4.2 christos case 'C': /* don't distinguish cpus */
295 1.3.4.2 christos distinguish_cpus = false;
296 1.3.4.2 christos break;
297 1.3.4.2 christos case 'k': /* kernel only */
298 1.3.4.2 christos kernel_only = true;
299 1.3.4.2 christos break;
300 1.3.4.2 christos case 'L': /* don't distinguish lwps */
301 1.3.4.2 christos distinguish_lwps = false;
302 1.3.4.2 christos break;
303 1.3.4.2 christos case 'p': /* only for the process for the given pid */
304 1.3.4.2 christos errno = 0;
305 1.3.4.2 christos val = strtoumax(optarg, &ep, 10);
306 1.3.4.2 christos if (optarg[0] == 0 || *ep != 0 ||
307 1.3.4.2 christos val > INT32_MAX) {
308 1.3.4.2 christos errx(EXIT_FAILURE, "invalid p option");
309 1.3.4.2 christos }
310 1.3.4.2 christos target_pid = val;
311 1.3.4.2 christos filter_by_pid = true;
312 1.3.4.2 christos break;
313 1.3.4.2 christos case 'P': /* don't distinguish processes */
314 1.3.4.2 christos distinguish_processes = false;
315 1.3.4.2 christos break;
316 1.3.4.2 christos case 's': /* per symbol */
317 1.3.4.2 christos per_symbol = true;
318 1.3.4.2 christos break;
319 1.3.4.2 christos default:
320 1.3.4.2 christos exit(EXIT_FAILURE);
321 1.3.4.2 christos }
322 1.3.4.2 christos }
323 1.3.4.2 christos argc -= optind;
324 1.3.4.2 christos argv += optind;
325 1.3.4.2 christos
326 1.3.4.2 christos if (argc == 0) {
327 1.3.4.2 christos errx(EXIT_FAILURE, "missing file name");
328 1.3.4.2 christos }
329 1.3.4.2 christos
330 1.3.4.2 christos f = fopen(argv[0], "rb");
331 1.3.4.2 christos if (f == NULL) {
332 1.3.4.2 christos errx(EXIT_FAILURE, "fopen");
333 1.3.4.2 christos }
334 1.3.4.2 christos
335 1.3.4.2 christos ksymload();
336 1.3.4.2 christos rb_tree_init(&addrtree, &addrtree_ops);
337 1.3.4.2 christos
338 1.3.4.2 christos /*
339 1.3.4.2 christos * read and count samples.
340 1.3.4.2 christos */
341 1.3.4.2 christos
342 1.3.4.2 christos naddrs = 0;
343 1.3.4.2 christos nsamples = 0;
344 1.3.4.2 christos while (/*CONSTCOND*/true) {
345 1.3.4.2 christos struct addr *o;
346 1.3.4.2 christos tprof_sample_t sample;
347 1.3.4.2 christos size_t n = fread(&sample, sizeof(sample), 1, f);
348 1.3.4.2 christos bool in_kernel;
349 1.3.4.2 christos
350 1.3.4.2 christos if (n == 0) {
351 1.3.4.2 christos if (feof(f)) {
352 1.3.4.2 christos break;
353 1.3.4.2 christos }
354 1.3.4.2 christos if (ferror(f)) {
355 1.3.4.2 christos err(EXIT_FAILURE, "fread");
356 1.3.4.2 christos }
357 1.3.4.2 christos }
358 1.3.4.2 christos if (filter_by_pid && (pid_t)sample.s_pid != target_pid) {
359 1.3.4.2 christos continue;
360 1.3.4.2 christos }
361 1.3.4.2 christos in_kernel = (sample.s_flags & TPROF_SAMPLE_INKERNEL) != 0;
362 1.3.4.2 christos if (kernel_only && !in_kernel) {
363 1.3.4.2 christos continue;
364 1.3.4.2 christos }
365 1.3.4.2 christos a = emalloc(sizeof(*a));
366 1.3.4.2 christos a->addr = (uint64_t)sample.s_pc;
367 1.3.4.2 christos if (distinguish_processes) {
368 1.3.4.2 christos a->pid = sample.s_pid;
369 1.3.4.2 christos } else {
370 1.3.4.2 christos a->pid = 0;
371 1.3.4.2 christos }
372 1.3.4.2 christos if (distinguish_lwps) {
373 1.3.4.2 christos a->lwpid = sample.s_lwpid;
374 1.3.4.2 christos } else {
375 1.3.4.2 christos a->lwpid = 0;
376 1.3.4.2 christos }
377 1.3.4.2 christos if (distinguish_cpus) {
378 1.3.4.2 christos a->cpuid = sample.s_cpuid;
379 1.3.4.2 christos } else {
380 1.3.4.2 christos a->cpuid = 0;
381 1.3.4.2 christos }
382 1.3.4.2 christos a->in_kernel = in_kernel;
383 1.3.4.2 christos if (per_symbol) {
384 1.3.4.2 christos const char *name;
385 1.3.4.2 christos uint64_t offset;
386 1.3.4.2 christos
387 1.3.4.2 christos name = ksymlookup(a->addr, &offset);
388 1.3.4.2 christos if (name != NULL) {
389 1.3.4.2 christos a->addr -= offset;
390 1.3.4.2 christos }
391 1.3.4.2 christos }
392 1.3.4.2 christos a->nsamples = 1;
393 1.3.4.2 christos o = rb_tree_insert_node(&addrtree, a);
394 1.3.4.2 christos if (o != a) {
395 1.3.4.2 christos assert(a->addr == o->addr);
396 1.3.4.2 christos assert(a->pid == o->pid);
397 1.3.4.2 christos assert(a->lwpid == o->lwpid);
398 1.3.4.2 christos assert(a->cpuid == o->cpuid);
399 1.3.4.2 christos assert(a->in_kernel == o->in_kernel);
400 1.3.4.2 christos free(a);
401 1.3.4.2 christos o->nsamples++;
402 1.3.4.2 christos } else {
403 1.3.4.2 christos naddrs++;
404 1.3.4.2 christos }
405 1.3.4.2 christos nsamples++;
406 1.3.4.2 christos }
407 1.3.4.2 christos
408 1.3.4.2 christos /*
409 1.3.4.2 christos * sort samples by addresses.
410 1.3.4.2 christos */
411 1.3.4.2 christos
412 1.3.4.2 christos l = emalloc(naddrs * sizeof(*l));
413 1.3.4.2 christos p = l;
414 1.3.4.2 christos RB_TREE_FOREACH(a, &addrtree) {
415 1.3.4.2 christos *p++ = a;
416 1.3.4.2 christos }
417 1.3.4.2 christos assert(l + naddrs == p);
418 1.3.4.2 christos qsort(l, naddrs, sizeof(*l), compare_nsamples);
419 1.3.4.2 christos
420 1.3.4.2 christos /*
421 1.3.4.2 christos * print addresses and number of samples, preferably with
422 1.3.4.2 christos * resolved symbol names.
423 1.3.4.2 christos */
424 1.3.4.2 christos printf("File: %s\n", argv[0]);
425 1.3.4.2 christos printf("Number of samples: %zu\n\n", nsamples);
426 1.3.4.2 christos printf("percentage nsamples pid lwp cpu k address symbol\n");
427 1.3.4.2 christos printf("------------ -------- ------ ---- ---- - ---------------- ------\n");
428 1.3.4.2 christos for (i = 0; i < naddrs; i++) {
429 1.3.4.2 christos const char *name;
430 1.3.4.2 christos char buf[100];
431 1.3.4.2 christos uint64_t offset;
432 1.3.4.2 christos
433 1.3.4.2 christos a = l[i];
434 1.3.4.2 christos if (a->in_kernel) {
435 1.3.4.2 christos name = ksymlookup(a->addr, &offset);
436 1.3.4.2 christos } else {
437 1.3.4.2 christos name = NULL;
438 1.3.4.2 christos }
439 1.3.4.2 christos if (name == NULL) {
440 1.3.4.2 christos (void)snprintf(buf, sizeof(buf), "<%016" PRIx64 ">",
441 1.3.4.2 christos a->addr);
442 1.3.4.2 christos name = buf;
443 1.3.4.2 christos } else if (offset != 0) {
444 1.3.4.2 christos (void)snprintf(buf, sizeof(buf), "%s+0x%" PRIx64, name,
445 1.3.4.2 christos offset);
446 1.3.4.2 christos name = buf;
447 1.3.4.2 christos }
448 1.3.4.2 christos
449 1.3.4.2 christos perc = ((float)a->nsamples / (float)nsamples) * 100.0;
450 1.3.4.2 christos
451 1.3.4.2 christos printf("%11f%% %8u %6" PRIu32 " %4" PRIu32 " %4" PRIu32 " %u %016"
452 1.3.4.2 christos PRIx64 " %s\n",
453 1.3.4.2 christos perc,
454 1.3.4.2 christos a->nsamples, a->pid, a->lwpid, a->cpuid, a->in_kernel,
455 1.3.4.2 christos a->addr, name);
456 1.3.4.2 christos }
457 1.3.4.2 christos
458 1.3.4.2 christos fclose(f);
459 1.3.4.2 christos }
460