~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to massif/hp2ps/TraceElement.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.  */
4
 
 
5
 
#include <stdio.h>
6
 
#include <stdlib.h>
7
 
#include "Main.h"
8
 
#include "Defines.h"
9
 
#include "HpFile.h"
10
 
#include "Error.h"
11
 
#include "Utilities.h"
12
 
 
13
 
/* own stuff */
14
 
#include "TraceElement.h"
15
 
 
16
 
/*
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.    
22
 
 */
23
 
 
24
 
extern floatish thresholdpercent;
25
 
 
26
 
void TraceElement()
27
 
{
28
 
    intish i;
29
 
    intish j;
30
 
    struct chunk* ch;
31
 
    floatish grandtotal;
32
 
    intish   min;
33
 
    floatish t;
34
 
    floatish p;
35
 
    struct entry* e;
36
 
    intish *totals; 
37
 
 
38
 
    totals = (intish *) xmalloc(nidents * sizeof(intish));
39
 
 
40
 
    /* find totals */
41
 
 
42
 
    for (i = 0; i < nidents; i++) {
43
 
        totals[ i ] = 0;
44
 
    }
45
 
 
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; 
50
 
            }
51
 
        }
52
 
    }    
53
 
 
54
 
    /* sort on the basis of total */
55
 
 
56
 
    for (i = 0; i < nidents-1; i++) {
57
 
        min = i;
58
 
        for (j = i+1; j < nidents; j++) {
59
 
            if (totals[ j ] < totals[ min ]) {
60
 
                min = j;
61
 
            }
62
 
        }    
63
 
 
64
 
        t = totals[ min ];
65
 
        totals[ min ] = totals[ i ];
66
 
        totals[ i ] = t;
67
 
 
68
 
        e = identtable[ min ];
69
 
        identtable[ min ] = identtable[ i ];
70
 
        identtable[ i ] = e;
71
 
    }
72
 
 
73
 
 
74
 
    /* find the grand total (NB: can get *BIG*!) */
75
 
 
76
 
    grandtotal = 0.0;
77
 
 
78
 
    for (i = 0; i < nidents; i++) {
79
 
        grandtotal += (floatish) totals[ i ];
80
 
    }
81
 
 
82
 
    t = 0.0;    /* cumulative percentage */
83
 
   
84
 
    for (i = 0; i < nidents; i++) {
85
 
        p = (100.0 * (floatish) totals[i]) / grandtotal;
86
 
        t = t + p; 
87
 
        if (t >= THRESHOLD_PERCENT) {
88
 
            break;
89
 
        }
90
 
    }
91
 
 
92
 
    /* identifiers from 0 to i-1 should be removed */
93
 
    for (j = 0; i < nidents; i++, j++) {
94
 
        identtable[j] = identtable[i]; 
95
 
    }
96
 
 
97
 
    nidents = j;
98
 
 
99
 
    free(totals);
100
 
}