FreeBSD/usr.sbin/pmcstat/pmcpl_calltree.c
/*
 * Format and display given PMC index.
 */
Format and display given PMC index.
Format and display given PMC index .
static void
pmcpl_ct_node_printtop(struct pmcpl_ct_sample *rsamples, int pmcin, int maxy)
{
#undef	TS
#undef	TSI
#define	TS(x, y)	(pmcpl_ct_topscreen[x][y])
#define	TSI(x, y)	(pmcpl_ct_topscreen[x][pmcpl_ct_topmax[y].ln_index])
	int v_attrs, ns_len, vs_len, is_len, width, indentwidth, x, y;
	float v;
	char ns[30], vs[10], is[20];
	struct pmcpl_ct_node *ct;
	const char *space = " ";
	for (y = 0; ; y++) {
		ct = TS(1, y);
		if (ct == NULL)
			break;
		pmcpl_ct_topmax[y].ln_sum = 0;
		pmcpl_ct_topmax[y].ln_index = y;
		for (x = 1; TS(x, y) != NULL; x++) {
			pmcpl_ct_topmax[y].ln_sum +=
			    PMCPL_CT_SAMPLE(pmcin, &TS(x, y)->pct_samples);
		}
	}
	qsort(pmcpl_ct_topmax, y, sizeof(pmcpl_ct_topmax[0]),
	    pmcpl_ct_line_compare);
	pmcpl_ct_topmax[y].ln_index = y;
	for (y = 0; y < maxy; y++) {
		ct = TSI(1, y);
		if (ct == NULL)
			break;
		if (y > 0)
			PMCSTAT_PRINTW("\n");
		v = pmcpl_ct_topmax[y].ln_sum * 100.0 /
		    rsamples->sb[pmcin];
		snprintf(vs, sizeof(vs), "%.1f", v);
		v_attrs = PMCSTAT_ATTRPERCENT(v);
		PMCSTAT_ATTRON(v_attrs);
		PMCSTAT_PRINTW("%5.5s ", vs);
		PMCSTAT_ATTROFF(v_attrs);
		width = indentwidth = 5 + 1;
		for (x = 1; (ct = TSI(x, y)) != NULL; x++) {
			vs[0] = '\0'; vs_len = 0;
			is[0] = '\0'; is_len = 0;
			v = PMCPL_CT_SAMPLEP(pmcin, &ct->pct_samples);
			if (v > pmcstat_threshold)
				vs_len  = snprintf(vs, sizeof(vs),
				    "(%.1f%%)", v);
			v_attrs = PMCSTAT_ATTRPERCENT(v);
			if (pmcstat_skiplink && v <= pmcstat_threshold) {
				strlcpy(ns, ".", sizeof(ns));
				ns_len = 1;
			} else {
			if (ct->pct_sym != NULL) {
				ns_len = snprintf(ns, sizeof(ns), "%s",
				    pmcstat_string_unintern(ct->pct_sym->ps_name));
			} else
				ns_len = snprintf(ns, sizeof(ns), "%p",
				    (void *)ct->pct_func);
			if (x == 1 ||
			    TSI(x-1, y)->pct_image != ct->pct_image)
				is_len = snprintf(is, sizeof(is), "@%s",
				    pmcstat_string_unintern(ct->pct_image->pi_name));
			width += ns_len + is_len + vs_len + 1;
			}
			if (width >= pmcstat_displaywidth) {
				maxy--;
				if (y >= maxy)
					break;
				PMCSTAT_PRINTW("\n%*s", indentwidth, space);
				width = indentwidth + ns_len + is_len + vs_len;
			}
			PMCSTAT_ATTRON(v_attrs);
			PMCSTAT_PRINTW("%s%s%s ", ns, is, vs);
			PMCSTAT_ATTROFF(v_attrs);
		}
	}
}
static void pmcpl_ct_node_printtop ( struct pmcpl_ct_sample * rsamples , int pmcin , int maxy ) { #undef 	TS #undef 	TSI #define TS ( x , y ) 	(pmcpl_ct_topscreen[x][y]) #define TSI ( x , y ) 	(pmcpl_ct_topscreen[x][pmcpl_ct_topmax[y].ln_index]) int v_attrs , ns_len , vs_len , is_len , width , indentwidth , x , y ; float v ; char ns [ 30 ] , vs [ 10 ] , is [ 20 ] ; struct pmcpl_ct_node * ct ; const char * space = " " ; for ( y = 0 ; ; y ++ ) { ct = TS ( 1 , y ) ; if ( ct == NULL ) break ; pmcpl_ct_topmax [ y ] . ln_sum = 0 ; pmcpl_ct_topmax [ y ] . ln_index = y ; for ( x = 1 ; TS ( x , y ) != NULL ; x ++ ) { pmcpl_ct_topmax [ y ] . ln_sum += PMCPL_CT_SAMPLE ( pmcin , & TS ( x , y ) -> pct_samples ) ; } } qsort ( pmcpl_ct_topmax , y , sizeof ( pmcpl_ct_topmax [ 0 ] ) , pmcpl_ct_line_compare ) ; pmcpl_ct_topmax [ y ] . ln_index = y ; for ( y = 0 ; y < maxy ; y ++ ) { ct = TSI ( 1 , y ) ; if ( ct == NULL ) break ; if ( y > 0 ) PMCSTAT_PRINTW ( " \n " ) ; v = pmcpl_ct_topmax [ y ] . ln_sum * 100.0 / rsamples -> sb [ pmcin ] ; snprintf ( vs , sizeof ( vs ) , " " , v ) ; v_attrs = PMCSTAT_ATTRPERCENT ( v ) ; PMCSTAT_ATTRON ( v_attrs ) ; PMCSTAT_PRINTW ( " " , vs ) ; PMCSTAT_ATTROFF ( v_attrs ) ; width = indentwidth = 5 + 1 ; for ( x = 1 ; ( ct = TSI ( x , y ) ) != NULL ; x ++ ) { vs [ 0 ] = ' \0 ' ; vs_len = 0 ; is [ 0 ] = ' \0 ' ; is_len = 0 ; v = PMCPL_CT_SAMPLEP ( pmcin , & ct -> pct_samples ) ; if ( v > pmcstat_threshold ) vs_len = snprintf ( vs , sizeof ( vs ) , " " , v ) ; v_attrs = PMCSTAT_ATTRPERCENT ( v ) ; if ( pmcstat_skiplink && v <= pmcstat_threshold ) { strlcpy ( ns , " " , sizeof ( ns ) ) ; ns_len = 1 ; } else { if ( ct -> pct_sym != NULL ) { ns_len = snprintf ( ns , sizeof ( ns ) , " " , pmcstat_string_unintern ( ct -> pct_sym -> ps_name ) ) ; } else ns_len = snprintf ( ns , sizeof ( ns ) , " " , ( void * ) ct -> pct_func ) ; if ( x == 1 || TSI ( x - 1 , y ) -> pct_image != ct -> pct_image ) is_len = snprintf ( is , sizeof ( is ) , " " , pmcstat_string_unintern ( ct -> pct_image -> pi_name ) ) ; width += ns_len + is_len + vs_len + 1 ; } if ( width >= pmcstat_displaywidth ) { maxy -- ; if ( y >= maxy ) break ; PMCSTAT_PRINTW ( " \n " , indentwidth , space ) ; width = indentwidth + ns_len + is_len + vs_len ; } PMCSTAT_ATTRON ( v_attrs ) ; PMCSTAT_PRINTW ( " " , ns , is , vs ) ; PMCSTAT_ATTROFF ( v_attrs ) ; } } }
Format and display given PMC index.
Format and display given PMC index .
/*
	 * Sort by line cost.
	 */ /* Output sum. */ /* Format value. */ /* Format image. */ /* Check for line wrap. */