nethercote | 5912c81 | 2004-02-15 15:38:08 +0000 | [diff] [blame] | 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 | |
nethercote | c9f3692 | 2004-02-14 16:40:02 +0000 | [diff] [blame] | 5 | #include <stdio.h> |
nethercote | a0b7791 | 2004-06-02 20:43:24 +0000 | [diff] [blame] | 6 | #include <stdlib.h> |
nethercote | c9f3692 | 2004-02-14 16:40:02 +0000 | [diff] [blame] | 7 | #include "Main.h" |
| 8 | #include "Defines.h" |
| 9 | #include "Dimensions.h" |
| 10 | #include "Error.h" |
| 11 | #include "HpFile.h" |
| 12 | #include "Utilities.h" |
| 13 | |
| 14 | /* own stuff */ |
| 15 | #include "Scale.h" |
| 16 | |
| 17 | /* |
| 18 | * Return the maximum combined height that all the sample |
| 19 | * curves will reach. This (absolute) figure can then be |
| 20 | * used to scale the samples automatically so that they |
| 21 | * fit on the page. |
| 22 | */ |
| 23 | |
nethercote | c9f3692 | 2004-02-14 16:40:02 +0000 | [diff] [blame] | 24 | floatish |
| 25 | MaxCombinedHeight() |
| 26 | { |
| 27 | intish i; |
| 28 | intish j; |
| 29 | floatish mx; |
| 30 | int bucket; |
| 31 | floatish value; |
| 32 | struct chunk* ch; |
| 33 | floatish *maxima; |
| 34 | |
| 35 | maxima = (floatish*) xmalloc(nsamples * sizeof(floatish)); |
| 36 | for (i = 0; i < nsamples; i++) { |
| 37 | maxima[ i ] = 0.0; |
| 38 | } |
| 39 | |
| 40 | for (i = 0; i < nidents; i++) { |
| 41 | for (ch = identtable[i]->chk; ch; ch = ch->next) { |
| 42 | for (j = 0; j < ch->nd; j++) { |
| 43 | bucket = ch->d[j].bucket; |
| 44 | value = ch->d[j].value; |
| 45 | if (bucket >= nsamples) |
| 46 | Disaster("bucket out of range"); |
| 47 | maxima[ bucket ] += value; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | for (mx = maxima[ 0 ], i = 0; i < nsamples; i++) { |
| 53 | if (maxima[ i ] > mx) mx = maxima[ i ]; |
| 54 | } |
| 55 | |
| 56 | free(maxima); |
| 57 | return mx; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | |
| 62 | /* |
| 63 | * Scale the values from the samples so that they will fit on |
| 64 | * the page. |
| 65 | */ |
| 66 | |
| 67 | extern floatish xrange; |
| 68 | extern floatish yrange; |
| 69 | |
| 70 | void |
| 71 | Scale() |
| 72 | { |
| 73 | intish i; |
| 74 | intish j; |
| 75 | floatish sf; |
| 76 | struct chunk* ch; |
| 77 | |
| 78 | if (yrange == 0.0) /* no samples */ |
| 79 | return; |
| 80 | |
| 81 | sf = graphheight / yrange; |
| 82 | |
| 83 | for (i = 0; i < nidents; i++) { |
| 84 | for (ch = identtable[i]->chk; ch; ch = ch->next) { |
| 85 | for (j = 0; j < ch->nd; j++) { |
| 86 | ch->d[j].value = ch->d[j].value * sf; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |