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

« back to all changes in this revision

Viewing changes to massif/hp2ps/TopTwenty.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 "Error.h"
10
 
#include "HpFile.h"
11
 
#include "Utilities.h"
12
 
 
13
 
/* own stuff */
14
 
#include "TopTwenty.h"
15
 
 
16
 
/*
17
 
 *      We only have room in the key for a maximum of 20 identifiers. 
18
 
 *      We therefore choose to keep the top 20 bands --- these will 
19
 
 *      be the most important ones, since this pass is performed after 
20
 
 *      the threshold and standard deviation passes. If there are more 
21
 
 *      than 20 bands, the excess are gathered together as an "OTHER" ]
22
 
 *      band which appears as band 20.
23
 
 */
24
 
 
25
 
void
26
 
TopTwenty()
27
 
{
28
 
    intish i;
29
 
    intish j;
30
 
    intish compact;
31
 
    intish bucket;
32
 
    floatish value;
33
 
    struct entry* en;
34
 
    struct chunk* ch;
35
 
    floatish *other; 
36
 
 
37
 
    i = nidents;
38
 
    if (i <= TWENTY) return;    /* nothing to do! */
39
 
 
40
 
    other = (floatish*) xmalloc(nsamples * sizeof(floatish));
41
 
    /* build a list of samples for "OTHER" */ 
42
 
 
43
 
    compact = (i - TWENTY) + 1;
44
 
 
45
 
    for (i = 0; i < nsamples; i++) {
46
 
        other[ i ] = 0.0;
47
 
    }   
48
 
 
49
 
    for (i = 0; i < compact && i < nidents; i++) {
50
 
        for (ch = identtable[i]->chk; ch; ch = ch->next) {
51
 
            for (j = 0; j < ch->nd; j++) {
52
 
                bucket = ch->d[j].bucket;
53
 
                value  = ch->d[j].value;
54
 
                if (bucket >= nsamples)
55
 
                    Disaster("bucket out of range");
56
 
                other[ bucket ] += value;
57
 
            }   
58
 
        }    
59
 
    }    
60
 
 
61
 
    en = MakeEntry("OTHER");
62
 
    en->next = 0;
63
 
 
64
 
    for (i = 0; i < nsamples; i++) {
65
 
        StoreSample(en, i, other[i]);
66
 
    }
67
 
 
68
 
    /* slide samples down */
69
 
    for (i = compact; i < nidents; i++) {
70
 
        identtable[i-compact+1] = identtable[i];
71
 
    }
72
 
 
73
 
    nidents = TWENTY;
74
 
    identtable[0] = en;
75
 
    free(other);
76
 
}