]>
Commit | Line | Data |
---|---|---|
61af3de3 JG |
1 | /* |
2 | * stats.h -- Statistics helpers | |
3 | * | |
4 | * Copyright (C) 2004 Henrique M. Holschuh <hmh@debian.org> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
d1b4c504 | 10 | * |
61af3de3 JG |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
d32709d1 | 18 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
61af3de3 JG |
19 | */ |
20 | ||
21 | #ifndef STATS__H | |
22 | #define STATS__H | |
23 | ||
24 | #include <unistd.h> | |
25 | #include <stdint.h> | |
26 | ||
27 | /* Min-Max stat */ | |
28 | struct rng_stat { | |
29 | uint64_t max; /* Highest value seen */ | |
30 | uint64_t min; /* Lowest value seen */ | |
31 | uint64_t num_samples; /* Number of samples */ | |
32 | uint64_t sum; /* Sum of all samples */ | |
33 | }; | |
34 | ||
35 | /* Sets a prefix for all stat dumps. Maximum length is 19 chars */ | |
36 | extern void set_stat_prefix(const char* prefix); | |
37 | ||
38 | /* Computes elapsed time in microseconds */ | |
39 | extern uint64_t elapsed_time(struct timeval *start, | |
40 | struct timeval *stop); | |
41 | ||
42 | /* Updates min-max stat */ | |
43 | extern void update_stat(struct rng_stat *stat, uint64_t value); | |
44 | ||
45 | /* Updates min-max microseconds timer stat */ | |
46 | #define update_usectimer_stat(STAT, START, STOP) \ | |
47 | update_stat(STAT, elapsed_time(START, STOP)) | |
48 | ||
49 | /* | |
50 | * The following functions format a stat dump on buf, and | |
51 | * return a pointer to the start of buf | |
52 | */ | |
d1b4c504 | 53 | |
61af3de3 | 54 | /* Dump simple counter */ |
d1b4c504 | 55 | extern char *dump_stat_counter(char *buf, int size, |
61af3de3 JG |
56 | const char *msg, uint64_t value); |
57 | ||
58 | /* Dump min-max time stat */ | |
59 | extern char *dump_stat_stat(char *buf, int size, | |
60 | const char *msg, const char *unit, | |
61 | struct rng_stat *stat); | |
62 | ||
63 | /* | |
64 | * Dump min-max speed stat, base time unit is a microsecond | |
65 | */ | |
66 | extern char *dump_stat_bw(char *buf, int size, | |
67 | const char *msg, const char *unit, | |
68 | struct rng_stat *stat, | |
69 | uint64_t blocksize); | |
70 | ||
71 | #endif /* STATS__H */ |