-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats.h
85 lines (65 loc) · 2.2 KB
/
stats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* {{{
This file is part of libtraceproc - a library for tracing Pro*C/OCI calls
Copyright (C) 2013 Georg Sauthoff <mail@georg.so>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}}} */
#ifndef STATS_H
#define STATS_H
#include <stddef.h>
#include <time.h>
struct Stats {
size_t *counts;
size_t count_sum;
size_t *fn_counts;
size_t fn_count_sum;
struct timespec *times;
struct timespec time_sum;
struct timespec *fn_times;
struct timespec fn_time_sum;
struct timespec prog_start;
struct timespec prog_end;
struct timespec prog_time;
};
typedef struct Stats Stats;
#define STATS_BEGIN(A) \
struct timespec time_begin = {0}, time_end = {0}; \
do { \
if (A) { \
int ret = clock_gettime(WRAP_CLOCK_ID, &time_begin); \
IFERRNOEXIT(ret, 0, 10); \
} \
} while (0)
#define STATS_END(A, B, C) \
do { \
if (A) { \
int ret = clock_gettime(WRAP_CLOCK_ID, &time_end); \
IFERRNOEXIT(ret, 0, 10); \
++stats.fn_counts[B]; \
ret = timespec_add_intv(stats.fn_times + B,\
&time_begin, &time_end); \
IFTRUEEXIT(ret, 0, 10); \
if (C) { \
++stats.counts[C]; \
ret = timespec_add_intv(stats.times + C, &time_begin, &time_end); \
IFTRUEEXIT(ret, 0, 10); \
} \
} \
} while (0)
__attribute__((visibility("hidden")))
int stats_init(Stats *stats, size_t type_size, size_t fn_size);
__attribute__((visibility("hidden")))
int stats_sum_up(Stats *stats, size_t type_size, size_t fn_size,
const struct timespec *prog_time);
__attribute__((visibility("hidden")))
int stats_pp_fns(const Stats *stats, char const * const * names,
unsigned n);
#endif