/*
* Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
struct addr {
struct rb_node node;
uint64_t addr; /* address */
uint32_t pid; /* process id */
uint32_t lwpid; /* lwp id */
uint32_t cpuid; /* cpu id */
bool in_kernel; /* if addr is in the kernel address space */
unsigned int nsamples; /* number of samples taken for the address */
unsigned int ncount[TPROF_MAXCOUNTERS]; /* count per event */
};
/*
* print addresses and number of samples, preferably with
* resolved symbol names.
*/
printf("File: %s\n", argv[0]);
printf("Number of samples: %zu\n\n", nsamples);
printf("percentage nsamples ");
for (c = 0; c <= maxevent; c++)
printf("event#%02u ", c);
printf("pid lwp cpu k address symbol\n");
printf("------------ -------- ");
for (c = 0; c <= maxevent; c++)
printf("-------- ");
printf("------ ------ ---- - ---------------- ------\n");
for (i = 0; i < naddrs; i++) {
const char *name;
char buf[100];
uint64_t offset;
a = l[i];
if (a->in_kernel) {
name = ksymlookup(a->addr, &offset, NULL);
} else {
name = NULL;
}
if (name == NULL) {
(void)snprintf(buf, sizeof(buf), "<%016" PRIx64 ">",
a->addr);
name = buf;
} else if (offset != 0) {
(void)snprintf(buf, sizeof(buf), "%s+0x%" PRIx64, name,
offset);
name = buf;
}
perc = ((float)a->nsamples / (float)nsamples) * 100.0;
printf("%11f%% %8u", perc, a->nsamples);
for (c = 0; c <= maxevent; c++)
printf(" %8u", a->ncount[c]);