2 * Copyright (c) 2005-2007, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
4 * Copyright (c) 2014, Adrian Chadd, Netflix Inc.
7 * Portions of this software were developed by A. Joseph Koshy under
8 * sponsorship from the FreeBSD Foundation and Google, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Transform a hwpmc(4) log into human readable form, and into
34 * gprof(1) compatible profiles.
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/endian.h>
43 #include <sys/imgact_aout.h>
44 #include <sys/imgact_elf.h>
47 #include <sys/queue.h>
48 #include <sys/socket.h>
52 #include <netinet/in.h>
72 #include "pmcstat_log.h"
73 #include "pmcpl_annotate_cg.h"
80 pmcpl_annotate_cg_process(struct pmcstat_process *pp, struct pmcstat_pmcrecord *pmcr,
81 uint32_t nsamples, uintfptr_t *cc, int usermode, uint32_t cpu)
83 struct pmcstat_pcmap *map;
84 struct pmcstat_symbol *sym;
86 struct pmcstat_image *image;
88 char filename[PATH_MAX], funcname[PATH_MAX];
91 (void) pmcr; (void) nsamples; (void) usermode; (void) cpu;
93 for (i = 0; i < (int) nsamples; i++) {
101 map = pmcstat_process_find_map(usermode ? pp : pmcstat_kernproc, cc[i]);
103 assert(cc[i] >= map->ppm_lowpc && cc[i] < map->ppm_highpc);
104 image = map->ppm_image;
105 newpc = cc[i] - (map->ppm_lowpc +
106 (image->pi_vaddr - image->pi_start));
107 sym = pmcstat_symbol_search(image, newpc);
110 if (map != NULL && image != NULL && sym != NULL) {
111 (void) pmcstat_image_addr2line(image, cc[i],
112 filename, sizeof(filename), &sline, funcname, sizeof(funcname));
115 if (map != NULL && sym != NULL) {
116 fprintf(args.pa_graphfile, "%p %s %s:%d\n",
122 fprintf(args.pa_graphfile, "%p <unknown> ??:0\n",
126 fprintf(args.pa_graphfile, "--\n");