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> 610b86b1bbSFabien Thomas #include <libgen.h> 620b86b1bbSFabien Thomas #include <limits.h> 630b86b1bbSFabien Thomas #include <netdb.h> 640b86b1bbSFabien Thomas #include <pmc.h> 650b86b1bbSFabien Thomas #include <pmclog.h> 660b86b1bbSFabien Thomas #include <sysexits.h> 670b86b1bbSFabien Thomas #include <stdint.h> 680b86b1bbSFabien Thomas #include <stdio.h> 690b86b1bbSFabien Thomas #include <stdlib.h> 700b86b1bbSFabien Thomas #include <string.h> 710b86b1bbSFabien Thomas #include <unistd.h> 720b86b1bbSFabien Thomas 730b86b1bbSFabien Thomas #include "pmcstat.h" 740b86b1bbSFabien Thomas #include "pmcstat_log.h" 750b86b1bbSFabien Thomas #include "pmcstat_top.h" 760b86b1bbSFabien Thomas #include "pmcpl_callgraph.h" 770b86b1bbSFabien Thomas 78d27927f7SRuslan Bukin #define min(A,B) ((A) < (B) ? (A) : (B)) 79d27927f7SRuslan Bukin #define max(A,B) ((A) > (B) ? (A) : (B)) 80d27927f7SRuslan Bukin 810b86b1bbSFabien Thomas /* Get the sample value in percent related to nsamples. */ 820b86b1bbSFabien Thomas #define PMCPL_CG_COUNTP(a) \ 830b86b1bbSFabien Thomas ((a)->pcg_count * 100.0 / nsamples) 840b86b1bbSFabien Thomas 850b86b1bbSFabien Thomas /* 860b86b1bbSFabien Thomas * The toplevel CG nodes (i.e., with rank == 0) are placed in a hash table. 870b86b1bbSFabien Thomas */ 880b86b1bbSFabien Thomas 890b86b1bbSFabien Thomas struct pmcstat_cgnode_hash_list pmcstat_cgnode_hash[PMCSTAT_NHASH]; 900b86b1bbSFabien Thomas int pmcstat_cgnode_hash_count; 910b86b1bbSFabien Thomas 920b86b1bbSFabien Thomas static pmcstat_interned_string pmcstat_previous_filename_printed; 930b86b1bbSFabien Thomas 940b86b1bbSFabien Thomas static struct pmcstat_cgnode * 950b86b1bbSFabien Thomas pmcstat_cgnode_allocate(struct pmcstat_image *image, uintfptr_t pc) 960b86b1bbSFabien Thomas { 970b86b1bbSFabien Thomas struct pmcstat_cgnode *cg; 980b86b1bbSFabien Thomas 990b86b1bbSFabien Thomas if ((cg = malloc(sizeof(*cg))) == NULL) 1000b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot allocate callgraph node"); 1010b86b1bbSFabien Thomas 1020b86b1bbSFabien Thomas cg->pcg_image = image; 1030b86b1bbSFabien Thomas cg->pcg_func = pc; 1040b86b1bbSFabien Thomas 1050b86b1bbSFabien Thomas cg->pcg_count = 0; 1060b86b1bbSFabien Thomas cg->pcg_nchildren = 0; 1070b86b1bbSFabien Thomas LIST_INIT(&cg->pcg_children); 1080b86b1bbSFabien Thomas 1090b86b1bbSFabien Thomas return (cg); 1100b86b1bbSFabien Thomas } 1110b86b1bbSFabien Thomas 1120b86b1bbSFabien Thomas /* 1130b86b1bbSFabien Thomas * Free a node and its children. 1140b86b1bbSFabien Thomas */ 1150b86b1bbSFabien Thomas static void 1160b86b1bbSFabien Thomas pmcstat_cgnode_free(struct pmcstat_cgnode *cg) 1170b86b1bbSFabien Thomas { 1180b86b1bbSFabien Thomas struct pmcstat_cgnode *cgc, *cgtmp; 1190b86b1bbSFabien Thomas 1200b86b1bbSFabien Thomas LIST_FOREACH_SAFE(cgc, &cg->pcg_children, pcg_sibling, cgtmp) 1210b86b1bbSFabien Thomas pmcstat_cgnode_free(cgc); 1220b86b1bbSFabien Thomas free(cg); 1230b86b1bbSFabien Thomas } 1240b86b1bbSFabien Thomas 1250b86b1bbSFabien Thomas /* 1260b86b1bbSFabien Thomas * Look for a callgraph node associated with pmc `pmcid' in the global 1270b86b1bbSFabien Thomas * hash table that corresponds to the given `pc' value in the process 1280b86b1bbSFabien Thomas * `pp'. 1290b86b1bbSFabien Thomas */ 1300b86b1bbSFabien Thomas static struct pmcstat_cgnode * 1310b86b1bbSFabien Thomas pmcstat_cgnode_hash_lookup_pc(struct pmcstat_process *pp, pmc_id_t pmcid, 1320b86b1bbSFabien Thomas uintfptr_t pc, int usermode) 1330b86b1bbSFabien Thomas { 1340b86b1bbSFabien Thomas struct pmcstat_pcmap *ppm; 1350b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 1360b86b1bbSFabien Thomas struct pmcstat_image *image; 1370b86b1bbSFabien Thomas struct pmcstat_cgnode *cg; 1380b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *h; 1390b86b1bbSFabien Thomas uintfptr_t loadaddress; 1400b86b1bbSFabien Thomas unsigned int i, hash; 1410b86b1bbSFabien Thomas 1420b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(usermode ? pp : pmcstat_kernproc, pc); 1430b86b1bbSFabien Thomas if (ppm == NULL) 1440b86b1bbSFabien Thomas return (NULL); 1450b86b1bbSFabien Thomas 1460b86b1bbSFabien Thomas image = ppm->ppm_image; 1470b86b1bbSFabien Thomas 1480b86b1bbSFabien Thomas loadaddress = ppm->ppm_lowpc + image->pi_vaddr - image->pi_start; 1490b86b1bbSFabien Thomas pc -= loadaddress; /* Convert to an offset in the image. */ 1500b86b1bbSFabien Thomas 1510b86b1bbSFabien Thomas /* 1520b86b1bbSFabien Thomas * Try determine the function at this offset. If we can't 1530b86b1bbSFabien Thomas * find a function round leave the `pc' value alone. 1540b86b1bbSFabien Thomas */ 155*94e9ef85SMateusz Guzik if (!(args.pa_flags & (FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET))) { 1560b86b1bbSFabien Thomas if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 1570b86b1bbSFabien Thomas pc = sym->ps_start; 158eb707d60SFabien Thomas else 159eb707d60SFabien Thomas pmcstat_stats.ps_samples_unknown_function++; 160*94e9ef85SMateusz Guzik } 1610b86b1bbSFabien Thomas 1620b86b1bbSFabien Thomas for (hash = i = 0; i < sizeof(uintfptr_t); i++) 1630b86b1bbSFabien Thomas hash += (pc >> i) & 0xFF; 1640b86b1bbSFabien Thomas 1650b86b1bbSFabien Thomas hash &= PMCSTAT_HASH_MASK; 1660b86b1bbSFabien Thomas 1670b86b1bbSFabien Thomas cg = NULL; 1680b86b1bbSFabien Thomas LIST_FOREACH(h, &pmcstat_cgnode_hash[hash], pch_next) 1690b86b1bbSFabien Thomas { 1700b86b1bbSFabien Thomas if (h->pch_pmcid != pmcid) 1710b86b1bbSFabien Thomas continue; 1720b86b1bbSFabien Thomas 1730b86b1bbSFabien Thomas cg = h->pch_cgnode; 1740b86b1bbSFabien Thomas 1750b86b1bbSFabien Thomas assert(cg != NULL); 1760b86b1bbSFabien Thomas 1770b86b1bbSFabien Thomas if (cg->pcg_image == image && cg->pcg_func == pc) 1780b86b1bbSFabien Thomas return (cg); 1790b86b1bbSFabien Thomas } 1800b86b1bbSFabien Thomas 1810b86b1bbSFabien Thomas /* 1820b86b1bbSFabien Thomas * We haven't seen this (pmcid, pc) tuple yet, so allocate a 1830b86b1bbSFabien Thomas * new callgraph node and a new hash table entry for it. 1840b86b1bbSFabien Thomas */ 1850b86b1bbSFabien Thomas cg = pmcstat_cgnode_allocate(image, pc); 1860b86b1bbSFabien Thomas if ((h = malloc(sizeof(*h))) == NULL) 1870b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Could not allocate callgraph node"); 1880b86b1bbSFabien Thomas 1890b86b1bbSFabien Thomas h->pch_pmcid = pmcid; 1900b86b1bbSFabien Thomas h->pch_cgnode = cg; 1910b86b1bbSFabien Thomas LIST_INSERT_HEAD(&pmcstat_cgnode_hash[hash], h, pch_next); 1920b86b1bbSFabien Thomas 1930b86b1bbSFabien Thomas pmcstat_cgnode_hash_count++; 1940b86b1bbSFabien Thomas 1950b86b1bbSFabien Thomas return (cg); 1960b86b1bbSFabien Thomas } 1970b86b1bbSFabien Thomas 1980b86b1bbSFabien Thomas /* 1990b86b1bbSFabien Thomas * Compare two callgraph nodes for sorting. 2000b86b1bbSFabien Thomas */ 2010b86b1bbSFabien Thomas static int 2020b86b1bbSFabien Thomas pmcstat_cgnode_compare(const void *a, const void *b) 2030b86b1bbSFabien Thomas { 2040b86b1bbSFabien Thomas const struct pmcstat_cgnode *const *pcg1, *const *pcg2, *cg1, *cg2; 2050b86b1bbSFabien Thomas 2060b86b1bbSFabien Thomas pcg1 = (const struct pmcstat_cgnode *const *) a; 2070b86b1bbSFabien Thomas cg1 = *pcg1; 2080b86b1bbSFabien Thomas pcg2 = (const struct pmcstat_cgnode *const *) b; 2090b86b1bbSFabien Thomas cg2 = *pcg2; 2100b86b1bbSFabien Thomas 2110b86b1bbSFabien Thomas /* Sort in reverse order */ 2120b86b1bbSFabien Thomas if (cg1->pcg_count < cg2->pcg_count) 2130b86b1bbSFabien Thomas return (1); 2140b86b1bbSFabien Thomas if (cg1->pcg_count > cg2->pcg_count) 2150b86b1bbSFabien Thomas return (-1); 2160b86b1bbSFabien Thomas return (0); 2170b86b1bbSFabien Thomas } 2180b86b1bbSFabien Thomas 2190b86b1bbSFabien Thomas /* 2200b86b1bbSFabien Thomas * Find (allocating if a needed) a callgraph node in the given 2210b86b1bbSFabien Thomas * parent with the same (image, pcoffset) pair. 2220b86b1bbSFabien Thomas */ 2230b86b1bbSFabien Thomas 2240b86b1bbSFabien Thomas static struct pmcstat_cgnode * 2250b86b1bbSFabien Thomas pmcstat_cgnode_find(struct pmcstat_cgnode *parent, struct pmcstat_image *image, 2260b86b1bbSFabien Thomas uintfptr_t pcoffset) 2270b86b1bbSFabien Thomas { 2280b86b1bbSFabien Thomas struct pmcstat_cgnode *child; 2290b86b1bbSFabien Thomas 2300b86b1bbSFabien Thomas LIST_FOREACH(child, &parent->pcg_children, pcg_sibling) { 2310b86b1bbSFabien Thomas if (child->pcg_image == image && 2320b86b1bbSFabien Thomas child->pcg_func == pcoffset) 2330b86b1bbSFabien Thomas return (child); 2340b86b1bbSFabien Thomas } 2350b86b1bbSFabien Thomas 2360b86b1bbSFabien Thomas /* 2370b86b1bbSFabien Thomas * Allocate a new structure. 2380b86b1bbSFabien Thomas */ 2390b86b1bbSFabien Thomas 2400b86b1bbSFabien Thomas child = pmcstat_cgnode_allocate(image, pcoffset); 2410b86b1bbSFabien Thomas 2420b86b1bbSFabien Thomas /* 2430b86b1bbSFabien Thomas * Link it into the parent. 2440b86b1bbSFabien Thomas */ 2450b86b1bbSFabien Thomas LIST_INSERT_HEAD(&parent->pcg_children, child, pcg_sibling); 2460b86b1bbSFabien Thomas parent->pcg_nchildren++; 2470b86b1bbSFabien Thomas 2480b86b1bbSFabien Thomas return (child); 2490b86b1bbSFabien Thomas } 2500b86b1bbSFabien Thomas 2510b86b1bbSFabien Thomas /* 2520b86b1bbSFabien Thomas * Print one callgraph node. The output format is: 2530b86b1bbSFabien Thomas * 2540b86b1bbSFabien Thomas * indentation %(parent's samples) #nsamples function@object 2550b86b1bbSFabien Thomas */ 2560b86b1bbSFabien Thomas static void 2570b86b1bbSFabien Thomas pmcstat_cgnode_print(struct pmcstat_cgnode *cg, int depth, uint32_t total) 2580b86b1bbSFabien Thomas { 2590b86b1bbSFabien Thomas uint32_t n; 2600b86b1bbSFabien Thomas const char *space; 2610b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 2620b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 2630b86b1bbSFabien Thomas 2640b86b1bbSFabien Thomas space = " "; 2650b86b1bbSFabien Thomas 2660b86b1bbSFabien Thomas if (depth > 0) 2670b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", depth, space); 2680b86b1bbSFabien Thomas 2690b86b1bbSFabien Thomas if (cg->pcg_count == total) 2700b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "100.0%% "); 2710b86b1bbSFabien Thomas else 2720b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%05.2f%% ", 2730b86b1bbSFabien Thomas 100.0 * cg->pcg_count / total); 2740b86b1bbSFabien Thomas 2750b86b1bbSFabien Thomas n = fprintf(args.pa_graphfile, " [%u] ", cg->pcg_count); 2760b86b1bbSFabien Thomas 2770b86b1bbSFabien Thomas /* #samples is a 12 character wide field. */ 2780b86b1bbSFabien Thomas if (n < 12) 2790b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", 12 - n, space); 2800b86b1bbSFabien Thomas 2810b86b1bbSFabien Thomas if (depth > 0) 2820b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%*s", depth, space); 2830b86b1bbSFabien Thomas 2840b86b1bbSFabien Thomas sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 2850b86b1bbSFabien Thomas if (sym) 2860b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%s", 2870b86b1bbSFabien Thomas pmcstat_string_unintern(sym->ps_name)); 2880b86b1bbSFabien Thomas else 2890b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "%p", 2900b86b1bbSFabien Thomas (void *) (cg->pcg_image->pi_vaddr + cg->pcg_func)); 2910b86b1bbSFabien Thomas 2920b86b1bbSFabien Thomas if (pmcstat_previous_filename_printed != 2930b86b1bbSFabien Thomas cg->pcg_image->pi_fullpath) { 2940b86b1bbSFabien Thomas pmcstat_previous_filename_printed = cg->pcg_image->pi_fullpath; 2950b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, " @ %s\n", 2960b86b1bbSFabien Thomas pmcstat_string_unintern( 2970b86b1bbSFabien Thomas pmcstat_previous_filename_printed)); 2980b86b1bbSFabien Thomas } else 2990b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "\n"); 3000b86b1bbSFabien Thomas 3010b86b1bbSFabien Thomas if (cg->pcg_nchildren == 0) 3020b86b1bbSFabien Thomas return; 3030b86b1bbSFabien Thomas 3040b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 3050b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 3060b86b1bbSFabien Thomas cg->pcg_nchildren)) == NULL) 3070b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot print callgraph"); 3080b86b1bbSFabien Thomas cgn = sortbuffer; 3090b86b1bbSFabien Thomas 3100b86b1bbSFabien Thomas LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 3110b86b1bbSFabien Thomas *cgn++ = pcg; 3120b86b1bbSFabien Thomas 3130b86b1bbSFabien Thomas assert(cgn - sortbuffer == (int) cg->pcg_nchildren); 3140b86b1bbSFabien Thomas 3150b86b1bbSFabien Thomas qsort(sortbuffer, cg->pcg_nchildren, sizeof(struct pmcstat_cgnode *), 3160b86b1bbSFabien Thomas pmcstat_cgnode_compare); 3170b86b1bbSFabien Thomas 3180b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < cg->pcg_nchildren; n++, cgn++) 3190b86b1bbSFabien Thomas pmcstat_cgnode_print(*cgn, depth+1, cg->pcg_count); 3200b86b1bbSFabien Thomas 3210b86b1bbSFabien Thomas free(sortbuffer); 3220b86b1bbSFabien Thomas } 3230b86b1bbSFabien Thomas 3240b86b1bbSFabien Thomas /* 3250b86b1bbSFabien Thomas * Record a callchain. 3260b86b1bbSFabien Thomas */ 3270b86b1bbSFabien Thomas 3280b86b1bbSFabien Thomas void 3290b86b1bbSFabien Thomas pmcpl_cg_process(struct pmcstat_process *pp, struct pmcstat_pmcrecord *pmcr, 3300b86b1bbSFabien Thomas uint32_t nsamples, uintfptr_t *cc, int usermode, uint32_t cpu) 3310b86b1bbSFabien Thomas { 3320b86b1bbSFabien Thomas uintfptr_t pc, loadaddress; 3330b86b1bbSFabien Thomas uint32_t n; 3340b86b1bbSFabien Thomas struct pmcstat_image *image; 3350b86b1bbSFabien Thomas struct pmcstat_pcmap *ppm; 3360b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 3370b86b1bbSFabien Thomas struct pmcstat_cgnode *parent, *child; 3380b86b1bbSFabien Thomas struct pmcstat_process *km; 3390b86b1bbSFabien Thomas pmc_id_t pmcid; 3400b86b1bbSFabien Thomas 3410b86b1bbSFabien Thomas (void) cpu; 3420b86b1bbSFabien Thomas 3430b86b1bbSFabien Thomas /* 3440b86b1bbSFabien Thomas * Find the callgraph node recorded in the global hash table 3450b86b1bbSFabien Thomas * for this (pmcid, pc). 3460b86b1bbSFabien Thomas */ 3470b86b1bbSFabien Thomas 3480b86b1bbSFabien Thomas pc = cc[0]; 3490b86b1bbSFabien Thomas pmcid = pmcr->pr_pmcid; 3505de96e33SMatt Macy child = parent = pmcstat_cgnode_hash_lookup_pc(pp, pmcid, pc, usermode); 3510b86b1bbSFabien Thomas if (parent == NULL) { 3520b86b1bbSFabien Thomas pmcstat_stats.ps_callchain_dubious_frames++; 353c86819ecSFabien Thomas pmcr->pr_dubious_frames++; 3540b86b1bbSFabien Thomas return; 3550b86b1bbSFabien Thomas } 3560b86b1bbSFabien Thomas 3570b86b1bbSFabien Thomas parent->pcg_count++; 3580b86b1bbSFabien Thomas 3590b86b1bbSFabien Thomas /* 3600b86b1bbSFabien Thomas * For each return address in the call chain record, subject 3610b86b1bbSFabien Thomas * to the maximum depth desired. 3620b86b1bbSFabien Thomas * - Find the image associated with the sample. Stop if there 3630b86b1bbSFabien Thomas * there is no valid image at that address. 3640b86b1bbSFabien Thomas * - Find the function that overlaps the return address. 3650b86b1bbSFabien Thomas * - If found: use the start address of the function. 3660b86b1bbSFabien Thomas * If not found (say an object's symbol table is not present or 3670b86b1bbSFabien Thomas * is incomplete), round down to th gprof bucket granularity. 3680b86b1bbSFabien Thomas * - Convert return virtual address to an offset in the image. 3690b86b1bbSFabien Thomas * - Look for a child with the same {offset,image} tuple, 3700b86b1bbSFabien Thomas * inserting one if needed. 3710b86b1bbSFabien Thomas * - Increment the count of occurrences of the child. 3720b86b1bbSFabien Thomas */ 3730b86b1bbSFabien Thomas km = pmcstat_kernproc; 3740b86b1bbSFabien Thomas 3750b86b1bbSFabien Thomas for (n = 1; n < (uint32_t) args.pa_graphdepth && n < nsamples; n++, 3760b86b1bbSFabien Thomas parent = child) { 3770b86b1bbSFabien Thomas pc = cc[n]; 3780b86b1bbSFabien Thomas 3790b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(usermode ? pp : km, pc); 3800b86b1bbSFabien Thomas if (ppm == NULL) { 3810b86b1bbSFabien Thomas /* Detect full frame capture (kernel + user). */ 3820b86b1bbSFabien Thomas if (!usermode) { 3830b86b1bbSFabien Thomas ppm = pmcstat_process_find_map(pp, pc); 3840b86b1bbSFabien Thomas if (ppm != NULL) 3850b86b1bbSFabien Thomas km = pp; 3860b86b1bbSFabien Thomas } 3870b86b1bbSFabien Thomas } 3880b86b1bbSFabien Thomas if (ppm == NULL) 3895de96e33SMatt Macy continue; 3900b86b1bbSFabien Thomas 3910b86b1bbSFabien Thomas image = ppm->ppm_image; 3920b86b1bbSFabien Thomas loadaddress = ppm->ppm_lowpc + image->pi_vaddr - 3930b86b1bbSFabien Thomas image->pi_start; 3940b86b1bbSFabien Thomas pc -= loadaddress; 3950b86b1bbSFabien Thomas 3960b86b1bbSFabien Thomas if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 3970b86b1bbSFabien Thomas pc = sym->ps_start; 3980b86b1bbSFabien Thomas 3990b86b1bbSFabien Thomas child = pmcstat_cgnode_find(parent, image, pc); 4000b86b1bbSFabien Thomas child->pcg_count++; 4010b86b1bbSFabien Thomas } 4020b86b1bbSFabien Thomas } 4030b86b1bbSFabien Thomas 4040b86b1bbSFabien Thomas /* 4050b86b1bbSFabien Thomas * Printing a callgraph for a PMC. 4060b86b1bbSFabien Thomas */ 4070b86b1bbSFabien Thomas static void 4080b86b1bbSFabien Thomas pmcstat_callgraph_print_for_pmcid(struct pmcstat_pmcrecord *pmcr) 4090b86b1bbSFabien Thomas { 4100b86b1bbSFabien Thomas int n, nentries; 4110b86b1bbSFabien Thomas uint32_t nsamples; 4120b86b1bbSFabien Thomas pmc_id_t pmcid; 4130b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn; 4140b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch; 4150b86b1bbSFabien Thomas 4160b86b1bbSFabien Thomas /* 4170b86b1bbSFabien Thomas * We pull out all callgraph nodes in the top-level hash table 4180b86b1bbSFabien Thomas * with a matching PMC id. We then sort these based on the 4190b86b1bbSFabien Thomas * frequency of occurrence. Each callgraph node is then 4200b86b1bbSFabien Thomas * printed. 4210b86b1bbSFabien Thomas */ 4220b86b1bbSFabien Thomas 4230b86b1bbSFabien Thomas nsamples = 0; 4240b86b1bbSFabien Thomas pmcid = pmcr->pr_pmcid; 4250b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 4260b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 4270b86b1bbSFabien Thomas pmcstat_cgnode_hash_count)) == NULL) 4280b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot sort callgraph"); 4290b86b1bbSFabien Thomas cgn = sortbuffer; 4300b86b1bbSFabien Thomas 4310b86b1bbSFabien Thomas for (n = 0; n < PMCSTAT_NHASH; n++) 4320b86b1bbSFabien Thomas LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 4330b86b1bbSFabien Thomas if (pch->pch_pmcid == pmcid) { 4340b86b1bbSFabien Thomas nsamples += pch->pch_cgnode->pcg_count; 4350b86b1bbSFabien Thomas *cgn++ = pch->pch_cgnode; 4360b86b1bbSFabien Thomas } 4370b86b1bbSFabien Thomas 4380b86b1bbSFabien Thomas nentries = cgn - sortbuffer; 4390b86b1bbSFabien Thomas assert(nentries <= pmcstat_cgnode_hash_count); 4400b86b1bbSFabien Thomas 4410b86b1bbSFabien Thomas if (nentries == 0) { 4420b86b1bbSFabien Thomas free(sortbuffer); 4430b86b1bbSFabien Thomas return; 4440b86b1bbSFabien Thomas } 4450b86b1bbSFabien Thomas 4460b86b1bbSFabien Thomas qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 4470b86b1bbSFabien Thomas pmcstat_cgnode_compare); 4480b86b1bbSFabien Thomas 4490b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, 4500b86b1bbSFabien Thomas "@ %s [%u samples]\n\n", 4510b86b1bbSFabien Thomas pmcstat_string_unintern(pmcr->pr_pmcname), 4520b86b1bbSFabien Thomas nsamples); 4530b86b1bbSFabien Thomas 4540b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 4550b86b1bbSFabien Thomas pmcstat_previous_filename_printed = NULL; 4560b86b1bbSFabien Thomas pmcstat_cgnode_print(*cgn, 0, nsamples); 4570b86b1bbSFabien Thomas (void) fprintf(args.pa_graphfile, "\n"); 4580b86b1bbSFabien Thomas } 4590b86b1bbSFabien Thomas 4600b86b1bbSFabien Thomas free(sortbuffer); 4610b86b1bbSFabien Thomas } 4620b86b1bbSFabien Thomas 4630b86b1bbSFabien Thomas /* 4640b86b1bbSFabien Thomas * Print out callgraphs. 4650b86b1bbSFabien Thomas */ 4660b86b1bbSFabien Thomas 4670b86b1bbSFabien Thomas static void 4680b86b1bbSFabien Thomas pmcstat_callgraph_print(void) 4690b86b1bbSFabien Thomas { 4700b86b1bbSFabien Thomas struct pmcstat_pmcrecord *pmcr; 4710b86b1bbSFabien Thomas 4720b86b1bbSFabien Thomas LIST_FOREACH(pmcr, &pmcstat_pmcs, pr_next) 4730b86b1bbSFabien Thomas pmcstat_callgraph_print_for_pmcid(pmcr); 4740b86b1bbSFabien Thomas } 4750b86b1bbSFabien Thomas 4760b86b1bbSFabien Thomas static void 4770b86b1bbSFabien Thomas pmcstat_cgnode_topprint(struct pmcstat_cgnode *cg, 478821a352aSMatt Macy int depth __unused, uint32_t nsamples) 4790b86b1bbSFabien Thomas { 4800b86b1bbSFabien Thomas int v_attrs, vs_len, ns_len, width, len, n, nchildren; 4810b86b1bbSFabien Thomas float v; 4820b86b1bbSFabien Thomas char ns[30], vs[10]; 4830b86b1bbSFabien Thomas struct pmcstat_symbol *sym; 4840b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 4850b86b1bbSFabien Thomas 4860b86b1bbSFabien Thomas /* Format value. */ 4870b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(cg); 4880b86b1bbSFabien Thomas snprintf(vs, sizeof(vs), "%.1f", v); 4890b86b1bbSFabien Thomas v_attrs = PMCSTAT_ATTRPERCENT(v); 4900b86b1bbSFabien Thomas 4910b86b1bbSFabien Thomas /* Format name. */ 4920b86b1bbSFabien Thomas sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 493*94e9ef85SMateusz Guzik if (sym == NULL) { 4940b86b1bbSFabien Thomas snprintf(ns, sizeof(ns), "%p", 4954bd2a4b5SMatt Macy (void *)(cg->pcg_image->pi_vaddr + cg->pcg_func)); 496*94e9ef85SMateusz Guzik } else { 497*94e9ef85SMateusz Guzik switch (args.pa_flags & (FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET)) { 498*94e9ef85SMateusz Guzik case FLAG_SKIP_TOP_FN_RES | FLAG_SHOW_OFFSET: 499*94e9ef85SMateusz Guzik case FLAG_SKIP_TOP_FN_RES: 500*94e9ef85SMateusz Guzik snprintf(ns, sizeof(ns), "%p", 501*94e9ef85SMateusz Guzik (void *)(cg->pcg_image->pi_vaddr + cg->pcg_func)); 502*94e9ef85SMateusz Guzik break; 503*94e9ef85SMateusz Guzik case FLAG_SHOW_OFFSET: 504*94e9ef85SMateusz Guzik snprintf(ns, sizeof(ns), "%s+%#0lx", 505*94e9ef85SMateusz Guzik pmcstat_string_unintern(sym->ps_name), 506*94e9ef85SMateusz Guzik cg->pcg_func - sym->ps_start); 507*94e9ef85SMateusz Guzik break; 508*94e9ef85SMateusz Guzik default: 509*94e9ef85SMateusz Guzik snprintf(ns, sizeof(ns), "%s", 510*94e9ef85SMateusz Guzik pmcstat_string_unintern(sym->ps_name)); 511*94e9ef85SMateusz Guzik break; 512*94e9ef85SMateusz Guzik } 513*94e9ef85SMateusz Guzik } 5140b86b1bbSFabien Thomas 5150b86b1bbSFabien Thomas PMCSTAT_ATTRON(v_attrs); 5160b86b1bbSFabien Thomas PMCSTAT_PRINTW("%5.5s", vs); 5170b86b1bbSFabien Thomas PMCSTAT_ATTROFF(v_attrs); 518*94e9ef85SMateusz Guzik PMCSTAT_PRINTW(" %-10.10s %-30.30s", 5190b86b1bbSFabien Thomas pmcstat_string_unintern(cg->pcg_image->pi_name), 5200b86b1bbSFabien Thomas ns); 5210b86b1bbSFabien Thomas 5220b86b1bbSFabien Thomas nchildren = cg->pcg_nchildren; 5230b86b1bbSFabien Thomas if (nchildren == 0) { 5240b86b1bbSFabien Thomas PMCSTAT_PRINTW("\n"); 5250b86b1bbSFabien Thomas return; 5260b86b1bbSFabien Thomas } 5270b86b1bbSFabien Thomas 5280b86b1bbSFabien Thomas width = pmcstat_displaywidth - 40; 5290b86b1bbSFabien Thomas 5300b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 5310b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 5320b86b1bbSFabien Thomas nchildren)) == NULL) 5330b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot print callgraph"); 5340b86b1bbSFabien Thomas cgn = sortbuffer; 5350b86b1bbSFabien Thomas 5360b86b1bbSFabien Thomas LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 5370b86b1bbSFabien Thomas *cgn++ = pcg; 5380b86b1bbSFabien Thomas 5390b86b1bbSFabien Thomas assert(cgn - sortbuffer == (int)nchildren); 5400b86b1bbSFabien Thomas 5410b86b1bbSFabien Thomas qsort(sortbuffer, nchildren, sizeof(struct pmcstat_cgnode *), 5420b86b1bbSFabien Thomas pmcstat_cgnode_compare); 5430b86b1bbSFabien Thomas 5440b86b1bbSFabien Thomas /* Count how many callers. */ 5450b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 5460b86b1bbSFabien Thomas pcg = *cgn; 5470b86b1bbSFabien Thomas 5480b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(pcg); 5490b86b1bbSFabien Thomas if (v < pmcstat_threshold) 5500b86b1bbSFabien Thomas break; 5510b86b1bbSFabien Thomas } 5520b86b1bbSFabien Thomas nchildren = n; 5530b86b1bbSFabien Thomas 5540b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 5550b86b1bbSFabien Thomas pcg = *cgn; 5560b86b1bbSFabien Thomas 5570b86b1bbSFabien Thomas /* Format value. */ 5580b86b1bbSFabien Thomas if (nchildren > 1) { 5590b86b1bbSFabien Thomas v = PMCPL_CG_COUNTP(pcg); 5600b86b1bbSFabien Thomas vs_len = snprintf(vs, sizeof(vs), ":%.1f", v); 5610b86b1bbSFabien Thomas v_attrs = PMCSTAT_ATTRPERCENT(v); 5620b86b1bbSFabien Thomas } else 5630b86b1bbSFabien Thomas vs_len = 0; 5640b86b1bbSFabien Thomas 5650b86b1bbSFabien Thomas /* Format name. */ 5660b86b1bbSFabien Thomas sym = pmcstat_symbol_search(pcg->pcg_image, pcg->pcg_func); 5670b86b1bbSFabien Thomas if (sym != NULL) { 5680b86b1bbSFabien Thomas ns_len = snprintf(ns, sizeof(ns), "%s", 5690b86b1bbSFabien Thomas pmcstat_string_unintern(sym->ps_name)); 5700b86b1bbSFabien Thomas } else 5710b86b1bbSFabien Thomas ns_len = snprintf(ns, sizeof(ns), "%p", 5720b86b1bbSFabien Thomas (void *)pcg->pcg_func); 5730b86b1bbSFabien Thomas 5740b86b1bbSFabien Thomas len = ns_len + vs_len + 1; 5750b86b1bbSFabien Thomas if (width - len < 0) { 5760b86b1bbSFabien Thomas PMCSTAT_PRINTW(" ..."); 5770b86b1bbSFabien Thomas break; 5780b86b1bbSFabien Thomas } 5790b86b1bbSFabien Thomas width -= len; 5800b86b1bbSFabien Thomas 5810b86b1bbSFabien Thomas PMCSTAT_PRINTW(" %s", ns); 5820b86b1bbSFabien Thomas if (nchildren > 1) { 5830b86b1bbSFabien Thomas PMCSTAT_ATTRON(v_attrs); 5840b86b1bbSFabien Thomas PMCSTAT_PRINTW("%s", vs); 5850b86b1bbSFabien Thomas PMCSTAT_ATTROFF(v_attrs); 5860b86b1bbSFabien Thomas } 5870b86b1bbSFabien Thomas } 5880b86b1bbSFabien Thomas PMCSTAT_PRINTW("\n"); 5890b86b1bbSFabien Thomas free(sortbuffer); 5900b86b1bbSFabien Thomas } 5910b86b1bbSFabien Thomas 5920b86b1bbSFabien Thomas /* 5930b86b1bbSFabien Thomas * Top mode display. 5940b86b1bbSFabien Thomas */ 5950b86b1bbSFabien Thomas 5960b86b1bbSFabien Thomas void 5970b86b1bbSFabien Thomas pmcpl_cg_topdisplay(void) 5980b86b1bbSFabien Thomas { 5990b86b1bbSFabien Thomas int n, nentries; 6000b86b1bbSFabien Thomas uint32_t nsamples; 6010b86b1bbSFabien Thomas struct pmcstat_cgnode **sortbuffer, **cgn; 6020b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch; 6030b86b1bbSFabien Thomas struct pmcstat_pmcrecord *pmcr; 6040b86b1bbSFabien Thomas 6050b86b1bbSFabien Thomas pmcr = pmcstat_pmcindex_to_pmcr(pmcstat_pmcinfilter); 606410c7662SFabien Thomas if (!pmcr) 607410c7662SFabien Thomas err(EX_SOFTWARE, "ERROR: invalid pmcindex"); 6080b86b1bbSFabien Thomas 6090b86b1bbSFabien Thomas /* 6100b86b1bbSFabien Thomas * We pull out all callgraph nodes in the top-level hash table 6110b86b1bbSFabien Thomas * with a matching PMC index. We then sort these based on the 6120b86b1bbSFabien Thomas * frequency of occurrence. Each callgraph node is then 6130b86b1bbSFabien Thomas * printed. 6140b86b1bbSFabien Thomas */ 6150b86b1bbSFabien Thomas 6160b86b1bbSFabien Thomas nsamples = 0; 6170b86b1bbSFabien Thomas 6180b86b1bbSFabien Thomas if ((sortbuffer = (struct pmcstat_cgnode **) 6190b86b1bbSFabien Thomas malloc(sizeof(struct pmcstat_cgnode *) * 6200b86b1bbSFabien Thomas pmcstat_cgnode_hash_count)) == NULL) 6210b86b1bbSFabien Thomas err(EX_OSERR, "ERROR: Cannot sort callgraph"); 6220b86b1bbSFabien Thomas cgn = sortbuffer; 6230b86b1bbSFabien Thomas 6240b86b1bbSFabien Thomas for (n = 0; n < PMCSTAT_NHASH; n++) 6250b86b1bbSFabien Thomas LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 6260b86b1bbSFabien Thomas if (pmcr == NULL || pch->pch_pmcid == pmcr->pr_pmcid) { 6270b86b1bbSFabien Thomas nsamples += pch->pch_cgnode->pcg_count; 6280b86b1bbSFabien Thomas *cgn++ = pch->pch_cgnode; 6290b86b1bbSFabien Thomas } 6300b86b1bbSFabien Thomas 6310b86b1bbSFabien Thomas nentries = cgn - sortbuffer; 6320b86b1bbSFabien Thomas assert(nentries <= pmcstat_cgnode_hash_count); 6330b86b1bbSFabien Thomas 6340b86b1bbSFabien Thomas if (nentries == 0) { 6350b86b1bbSFabien Thomas free(sortbuffer); 6360b86b1bbSFabien Thomas return; 6370b86b1bbSFabien Thomas } 6380b86b1bbSFabien Thomas 6390b86b1bbSFabien Thomas qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 6400b86b1bbSFabien Thomas pmcstat_cgnode_compare); 6410b86b1bbSFabien Thomas 642*94e9ef85SMateusz Guzik PMCSTAT_PRINTW("%5.5s %-10.10s %-30.30s %s\n", 6430b86b1bbSFabien Thomas "%SAMP", "IMAGE", "FUNCTION", "CALLERS"); 6440b86b1bbSFabien Thomas 6450b86b1bbSFabien Thomas nentries = min(pmcstat_displayheight - 2, nentries); 6460b86b1bbSFabien Thomas 6470b86b1bbSFabien Thomas for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 6480b86b1bbSFabien Thomas if (PMCPL_CG_COUNTP(*cgn) < pmcstat_threshold) 6490b86b1bbSFabien Thomas break; 6500b86b1bbSFabien Thomas pmcstat_cgnode_topprint(*cgn, 0, nsamples); 6510b86b1bbSFabien Thomas } 6520b86b1bbSFabien Thomas 6530b86b1bbSFabien Thomas free(sortbuffer); 6540b86b1bbSFabien Thomas } 6550b86b1bbSFabien Thomas 6560b86b1bbSFabien Thomas /* 6570b86b1bbSFabien Thomas * Handle top mode keypress. 6580b86b1bbSFabien Thomas */ 6590b86b1bbSFabien Thomas 6600b86b1bbSFabien Thomas int 661d27927f7SRuslan Bukin pmcpl_cg_topkeypress(int c, void *arg) 6620b86b1bbSFabien Thomas { 663d27927f7SRuslan Bukin WINDOW *w; 664d27927f7SRuslan Bukin 665d27927f7SRuslan Bukin w = (WINDOW *)arg; 6660b86b1bbSFabien Thomas 6670b86b1bbSFabien Thomas (void) c; (void) w; 6680b86b1bbSFabien Thomas 6690b86b1bbSFabien Thomas return 0; 6700b86b1bbSFabien Thomas } 6710b86b1bbSFabien Thomas 6720b86b1bbSFabien Thomas int 6730b86b1bbSFabien Thomas pmcpl_cg_init(void) 6740b86b1bbSFabien Thomas { 6750b86b1bbSFabien Thomas int i; 6760b86b1bbSFabien Thomas 6770b86b1bbSFabien Thomas pmcstat_cgnode_hash_count = 0; 6780b86b1bbSFabien Thomas pmcstat_previous_filename_printed = NULL; 6790b86b1bbSFabien Thomas 6800b86b1bbSFabien Thomas for (i = 0; i < PMCSTAT_NHASH; i++) { 6810b86b1bbSFabien Thomas LIST_INIT(&pmcstat_cgnode_hash[i]); 6820b86b1bbSFabien Thomas } 6830b86b1bbSFabien Thomas 6840b86b1bbSFabien Thomas return (0); 6850b86b1bbSFabien Thomas } 6860b86b1bbSFabien Thomas 6870b86b1bbSFabien Thomas void 6880b86b1bbSFabien Thomas pmcpl_cg_shutdown(FILE *mf) 6890b86b1bbSFabien Thomas { 6900b86b1bbSFabien Thomas int i; 6910b86b1bbSFabien Thomas struct pmcstat_cgnode_hash *pch, *pchtmp; 6920b86b1bbSFabien Thomas 6930b86b1bbSFabien Thomas (void) mf; 6940b86b1bbSFabien Thomas 6950b86b1bbSFabien Thomas if (args.pa_flags & FLAG_DO_CALLGRAPHS) 6960b86b1bbSFabien Thomas pmcstat_callgraph_print(); 6970b86b1bbSFabien Thomas 6980b86b1bbSFabien Thomas /* 6990b86b1bbSFabien Thomas * Free memory. 7000b86b1bbSFabien Thomas */ 7010b86b1bbSFabien Thomas for (i = 0; i < PMCSTAT_NHASH; i++) { 7020b86b1bbSFabien Thomas LIST_FOREACH_SAFE(pch, &pmcstat_cgnode_hash[i], pch_next, 7030b86b1bbSFabien Thomas pchtmp) { 7040b86b1bbSFabien Thomas pmcstat_cgnode_free(pch->pch_cgnode); 7050b86b1bbSFabien Thomas LIST_REMOVE(pch, pch_next); 7060b86b1bbSFabien Thomas free(pch); 7070b86b1bbSFabien Thomas } 7080b86b1bbSFabien Thomas } 7090b86b1bbSFabien Thomas } 7100b86b1bbSFabien Thomas 711