/* */
1 /*
2 * Copyright (c) 2009
3 * Tama Communications Corporation
4 *
5 * This file is part of GNU GLOBAL.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _STATISTICS_H_
22 #define _STATISTICS_H_
23
24 #ifndef __attribute__
25 /* This feature is available in gcc versions 2.5 and later. */
26 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
27 # define __attribute__(x)
28 # endif
29 /* The __-protected variants of `format' and `printf' attributes
30 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
31 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
32 # define __format__ format
33 # define __printf__ printf
34 # endif
35 #endif
36
37 /**
38 * @file
39 * STATISTICS_TIME
40 *
41 * @par Usage:
42 * @code
43 * main()
44 * {
45 * STATISTICS_TIME *tim;
46 *
47 * init_statistics();
48 * tim = statistics_time_start("Time of making foo");
49 * makefoo();
50 * statistics_time_end(tim);
51 * for (i = 0; i < 3; i++) {
52 * tim = statistics_time_start("Time of making bar%d", i);
53 * makebar(i);
54 * statistics_time_end(tim);
55 * }
56 * print_statistics(style);
57 * exit(0);
58 * }
59 * @endcode
60 */
61 struct statistics_time;
62 typedef struct statistics_time STATISTICS_TIME;
63
64 /**
65 * @par STATISTICS_STYLE_NONE:
66 * Resource deallocation only.
67 *
68 * @par STATISTICS_STYLE_LIST:
69 * Print statistics information like following, and deallocate resource.
70 *
71 * @code{.txt}
72 * - Time of making foo .... user 2.016s system 0.128s elapsed 1.437s 149.0%
73 * - Time of making bar0 ... user 0.268s system 0.040s elapsed 0.282s 109.1%
74 * - Time of making bar1 ... user 1.084s system 0.120s elapsed 1.208s 99.2%
75 * - Time of making bar2 ... user 18.325s system 2.112s elapsed 16.010s 127.3%
76 * - The entire time ....... user 21.721s system 2.420s elapsed 18.989s 127.4%
77 * @endcode
78 *
79 * @par STATISTICS_STYLE_TABLE:
80 * Print statistics information like following, and deallocate resource.
81 *
82 * @code{.txt}
83 * period user[sec] system[sec] elapsed[sec] %CPU
84 * ------------------- --------- ----------- ------------ -----
85 * Time of making foo 2.016 0.128 1.437 149.0
86 * Time of making bar0 0.268 0.040 0.282 109.1
87 * Time of making bar1 1.084 0.120 1.208 99.2
88 * Time of making bar2 18.325 2.112 16.010 127.3
89 * ------------------- --------- ----------- ------------ -----
90 * The entire time 21.721 2.420 18.989 127.4
91 * @endcode
92 */
93 enum {
94 STATISTICS_STYLE_NONE,
95 STATISTICS_STYLE_LIST,
96 STATISTICS_STYLE_TABLE
97 };
98
99 void init_statistics(void);
100 STATISTICS_TIME *statistics_time_start(const char *, ...)
101 __attribute__ ((__format__ (__printf__, 1, 2)));
102 void statistics_time_end(STATISTICS_TIME *);
103 void print_statistics(int);
104
105 #endif
/* */