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