10b86b1bbSFabien Thomas /*- 21de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 31de7b4b8SPedro F. Giffuni * 40b86b1bbSFabien Thomas * Copyright (c) 2005-2007, Joseph Koshy 50b86b1bbSFabien Thomas * Copyright (c) 2007 The FreeBSD Foundation 60b86b1bbSFabien Thomas * All rights reserved. 70b86b1bbSFabien Thomas * 80b86b1bbSFabien Thomas * Portions of this software were developed by A. Joseph Koshy under 90b86b1bbSFabien Thomas * sponsorship from the FreeBSD Foundation and Google, Inc. 100b86b1bbSFabien Thomas * 110b86b1bbSFabien Thomas * Redistribution and use in source and binary forms, with or without 120b86b1bbSFabien Thomas * modification, are permitted provided that the following conditions 130b86b1bbSFabien Thomas * are met: 140b86b1bbSFabien Thomas * 1. Redistributions of source code must retain the above copyright 150b86b1bbSFabien Thomas * notice, this list of conditions and the following disclaimer. 160b86b1bbSFabien Thomas * 2. Redistributions in binary form must reproduce the above copyright 170b86b1bbSFabien Thomas * notice, this list of conditions and the following disclaimer in the 180b86b1bbSFabien Thomas * documentation and/or other materials provided with the distribution. 190b86b1bbSFabien Thomas * 200b86b1bbSFabien Thomas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 210b86b1bbSFabien Thomas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 220b86b1bbSFabien Thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230b86b1bbSFabien Thomas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 240b86b1bbSFabien Thomas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250b86b1bbSFabien Thomas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260b86b1bbSFabien Thomas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270b86b1bbSFabien Thomas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280b86b1bbSFabien Thomas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290b86b1bbSFabien Thomas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300b86b1bbSFabien Thomas * SUCH DAMAGE. 310b86b1bbSFabien Thomas */ 320b86b1bbSFabien Thomas 330b86b1bbSFabien Thomas /* 340b86b1bbSFabien Thomas * Transform a hwpmc(4) log into human readable form, and into 350b86b1bbSFabien Thomas * gprof(1) compatible profiles. 360b86b1bbSFabien Thomas */ 370b86b1bbSFabien Thomas 380b86b1bbSFabien Thomas #include <sys/cdefs.h> 390b86b1bbSFabien Thomas __FBSDID("$FreeBSD$"); 400b86b1bbSFabien Thomas 410b86b1bbSFabien Thomas #include <sys/param.h> 420b86b1bbSFabien Thomas #include <sys/endian.h> 430b86b1bbSFabien Thomas #include <sys/gmon.h> 440b86b1bbSFabien Thomas #include <sys/imgact_aout.h> 450b86b1bbSFabien Thomas #include <sys/imgact_elf.h> 460b86b1bbSFabien Thomas #include <sys/mman.h> 470b86b1bbSFabien Thomas #include <sys/pmc.h> 480b86b1bbSFabien Thomas #include <sys/queue.h> 490b86b1bbSFabien Thomas #include <sys/socket.h> 500b86b1bbSFabien Thomas #include <sys/stat.h> 510b86b1bbSFabien Thomas #include <sys/wait.h> 520b86b1bbSFabien Thomas 530b86b1bbSFabien Thomas #include <netinet/in.h> 540b86b1bbSFabien Thomas 550b86b1bbSFabien Thomas #include <assert.h> 560b86b1bbSFabien Thomas #include <curses.h> 570b86b1bbSFabien Thomas #include <err.h> 580b86b1bbSFabien Thomas #include <errno.h> 590b86b1bbSFabien Thomas #include <fcntl.h> 600b86b1bbSFabien Thomas #include <gelf.h> 61*ec3b2a79SMateusz Guzik #include <inttypes.h> 620b86b1bbSFabien Thomas #include <libgen.h> 630b86b1bbSFabien Thomas #include <limits.h> 640b86b1bbSFabien Thomas #include <netdb.h> 650b86b1bbSFabien Thomas #include <pmc.h> 660b86b1bbSFabien Thomas #include <pmclog.h> 670b86b1bbSFabien Thomas #include <sysexits.h> 680b86b1bbSFabien Thomas #include <stdint.h> 690b86b1bbSFabien Thomas #include <stdio.h> 700b86b1bbSFabien Thomas #include <stdlib.h> 710b86b1bbSFabien Thomas #include <string.h> 720b86b1bbSFabien Thomas #include <unistd.h> 730b86b1bbSFabien Thomas 740b86b1bbSFabien Thomas #include "pmcstat.h" 750b86b1bbSFabien Thomas #include "pmcstat_log.h" 760b86b1bbSFabien Thomas #include "pmcstat_top.h" 770b86b1bbSFabien Thomas #include "pmcpl_callgraph.h" 780b86b1bbSFabien Thomas 79d27927f7SRuslan Bukin #define min(A,B) ((A) < (B) ? (A) : (B)) 80d27927f7SRuslan Bukin #define max(A,B) ((A) > (B) ? (A) : (B)) 81d27927f7SRuslan Bukin 820b86b1bbSFabien Thomas /* Get the sample value in percent related to nsamples. */ 830b86b1bbSFabien Thomas #define PMCPL_CG_COUNTP(a) \ 840b86b1bbSFabien Thomas ((a)->pcg_count * 100.0 / nsamples) 850b86b1bbSFabien Thomas 860b86b1bbSFabien Thomas /* 870b86b1bbSFabien Thomas * The toplevel CG nodes (i.e., with rank == 0) are placed in a hash table. 880b86b1bbSFabien Thomas */ 890b86b1bbSFabien Thomas 900b86b1bbSFabien Thomas struct pmcstat_cgnode_hash_list pmcstat_cgnode_hash[PMCSTAT_NHASH]; 910b86b1bbSFabien Thomas int pmcstat_cgnode_hash_count; 920b86b1bbSFabien Thomas 930b86b1bbSFabien Thomas static pmcstat_interned_string pmcstat_previous_filename_printed; 940b86b1bbSFabien Thomas 950b86b1bbSFabien Thomas static struct pmcstat_cgnode * 960b86b1bbSFabien Thomas pmcstat_cgnode_allocate(struct pmcstat_image *image, uintfptr_t pc) 970b86b1bbSFabien Thomas { 980b86b1bbSFabien Thomas struct pmcstat_cgnode *cg; 990b86b1bbSFabien Thomas 1000b86b1bbSFabien Thomas if ((cg = malloc(sizeof(*cg))) == NULL) 1010b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot allocate callgraph node"); 1020b86b1bbSFabien Thomas 1030b86b1bbSFabien Thomas cg->pcg_image = image; 1040b86b1bbSFabien Thomas cg->pcg_func = pc; 1050b86b1bbSFabien Thomas 1060b86b1bbSFabien Thomas cg->pcg_count = 0; 1070b86b1bbSFabien Thomas cg->pcg_nchildren = 0; 1080b86b1bbSFabien Thomas LIST_INIT(&cg->pcg_children); 1090b86b1bbSFabien Thomas 1100b86b1bbSFabien Thomas return (cg); 1110b86b1bbSFabien Thomas } 1120b86b1bbSFabien Thomas 1130b86b1bbSFabien Thomas /* 1140b86b1bbSFabien Thomas * Free a node and its children. 1150b86b1bbSFabien Thomas */ 1160b86b1bbSFabien Thomas static void 1170b86b1bbSFabien Thomas pmcstat_cgnode_free(struct pmcstat_cgnode *cg) 1180b86b1bbSFabien Thomas { 1190b86b1bbSFabien Thomas struct pmcstat_cgnode *cgc, *cgtmp; 1200b86b1bbSFabien Thomas 1210b86b1bbSFabien Thomas LIST_FOREACH_SAFE(cgc, &cg->pcg_children, pcg_sibling, cgtmp) 1220b86b1bbSFabien Thomas pmcstat_cgnode_free(cgc); 1230b86b1bbSFabien Thomas free(cg); 1240b86b1bbSFabien Thomas } 1250b86b1bbSFabien Thomas 1260b86b1bbSFabien Thomas /* 1270b86b1bbSFabien Thomas * Look for a callgraph node associated with pmc `pmcid' in the global 1280b86b1bbSFabien Thomas * hash table that corresponds to the given `pc' value in the process 1290b86b1bbSFabien Thomas * `pp'. 1300b86b1bbSFabien Thomas */ 1310b86b1bbSFabien Thomas static struct pmcstat_cgnode * 1320b86b1bbSFabien Thomas pmcstat_cgnode_hash_lookup_pc(struct pmcstat_process *pp, pmc_id_t pmcid, 1330b86b1bbSFabien Thomas uintfptr_t pc, int usermode) 1340b86b1bbSFabien Thomas { 1350b86b1bbSFabien Thomas struct pmcstat_pcmap *ppm; 1360b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 1370b86b1bbSFabien Thomas struct pmcstat_image *image; 1380b86b1bbSFabien Thomas struct pmcstat_cgnode *cg; 1390b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *h; 1400b86b1bbSFabien Thomas uintfptr_t loadaddress; 1410b86b1bbSFabien Thomas unsigned int i, hash; 1420b86b1bbSFabien Thomas 1430b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(usermode ? pp : pmcstat_kernproc, pc); 1440b86b1bbSFabien Thomas if (ppm == NULL) 1450b86b1bbSFabien Thomas return (NULL); 1460b86b1bbSFabien Thomas 1470b86b1bbSFabien Thomas image = ppm->ppm_image; 1480b86b1bbSFabien Thomas 1490b86b1bbSFabien Thomas loadaddress = ppm->ppm_lowpc + image->pi_vaddr - image->pi_start; 1500b86b1bbSFabien Thomas pc -= loadaddress; /* Convert to an offset in the image. */ 1510b86b1bbSFabien Thomas 1520b86b1bbSFabien Thomas /* 1530b86b1bbSFabien Thomas * Try determine the function at this offset. If we can't 1540b86b1bbSFabien Thomas * find a function round leave the `pc' value alone. 1550b86b1bbSFabien Thomas */ 15694e9ef85SMateusz Guzik if (!(args.pa_flags & (FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET))) { 1570b86b1bbSFabien Thomas if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 1580b86b1bbSFabien Thomas pc = sym->ps_start; 159eb707d60SFabien Thomas else 160eb707d60SFabien Thomas pmcstat_stats.ps_samples_unknown_function++; 16194e9ef85SMateusz Guzik } 1620b86b1bbSFabien Thomas 1630b86b1bbSFabien Thomas for (hash = i = 0; i < sizeof(uintfptr_t); i++) 1640b86b1bbSFabien Thomas hash += (pc >> i) & 0xFF; 1650b86b1bbSFabien Thomas 1660b86b1bbSFabien Thomas hash &= PMCSTAT_HASH_MASK; 1670b86b1bbSFabien Thomas 1680b86b1bbSFabien Thomas cg = NULL; 1690b86b1bbSFabien Thomas LIST_FOREACH(h, &pmcstat_cgnode_hash[hash], pch_next) 1700b86b1bbSFabien Thomas { 1710b86b1bbSFabien Thomas if (h->pch_pmcid != pmcid) 1720b86b1bbSFabien Thomas continue; 1730b86b1bbSFabien Thomas 1740b86b1bbSFabien Thomas cg = h->pch_cgnode; 1750b86b1bbSFabien Thomas 1760b86b1bbSFabien Thomas assert(cg != NULL); 1770b86b1bbSFabien Thomas 1780b86b1bbSFabien Thomas if (cg->pcg_image == image && cg->pcg_func == pc) 1790b86b1bbSFabien Thomas return (cg); 1800b86b1bbSFabien Thomas } 1810b86b1bbSFabien Thomas 1820b86b1bbSFabien Thomas /* 1830b86b1bbSFabien Thomas * We haven't seen this (pmcid, pc) tuple yet, so allocate a 1840b86b1bbSFabien Thomas * new callgraph node and a new hash table entry for it. 1850b86b1bbSFabien Thomas */ 1860b86b1bbSFabien Thomas cg = pmcstat_cgnode_allocate(image, pc); 1870b86b1bbSFabien Thomas if ((h = malloc(sizeof(*h))) == NULL) 1880b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Could not allocate callgraph node"); 1890b86b1bbSFabien Thomas 1900b86b1bbSFabien Thomas h->pch_pmcid = pmcid; 1910b86b1bbSFabien Thomas h->pch_cgnode = cg; 1920b86b1bbSFabien Thomas LIST_INSERT_HEAD(&pmcstat_cgnode_hash[hash], h, pch_next); 1930b86b1bbSFabien Thomas 1940b86b1bbSFabien Thomas pmcstat_cgnode_hash_count++; 1950b86b1bbSFabien Thomas 1960b86b1bbSFabien Thomas return (cg); 1970b86b1bbSFabien Thomas } 1980b86b1bbSFabien Thomas 1990b86b1bbSFabien Thomas /* 2000b86b1bbSFabien Thomas * Compare two callgraph nodes for sorting. 2010b86b1bbSFabien Thomas */ 2020b86b1bbSFabien Thomas static int 2030b86b1bbSFabien Thomas pmcstat_cgnode_compare(const void *a, const void *b) 2040b86b1bbSFabien Thomas { 2050b86b1bbSFabien Thomas const struct pmcstat_cgnode *const *pcg1, *const *pcg2, *cg1, *cg2; 2060b86b1bbSFabien Thomas 2070b86b1bbSFabien Thomas pcg1 = (const struct pmcstat_cgnode *const *) a; 2080b86b1bbSFabien Thomas cg1 = *pcg1; 2090b86b1bbSFabien Thomas pcg2 = (const struct pmcstat_cgnode *const *) b; 2100b86b1bbSFabien Thomas cg2 = *pcg2; 2110b86b1bbSFabien Thomas 2120b86b1bbSFabien Thomas /* Sort in reverse order */ 2130b86b1bbSFabien Thomas if (cg1->pcg_count < cg2->pcg_count) 2140b86b1bbSFabien Thomas return (1); 2150b86b1bbSFabien Thomas if (cg1->pcg_count > cg2->pcg_count) 2160b86b1bbSFabien Thomas return (-1); 2170b86b1bbSFabien Thomas return (0); 2180b86b1bbSFabien Thomas } 2190b86b1bbSFabien Thomas 2200b86b1bbSFabien Thomas /* 2210b86b1bbSFabien Thomas * Find (allocating if a needed) a callgraph node in the given 2220b86b1bbSFabien Thomas * parent with the same (image, pcoffset) pair. 2230b86b1bbSFabien Thomas */ 2240b86b1bbSFabien Thomas 2250b86b1bbSFabien Thomas static struct pmcstat_cgnode * 2260b86b1bbSFabien Thomas pmcstat_cgnode_find(struct pmcstat_cgnode *parent, struct pmcstat_image *image, 2270b86b1bbSFabien Thomas uintfptr_t pcoffset) 2280b86b1bbSFabien Thomas { 2290b86b1bbSFabien Thomas struct pmcstat_cgnode *child; 2300b86b1bbSFabien Thomas 2310b86b1bbSFabien Thomas LIST_FOREACH(child, &parent->pcg_children, pcg_sibling) { 2320b86b1bbSFabien Thomas if (child->pcg_image == image && 2330b86b1bbSFabien Thomas child->pcg_func == pcoffset) 2340b86b1bbSFabien Thomas return (child); 2350b86b1bbSFabien Thomas } 2360b86b1bbSFabien Thomas 2370b86b1bbSFabien Thomas /* 2380b86b1bbSFabien Thomas * Allocate a new structure. 2390b86b1bbSFabien Thomas */ 2400b86b1bbSFabien Thomas 2410b86b1bbSFabien Thomas child = pmcstat_cgnode_allocate(image, pcoffset); 2420b86b1bbSFabien Thomas 2430b86b1bbSFabien Thomas /* 2440b86b1bbSFabien Thomas * Link it into the parent. 2450b86b1bbSFabien Thomas */ 2460b86b1bbSFabien Thomas LIST_INSERT_HEAD(&parent->pcg_children, child, pcg_sibling); 2470b86b1bbSFabien Thomas parent->pcg_nchildren++; 2480b86b1bbSFabien Thomas 2490b86b1bbSFabien Thomas return (child); 2500b86b1bbSFabien Thomas } 2510b86b1bbSFabien Thomas 2520b86b1bbSFabien Thomas /* 2530b86b1bbSFabien Thomas * Print one callgraph node. The output format is: 2540b86b1bbSFabien Thomas * 2550b86b1bbSFabien Thomas * indentation %(parent's samples) #nsamples function@object 2560b86b1bbSFabien Thomas */ 2570b86b1bbSFabien Thomas static void 2580b86b1bbSFabien Thomas pmcstat_cgnode_print(struct pmcstat_cgnode *cg, int depth, uint32_t total) 2590b86b1bbSFabien Thomas { 2600b86b1bbSFabien Thomas uint32_t n; 2610b86b1bbSFabien Thomas const char *space; 2620b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 2630b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 2640b86b1bbSFabien Thomas 2650b86b1bbSFabien Thomas space = " "; 2660b86b1bbSFabien Thomas 2670b86b1bbSFabien Thomas if (depth > 0) 2680b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", depth, space); 2690b86b1bbSFabien Thomas 2700b86b1bbSFabien Thomas if (cg->pcg_count == total) 2710b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "100.0%% "); 2720b86b1bbSFabien Thomas else 2730b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%05.2f%% ", 2740b86b1bbSFabien Thomas 100.0 * cg->pcg_count / total); 2750b86b1bbSFabien Thomas 2760b86b1bbSFabien Thomas n = fprintf(args.pa_graphfile, " [%u] ", cg->pcg_count); 2770b86b1bbSFabien Thomas 2780b86b1bbSFabien Thomas /* #samples is a 12 character wide field. */ 2790b86b1bbSFabien Thomas if (n < 12) 2800b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", 12 - n, space); 2810b86b1bbSFabien Thomas 2820b86b1bbSFabien Thomas if (depth > 0) 2830b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", depth, space); 2840b86b1bbSFabien Thomas 2850b86b1bbSFabien Thomas sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 2860b86b1bbSFabien Thomas if (sym) 2870b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%s", 2880b86b1bbSFabien Thomas pmcstat_string_unintern(sym->ps_name)); 2890b86b1bbSFabien Thomas else 2900b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%p", 2910b86b1bbSFabien Thomas (void *) (cg->pcg_image->pi_vaddr + cg->pcg_func)); 2920b86b1bbSFabien Thomas 2930b86b1bbSFabien Thomas if (pmcstat_previous_filename_printed != 2940b86b1bbSFabien Thomas cg->pcg_image->pi_fullpath) { 2950b86b1bbSFabien Thomas pmcstat_previous_filename_printed = cg->pcg_image->pi_fullpath; 2960b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, " @ %s\n", 2970b86b1bbSFabien Thomas pmcstat_string_unintern( 2980b86b1bbSFabien Thomas pmcstat_previous_filename_printed)); 2990b86b1bbSFabien Thomas } else 3000b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "\n"); 3010b86b1bbSFabien Thomas 3020b86b1bbSFabien Thomas if (cg->pcg_nchildren == 0) 3030b86b1bbSFabien Thomas return; 3040b86b1bbSFabien Thomas 3050b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 3060b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 3070b86b1bbSFabien Thomas cg->pcg_nchildren)) == NULL) 3080b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot print callgraph"); 3090b86b1bbSFabien Thomas cgn = sortbuffer; 3100b86b1bbSFabien Thomas 3110b86b1bbSFabien Thomas LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 3120b86b1bbSFabien Thomas *cgn++ = pcg; 3130b86b1bbSFabien Thomas 3140b86b1bbSFabien Thomas assert(cgn - sortbuffer == (int) cg->pcg_nchildren); 3150b86b1bbSFabien Thomas 3160b86b1bbSFabien Thomas qsort(sortbuffer, cg->pcg_nchildren, sizeof(struct pmcstat_cgnode *), 3170b86b1bbSFabien Thomas pmcstat_cgnode_compare); 3180b86b1bbSFabien Thomas 3190b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < cg->pcg_nchildren; n++, cgn++) 3200b86b1bbSFabien Thomas pmcstat_cgnode_print(*cgn, depth+1, cg->pcg_count); 3210b86b1bbSFabien Thomas 3220b86b1bbSFabien Thomas free(sortbuffer); 3230b86b1bbSFabien Thomas } 3240b86b1bbSFabien Thomas 3250b86b1bbSFabien Thomas /* 3260b86b1bbSFabien Thomas * Record a callchain. 3270b86b1bbSFabien Thomas */ 3280b86b1bbSFabien Thomas 3290b86b1bbSFabien Thomas void 3300b86b1bbSFabien Thomas pmcpl_cg_process(struct pmcstat_process *pp, struct pmcstat_pmcrecord *pmcr, 3310b86b1bbSFabien Thomas uint32_t nsamples, uintfptr_t *cc, int usermode, uint32_t cpu) 3320b86b1bbSFabien Thomas { 3330b86b1bbSFabien Thomas uintfptr_t pc, loadaddress; 3340b86b1bbSFabien Thomas uint32_t n; 3350b86b1bbSFabien Thomas struct pmcstat_image *image; 3360b86b1bbSFabien Thomas struct pmcstat_pcmap *ppm; 3370b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 3380b86b1bbSFabien Thomas struct pmcstat_cgnode *parent, *child; 3390b86b1bbSFabien Thomas struct pmcstat_process *km; 3400b86b1bbSFabien Thomas pmc_id_t pmcid; 3410b86b1bbSFabien Thomas 3420b86b1bbSFabien Thomas (void) cpu; 3430b86b1bbSFabien Thomas 3440b86b1bbSFabien Thomas /* 3450b86b1bbSFabien Thomas * Find the callgraph node recorded in the global hash table 3460b86b1bbSFabien Thomas * for this (pmcid, pc). 3470b86b1bbSFabien Thomas */ 3480b86b1bbSFabien Thomas 3490b86b1bbSFabien Thomas pc = cc[0]; 3500b86b1bbSFabien Thomas pmcid = pmcr->pr_pmcid; 3515de96e33SMatt Macy child = parent = pmcstat_cgnode_hash_lookup_pc(pp, pmcid, pc, usermode); 3520b86b1bbSFabien Thomas if (parent == NULL) { 3530b86b1bbSFabien Thomas pmcstat_stats.ps_callchain_dubious_frames++; 354c86819ecSFabien Thomas pmcr->pr_dubious_frames++; 3550b86b1bbSFabien Thomas return; 3560b86b1bbSFabien Thomas } 3570b86b1bbSFabien Thomas 3580b86b1bbSFabien Thomas parent->pcg_count++; 3590b86b1bbSFabien Thomas 3600b86b1bbSFabien Thomas /* 3610b86b1bbSFabien Thomas * For each return address in the call chain record, subject 3620b86b1bbSFabien Thomas * to the maximum depth desired. 3630b86b1bbSFabien Thomas * - Find the image associated with the sample. Stop if there 3640b86b1bbSFabien Thomas * there is no valid image at that address. 3650b86b1bbSFabien Thomas * - Find the function that overlaps the return address. 3660b86b1bbSFabien Thomas * - If found: use the start address of the function. 3670b86b1bbSFabien Thomas * If not found (say an object's symbol table is not present or 3680b86b1bbSFabien Thomas * is incomplete), round down to th gprof bucket granularity. 3690b86b1bbSFabien Thomas * - Convert return virtual address to an offset in the image. 3700b86b1bbSFabien Thomas * - Look for a child with the same {offset,image} tuple, 3710b86b1bbSFabien Thomas * inserting one if needed. 3720b86b1bbSFabien Thomas * - Increment the count of occurrences of the child. 3730b86b1bbSFabien Thomas */ 3740b86b1bbSFabien Thomas km = pmcstat_kernproc; 3750b86b1bbSFabien Thomas 3760b86b1bbSFabien Thomas for (n = 1; n < (uint32_t) args.pa_graphdepth && n < nsamples; n++, 3770b86b1bbSFabien Thomas parent = child) { 3780b86b1bbSFabien Thomas pc = cc[n]; 3790b86b1bbSFabien Thomas 3800b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(usermode ? pp : km, pc); 3810b86b1bbSFabien Thomas if (ppm == NULL) { 3820b86b1bbSFabien Thomas /* Detect full frame capture (kernel + user). */ 3830b86b1bbSFabien Thomas if (!usermode) { 3840b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(pp, pc); 3850b86b1bbSFabien Thomas if (ppm != NULL) 3860b86b1bbSFabien Thomas km = pp; 3870b86b1bbSFabien Thomas } 3880b86b1bbSFabien Thomas } 3890b86b1bbSFabien Thomas if (ppm == NULL) 3905de96e33SMatt Macy continue; 3910b86b1bbSFabien Thomas 3920b86b1bbSFabien Thomas image = ppm->ppm_image; 3930b86b1bbSFabien Thomas loadaddress = ppm->ppm_lowpc + image->pi_vaddr - 3940b86b1bbSFabien Thomas image->pi_start; 3950b86b1bbSFabien Thomas pc -= loadaddress; 3960b86b1bbSFabien Thomas 3970b86b1bbSFabien Thomas if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 3980b86b1bbSFabien Thomas pc = sym->ps_start; 3990b86b1bbSFabien Thomas 4000b86b1bbSFabien Thomas child = pmcstat_cgnode_find(parent, image, pc); 4010b86b1bbSFabien Thomas child->pcg_count++; 4020b86b1bbSFabien Thomas } 4030b86b1bbSFabien Thomas } 4040b86b1bbSFabien Thomas 4050b86b1bbSFabien Thomas /* 4060b86b1bbSFabien Thomas * Printing a callgraph for a PMC. 4070b86b1bbSFabien Thomas */ 4080b86b1bbSFabien Thomas static void 4090b86b1bbSFabien Thomas pmcstat_callgraph_print_for_pmcid(struct pmcstat_pmcrecord *pmcr) 4100b86b1bbSFabien Thomas { 4110b86b1bbSFabien Thomas int n, nentries; 4120b86b1bbSFabien Thomas uint32_t nsamples; 4130b86b1bbSFabien Thomas pmc_id_t pmcid; 4140b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn; 4150b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch; 4160b86b1bbSFabien Thomas 4170b86b1bbSFabien Thomas /* 4180b86b1bbSFabien Thomas * We pull out all callgraph nodes in the top-level hash table 4190b86b1bbSFabien Thomas * with a matching PMC id. We then sort these based on the 4200b86b1bbSFabien Thomas * frequency of occurrence. Each callgraph node is then 4210b86b1bbSFabien Thomas * printed. 4220b86b1bbSFabien Thomas */ 4230b86b1bbSFabien Thomas 4240b86b1bbSFabien Thomas nsamples = 0; 4250b86b1bbSFabien Thomas pmcid = pmcr->pr_pmcid; 4260b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 4270b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 4280b86b1bbSFabien Thomas pmcstat_cgnode_hash_count)) == NULL) 4290b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot sort callgraph"); 4300b86b1bbSFabien Thomas cgn = sortbuffer; 4310b86b1bbSFabien Thomas 4320b86b1bbSFabien Thomas for (n = 0; n < PMCSTAT_NHASH; n++) 4330b86b1bbSFabien Thomas LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 4340b86b1bbSFabien Thomas if (pch->pch_pmcid == pmcid) { 4350b86b1bbSFabien Thomas nsamples += pch->pch_cgnode->pcg_count; 4360b86b1bbSFabien Thomas *cgn++ = pch->pch_cgnode; 4370b86b1bbSFabien Thomas } 4380b86b1bbSFabien Thomas 4390b86b1bbSFabien Thomas nentries = cgn - sortbuffer; 4400b86b1bbSFabien Thomas assert(nentries <= pmcstat_cgnode_hash_count); 4410b86b1bbSFabien Thomas 4420b86b1bbSFabien Thomas if (nentries == 0) { 4430b86b1bbSFabien Thomas free(sortbuffer); 4440b86b1bbSFabien Thomas return; 4450b86b1bbSFabien Thomas } 4460b86b1bbSFabien Thomas 4470b86b1bbSFabien Thomas qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 4480b86b1bbSFabien Thomas pmcstat_cgnode_compare); 4490b86b1bbSFabien Thomas 4500b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, 4510b86b1bbSFabien Thomas "@ %s [%u samples]\n\n", 4520b86b1bbSFabien Thomas pmcstat_string_unintern(pmcr->pr_pmcname), 4530b86b1bbSFabien Thomas nsamples); 4540b86b1bbSFabien Thomas 4550b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 4560b86b1bbSFabien Thomas pmcstat_previous_filename_printed = NULL; 4570b86b1bbSFabien Thomas pmcstat_cgnode_print(*cgn, 0, nsamples); 4580b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "\n"); 4590b86b1bbSFabien Thomas } 4600b86b1bbSFabien Thomas 4610b86b1bbSFabien Thomas free(sortbuffer); 4620b86b1bbSFabien Thomas } 4630b86b1bbSFabien Thomas 4640b86b1bbSFabien Thomas /* 4650b86b1bbSFabien Thomas * Print out callgraphs. 4660b86b1bbSFabien Thomas */ 4670b86b1bbSFabien Thomas 4680b86b1bbSFabien Thomas static void 4690b86b1bbSFabien Thomas pmcstat_callgraph_print(void) 4700b86b1bbSFabien Thomas { 4710b86b1bbSFabien Thomas struct pmcstat_pmcrecord *pmcr; 4720b86b1bbSFabien Thomas 4730b86b1bbSFabien Thomas LIST_FOREACH(pmcr, &pmcstat_pmcs, pr_next) 4740b86b1bbSFabien Thomas pmcstat_callgraph_print_for_pmcid(pmcr); 4750b86b1bbSFabien Thomas } 4760b86b1bbSFabien Thomas 4770b86b1bbSFabien Thomas static void 4780b86b1bbSFabien Thomas pmcstat_cgnode_topprint(struct pmcstat_cgnode *cg, 479821a352aSMatt Macy int depth __unused, uint32_t nsamples) 4800b86b1bbSFabien Thomas { 4810b86b1bbSFabien Thomas int v_attrs, vs_len, ns_len, width, len, n, nchildren; 4820b86b1bbSFabien Thomas float v; 4830b86b1bbSFabien Thomas char ns[30], vs[10]; 4840b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 4850b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 4860b86b1bbSFabien Thomas 4870b86b1bbSFabien Thomas /* Format value. */ 4880b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(cg); 4890b86b1bbSFabien Thomas snprintf(vs, sizeof(vs), "%.1f", v); 4900b86b1bbSFabien Thomas v_attrs = PMCSTAT_ATTRPERCENT(v); 4910b86b1bbSFabien Thomas 4920b86b1bbSFabien Thomas /* Format name. */ 4930b86b1bbSFabien Thomas sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 49494e9ef85SMateusz Guzik if (sym == NULL) { 4950b86b1bbSFabien Thomas snprintf(ns, sizeof(ns), "%p", 4964bd2a4b5SMatt Macy (void *)(cg->pcg_image->pi_vaddr + cg->pcg_func)); 49794e9ef85SMateusz Guzik } else { 49894e9ef85SMateusz Guzik switch (args.pa_flags & (FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET)) { 49994e9ef85SMateusz Guzik case FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET: 50094e9ef85SMateusz Guzik case FLAG_SKIP_TOP_FN_RES: 50194e9ef85SMateusz Guzik snprintf(ns, sizeof(ns), "%p", 50294e9ef85SMateusz Guzik (void *)(cg->pcg_image->pi_vaddr + cg->pcg_func)); 50394e9ef85SMateusz Guzik break; 50494e9ef85SMateusz Guzik case FLAG_SHOW_OFFSET: 505*ec3b2a79SMateusz Guzik snprintf(ns, sizeof(ns), "%s+%#0" PRIx64, 50694e9ef85SMateusz Guzik pmcstat_string_unintern(sym->ps_name), 50794e9ef85SMateusz Guzik cg->pcg_func - sym->ps_start); 50894e9ef85SMateusz Guzik break; 50994e9ef85SMateusz Guzik default: 51094e9ef85SMateusz Guzik snprintf(ns, sizeof(ns), "%s", 51194e9ef85SMateusz Guzik pmcstat_string_unintern(sym->ps_name)); 51294e9ef85SMateusz Guzik break; 51394e9ef85SMateusz Guzik } 51494e9ef85SMateusz Guzik } 5150b86b1bbSFabien Thomas 5160b86b1bbSFabien Thomas PMCSTAT_ATTRON(v_attrs); 5170b86b1bbSFabien Thomas PMCSTAT_PRINTW("%5.5s", vs); 5180b86b1bbSFabien Thomas PMCSTAT_ATTROFF(v_attrs); 51994e9ef85SMateusz Guzik PMCSTAT_PRINTW(" %-10.10s %-30.30s", 5200b86b1bbSFabien Thomas pmcstat_string_unintern(cg->pcg_image->pi_name), 5210b86b1bbSFabien Thomas ns); 5220b86b1bbSFabien Thomas 5230b86b1bbSFabien Thomas nchildren = cg->pcg_nchildren; 5240b86b1bbSFabien Thomas if (nchildren == 0) { 5250b86b1bbSFabien Thomas PMCSTAT_PRINTW("\n"); 5260b86b1bbSFabien Thomas return; 5270b86b1bbSFabien Thomas } 5280b86b1bbSFabien Thomas 5290b86b1bbSFabien Thomas width = pmcstat_displaywidth - 40; 5300b86b1bbSFabien Thomas 5310b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 5320b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 5330b86b1bbSFabien Thomas nchildren)) == NULL) 5340b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot print callgraph"); 5350b86b1bbSFabien Thomas cgn = sortbuffer; 5360b86b1bbSFabien Thomas 5370b86b1bbSFabien Thomas LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 5380b86b1bbSFabien Thomas *cgn++ = pcg; 5390b86b1bbSFabien Thomas 5400b86b1bbSFabien Thomas assert(cgn - sortbuffer == (int)nchildren); 5410b86b1bbSFabien Thomas 5420b86b1bbSFabien Thomas qsort(sortbuffer, nchildren, sizeof(struct pmcstat_cgnode *), 5430b86b1bbSFabien Thomas pmcstat_cgnode_compare); 5440b86b1bbSFabien Thomas 5450b86b1bbSFabien Thomas /* Count how many callers. */ 5460b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 5470b86b1bbSFabien Thomas pcg = *cgn; 5480b86b1bbSFabien Thomas 5490b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(pcg); 5500b86b1bbSFabien Thomas if (v < pmcstat_threshold) 5510b86b1bbSFabien Thomas break; 5520b86b1bbSFabien Thomas } 5530b86b1bbSFabien Thomas nchildren = n; 5540b86b1bbSFabien Thomas 5550b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 5560b86b1bbSFabien Thomas pcg = *cgn; 5570b86b1bbSFabien Thomas 5580b86b1bbSFabien Thomas /* Format value. */ 5590b86b1bbSFabien Thomas if (nchildren > 1) { 5600b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(pcg); 5610b86b1bbSFabien Thomas vs_len = snprintf(vs, sizeof(vs), ":%.1f", v); 5620b86b1bbSFabien Thomas v_attrs = PMCSTAT_ATTRPERCENT(v); 5630b86b1bbSFabien Thomas } else 5640b86b1bbSFabien Thomas vs_len = 0; 5650b86b1bbSFabien Thomas 5660b86b1bbSFabien Thomas /* Format name. */ 5670b86b1bbSFabien Thomas sym = pmcstat_symbol_search(pcg->pcg_image, pcg->pcg_func); 5680b86b1bbSFabien Thomas if (sym != NULL) { 5690b86b1bbSFabien Thomas ns_len = snprintf(ns, sizeof(ns), "%s", 5700b86b1bbSFabien Thomas pmcstat_string_unintern(sym->ps_name)); 5710b86b1bbSFabien Thomas } else 5720b86b1bbSFabien Thomas ns_len = snprintf(ns, sizeof(ns), "%p", 5730b86b1bbSFabien Thomas (void *)pcg->pcg_func); 5740b86b1bbSFabien Thomas 5750b86b1bbSFabien Thomas len = ns_len + vs_len + 1; 5760b86b1bbSFabien Thomas if (width - len < 0) { 5770b86b1bbSFabien Thomas PMCSTAT_PRINTW(" ..."); 5780b86b1bbSFabien Thomas break; 5790b86b1bbSFabien Thomas } 5800b86b1bbSFabien Thomas width -= len; 5810b86b1bbSFabien Thomas 5820b86b1bbSFabien Thomas PMCSTAT_PRINTW(" %s", ns); 5830b86b1bbSFabien Thomas if (nchildren > 1) { 5840b86b1bbSFabien Thomas PMCSTAT_ATTRON(v_attrs); 5850b86b1bbSFabien Thomas PMCSTAT_PRINTW("%s", vs); 5860b86b1bbSFabien Thomas PMCSTAT_ATTROFF(v_attrs); 5870b86b1bbSFabien Thomas } 5880b86b1bbSFabien Thomas } 5890b86b1bbSFabien Thomas PMCSTAT_PRINTW("\n"); 5900b86b1bbSFabien Thomas free(sortbuffer); 5910b86b1bbSFabien Thomas } 5920b86b1bbSFabien Thomas 5930b86b1bbSFabien Thomas /* 5940b86b1bbSFabien Thomas * Top mode display. 5950b86b1bbSFabien Thomas */ 5960b86b1bbSFabien Thomas 5970b86b1bbSFabien Thomas void 5980b86b1bbSFabien Thomas pmcpl_cg_topdisplay(void) 5990b86b1bbSFabien Thomas { 6000b86b1bbSFabien Thomas int n, nentries; 6010b86b1bbSFabien Thomas uint32_t nsamples; 6020b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn; 6030b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch; 6040b86b1bbSFabien Thomas struct pmcstat_pmcrecord *pmcr; 6050b86b1bbSFabien Thomas 6060b86b1bbSFabien Thomas pmcr = pmcstat_pmcindex_to_pmcr(pmcstat_pmcinfilter); 607410c7662SFabien Thomas if (!pmcr) 608410c7662SFabien Thomas err(EX_SOFTWARE, "ERROR: invalid pmcindex"); 6090b86b1bbSFabien Thomas 6100b86b1bbSFabien Thomas /* 6110b86b1bbSFabien Thomas * We pull out all callgraph nodes in the top-level hash table 6120b86b1bbSFabien Thomas * with a matching PMC index. We then sort these based on the 6130b86b1bbSFabien Thomas * frequency of occurrence. Each callgraph node is then 6140b86b1bbSFabien Thomas * printed. 6150b86b1bbSFabien Thomas */ 6160b86b1bbSFabien Thomas 6170b86b1bbSFabien Thomas nsamples = 0; 6180b86b1bbSFabien Thomas 6190b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 6200b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 6210b86b1bbSFabien Thomas pmcstat_cgnode_hash_count)) == NULL) 6220b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot sort callgraph"); 6230b86b1bbSFabien Thomas cgn = sortbuffer; 6240b86b1bbSFabien Thomas 6250b86b1bbSFabien Thomas for (n = 0; n < PMCSTAT_NHASH; n++) 6260b86b1bbSFabien Thomas LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 6270b86b1bbSFabien Thomas if (pmcr == NULL || pch->pch_pmcid == pmcr->pr_pmcid) { 6280b86b1bbSFabien Thomas nsamples += pch->pch_cgnode->pcg_count; 6290b86b1bbSFabien Thomas *cgn++ = pch->pch_cgnode; 6300b86b1bbSFabien Thomas } 6310b86b1bbSFabien Thomas 6320b86b1bbSFabien Thomas nentries = cgn - sortbuffer; 6330b86b1bbSFabien Thomas assert(nentries <= pmcstat_cgnode_hash_count); 6340b86b1bbSFabien Thomas 6350b86b1bbSFabien Thomas if (nentries == 0) { 6360b86b1bbSFabien Thomas free(sortbuffer); 6370b86b1bbSFabien Thomas return; 6380b86b1bbSFabien Thomas } 6390b86b1bbSFabien Thomas 6400b86b1bbSFabien Thomas qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 6410b86b1bbSFabien Thomas pmcstat_cgnode_compare); 6420b86b1bbSFabien Thomas 64394e9ef85SMateusz Guzik PMCSTAT_PRINTW("%5.5s %-10.10s %-30.30s %s\n", 6440b86b1bbSFabien Thomas "%SAMP", "IMAGE", "FUNCTION", "CALLERS"); 6450b86b1bbSFabien Thomas 6460b86b1bbSFabien Thomas nentries = min(pmcstat_displayheight - 2, nentries); 6470b86b1bbSFabien Thomas 6480b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 6490b86b1bbSFabien Thomas if (PMCPL_CG_COUNTP(*cgn) < pmcstat_threshold) 6500b86b1bbSFabien Thomas break; 6510b86b1bbSFabien Thomas pmcstat_cgnode_topprint(*cgn, 0, nsamples); 6520b86b1bbSFabien Thomas } 6530b86b1bbSFabien Thomas 6540b86b1bbSFabien Thomas free(sortbuffer); 6550b86b1bbSFabien Thomas } 6560b86b1bbSFabien Thomas 6570b86b1bbSFabien Thomas /* 6580b86b1bbSFabien Thomas * Handle top mode keypress. 6590b86b1bbSFabien Thomas */ 6600b86b1bbSFabien Thomas 6610b86b1bbSFabien Thomas int 662d27927f7SRuslan Bukin pmcpl_cg_topkeypress(int c, void *arg) 6630b86b1bbSFabien Thomas { 664d27927f7SRuslan Bukin WINDOW *w; 665d27927f7SRuslan Bukin 666d27927f7SRuslan Bukin w = (WINDOW *)arg; 6670b86b1bbSFabien Thomas 6680b86b1bbSFabien Thomas (void) c; (void) w; 6690b86b1bbSFabien Thomas 6700b86b1bbSFabien Thomas return 0; 6710b86b1bbSFabien Thomas } 6720b86b1bbSFabien Thomas 6730b86b1bbSFabien Thomas int 6740b86b1bbSFabien Thomas pmcpl_cg_init(void) 6750b86b1bbSFabien Thomas { 6760b86b1bbSFabien Thomas int i; 6770b86b1bbSFabien Thomas 6780b86b1bbSFabien Thomas pmcstat_cgnode_hash_count = 0; 6790b86b1bbSFabien Thomas pmcstat_previous_filename_printed = NULL; 6800b86b1bbSFabien Thomas 6810b86b1bbSFabien Thomas for (i = 0; i < PMCSTAT_NHASH; i++) { 6820b86b1bbSFabien Thomas LIST_INIT(&pmcstat_cgnode_hash[i]); 6830b86b1bbSFabien Thomas } 6840b86b1bbSFabien Thomas 6850b86b1bbSFabien Thomas return (0); 6860b86b1bbSFabien Thomas } 6870b86b1bbSFabien Thomas 6880b86b1bbSFabien Thomas void 6890b86b1bbSFabien Thomas pmcpl_cg_shutdown(FILE *mf) 6900b86b1bbSFabien Thomas { 6910b86b1bbSFabien Thomas int i; 6920b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch, *pchtmp; 6930b86b1bbSFabien Thomas 6940b86b1bbSFabien Thomas (void) mf; 6950b86b1bbSFabien Thomas 6960b86b1bbSFabien Thomas if (args.pa_flags & FLAG_DO_CALLGRAPHS) 6970b86b1bbSFabien Thomas pmcstat_callgraph_print(); 6980b86b1bbSFabien Thomas 6990b86b1bbSFabien Thomas /* 7000b86b1bbSFabien Thomas * Free memory. 7010b86b1bbSFabien Thomas */ 7020b86b1bbSFabien Thomas for (i = 0; i < PMCSTAT_NHASH; i++) { 7030b86b1bbSFabien Thomas LIST_FOREACH_SAFE(pch, &pmcstat_cgnode_hash[i], pch_next, 7040b86b1bbSFabien Thomas pchtmp) { 7050b86b1bbSFabien Thomas pmcstat_cgnode_free(pch->pch_cgnode); 7060b86b1bbSFabien Thomas LIST_REMOVE(pch, pch_next); 7070b86b1bbSFabien Thomas free(pch); 7080b86b1bbSFabien Thomas } 7090b86b1bbSFabien Thomas } 7100b86b1bbSFabien Thomas } 7110b86b1bbSFabien Thomas 712