1
/* This file is part of hp2ps, a graph drawer for memory profiles.
2
Copyright (C) 2002 The University Court of the University of Glasgow.
3
This program is governed by the license contained in the file LICENSE. */
11
#include "Utilities.h"
14
#include "TraceElement.h"
17
* Compute the total volume for each identifier, and the grand
18
* total of these totals. The identifiers whose totals when
19
* added together amount to less that a threshold percentage
20
* (default 1%) of the grand total are considered to be ``trace
21
* elements'' and they are thrown away.
24
extern floatish thresholdpercent;
38
totals = (intish *) xmalloc(nidents * sizeof(intish));
42
for (i = 0; i < nidents; i++) {
46
for (i = 0; i < nidents; i++) {
47
for (ch = identtable[i]->chk; ch; ch = ch->next) {
48
for (j = 0; j < ch->nd; j++) {
49
totals[ i ] += ch->d[j].value;
54
/* sort on the basis of total */
56
for (i = 0; i < nidents-1; i++) {
58
for (j = i+1; j < nidents; j++) {
59
if (totals[ j ] < totals[ min ]) {
65
totals[ min ] = totals[ i ];
68
e = identtable[ min ];
69
identtable[ min ] = identtable[ i ];
74
/* find the grand total (NB: can get *BIG*!) */
78
for (i = 0; i < nidents; i++) {
79
grandtotal += (floatish) totals[ i ];
82
t = 0.0; /* cumulative percentage */
84
for (i = 0; i < nidents; i++) {
85
p = (100.0 * (floatish) totals[i]) / grandtotal;
87
if (t >= THRESHOLD_PERCENT) {
92
/* identifiers from 0 to i-1 should be removed */
93
for (j = 0; i < nidents; i++, j++) {
94
identtable[j] = identtable[i];