File: stats.h

package info (click to toggle)
austin 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,444 kB
  • sloc: ansic: 8,622; python: 2,669; sh: 106; makefile: 54
file content (142 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// This file is part of "austin" which is released under GPL.
//
// See file LICENCE or go to http://www.gnu.org/licenses/ for full license
// details.
//
// Austin is a Python frame stack sampler for CPython.
//
// Copyright (c) 2018 Gabriele N. Tornetta <phoenix1987@gmail.com>.
// All rights reserved.
//
// 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 <stdint.h>

typedef unsigned long ctime_t;  /* Forward */
typedef unsigned long ustat_t;  /* non-negative statistics metric */
typedef uint64_t microseconds_t;


#include "argparse.h"


#ifndef STATS_C
extern unsigned long _sample_cnt;

extern microseconds_t _min_sampling_time;
extern microseconds_t _max_sampling_time;
extern microseconds_t _avg_sampling_time;

extern ustat_t _error_cnt;
extern ustat_t _long_cnt;

extern microseconds_t _gc_time;
#endif


/**
 * Get the current boot time in microseconds. This is intended to give
 * something that is as close as possible to wall-clock time.
 */
microseconds_t
gettime();


/**
 * Reset the statistics. Call this every time a new run is started.
 */
void
stats_reset();


/**
 * Get the maximum sampling time observed.
 */
microseconds_t
stats_get_max_sampling_time();


/**
 * Get the smallest sampling time observed.
 */
microseconds_t
stats_get_min_sampling_time();


/**
 * Get the average sampling time from the last reset up to the moment this
 * method is called.
 */
microseconds_t
stats_get_avg_sampling_time();


/**
 * Increase the sample counter.
 */
#define stats_count_sample()            { _sample_cnt++; }


/**
 * Increase the counter of samples with errors.
 */
#define stats_count_error()             { _error_cnt++; }


/**
 * Accumulate GC time.
 */
#define stats_gc_time(delta)             { _gc_time+=(delta); }


/**
 * Check the duration of the last sampling and update the statistics.
 *
 * @param microseconds_t the time it took to obtain the sample.
 * @param microseconds_t the sampling interval.
 */
#define stats_check_duration(delta) { \
  if (delta > pargs.t_sampling_interval)                 \
    _long_cnt++;                                         \
  if (_min_sampling_time > delta)                        \
    _min_sampling_time = delta;                          \
  else if (_max_sampling_time < delta)                   \
    _max_sampling_time = delta;                          \
  _avg_sampling_time += delta;                           \
}


/**
 * Log the current statistics. Usually called at the end of a sampling run.
 */
void
stats_log_metrics();


/**
 * Set the start time.
 */
void
stats_start();


/**
 * Return the current sampling duration.
 */
microseconds_t
stats_duration();

#endif