mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-11 05:55:48 +00:00
ANSIfication of the hp2ps code. The most important changes are the correct use of the stdarg mechanism (former hacks could bite on other systems, so please tell upstream), inclusion of stdlib.h instead of declaring free yourself, adding a few missed PROTO()s and using size_t for xmalloc and xrealloc.: git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2399
77 lines
1.9 KiB
C
77 lines
1.9 KiB
C
/* This file is part of hp2ps, a graph drawer for memory profiles.
|
|
Copyright (C) 2002 The University Court of the University of Glasgow.
|
|
This program is governed by the license contained in the file LICENSE. */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "Main.h"
|
|
#include "Defines.h"
|
|
#include "Error.h"
|
|
#include "HpFile.h"
|
|
#include "Utilities.h"
|
|
|
|
/* own stuff */
|
|
#include "TopTwenty.h"
|
|
|
|
/*
|
|
* We only have room in the key for a maximum of 20 identifiers.
|
|
* We therefore choose to keep the top 20 bands --- these will
|
|
* be the most important ones, since this pass is performed after
|
|
* the threshold and standard deviation passes. If there are more
|
|
* than 20 bands, the excess are gathered together as an "OTHER" ]
|
|
* band which appears as band 20.
|
|
*/
|
|
|
|
void
|
|
TopTwenty()
|
|
{
|
|
intish i;
|
|
intish j;
|
|
intish compact;
|
|
intish bucket;
|
|
floatish value;
|
|
struct entry* en;
|
|
struct chunk* ch;
|
|
floatish *other;
|
|
|
|
i = nidents;
|
|
if (i <= TWENTY) return; /* nothing to do! */
|
|
|
|
other = (floatish*) xmalloc(nsamples * sizeof(floatish));
|
|
/* build a list of samples for "OTHER" */
|
|
|
|
compact = (i - TWENTY) + 1;
|
|
|
|
for (i = 0; i < nsamples; i++) {
|
|
other[ i ] = 0.0;
|
|
}
|
|
|
|
for (i = 0; i < compact && i < nidents; i++) {
|
|
for (ch = identtable[i]->chk; ch; ch = ch->next) {
|
|
for (j = 0; j < ch->nd; j++) {
|
|
bucket = ch->d[j].bucket;
|
|
value = ch->d[j].value;
|
|
if (bucket >= nsamples)
|
|
Disaster("bucket out of range");
|
|
other[ bucket ] += value;
|
|
}
|
|
}
|
|
}
|
|
|
|
en = MakeEntry("OTHER");
|
|
en->next = 0;
|
|
|
|
for (i = 0; i < nsamples; i++) {
|
|
StoreSample(en, i, other[i]);
|
|
}
|
|
|
|
/* slide samples down */
|
|
for (i = compact; i < nidents; i++) {
|
|
identtable[i-compact+1] = identtable[i];
|
|
}
|
|
|
|
nidents = TWENTY;
|
|
identtable[0] = en;
|
|
free(other);
|
|
}
|