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
|
/* $%BEGINLICENSE%$
Copyright (c) 2009, 2010, Oracle and/or its affiliates. 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; version 2 of the
License.
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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
$%ENDLICENSE%$ */
#include <glib.h>
#include "chassis-timings.h"
#include "glib-ext.h"
#define MICROS_IN_SEC 1000000
chassis_timestamps_global_t *chassis_timestamps_global = NULL;
chassis_timestamp_t *chassis_timestamp_new(void) {
chassis_timestamp_t *ts;
ts = g_new0(chassis_timestamp_t, 1);
return ts;
}
void chassis_timestamp_init_now(chassis_timestamp_t *ts,
const char *name,
const char *filename,
gint line) {
ts->name = name;
ts->filename = filename;
ts->line = line;
ts->usec = my_timer_microseconds();
ts->cycles = my_timer_cycles();
ts->ticks = my_timer_ticks();
}
void chassis_timestamp_free(chassis_timestamp_t *ts) {
g_free(ts);
}
chassis_timestamps_t *chassis_timestamps_new(void) {
chassis_timestamps_t *ts;
ts = g_new0(chassis_timestamps_t, 1);
ts->timestamps = g_queue_new();
return ts;
}
void chassis_timestamps_free(chassis_timestamps_t *ts) {
chassis_timestamp_t *t;
while ((t = g_queue_pop_head(ts->timestamps))) chassis_timestamp_free(t);
g_queue_free(ts->timestamps);
g_free(ts);
}
void chassis_timestamps_add(chassis_timestamps_t *ts,
const char *name,
const char *filename,
gint line) {
chassis_timestamp_t *t;
t = chassis_timestamp_new();
chassis_timestamp_init_now(t, name, filename, line);
g_queue_push_tail(ts->timestamps, t);
}
guint64 chassis_get_rel_milliseconds() {
return my_timer_milliseconds();
}
guint64 chassis_get_rel_microseconds() {
return my_timer_microseconds();
}
guint64 chassis_calc_rel_microseconds(guint64 start, guint64 stop) {
#ifdef WIN32
guint64 frequency;
g_assert(chassis_timestamps_global != NULL);
frequency = chassis_timestamps_global->microseconds_frequency;
if (0 == frequency) {
g_critical("High resolution counter QueryPerformanceCounter not available on this system. All timer values will be meaningless.");
return stop - start;
}
return (guint64) ((stop - start) * (1.0 / frequency) * MICROS_IN_SEC);
#else
return stop - start;
#endif
}
guint64 chassis_get_rel_nanoseconds() {
return my_timer_nanoseconds();
}
void chassis_timestamps_global_init(chassis_timestamps_global_t *gl) {
chassis_timestamps_global_t *timestamps = gl;
if (NULL == gl) {
if (NULL != chassis_timestamps_global) {
g_warning("%s: invalid attempt to reinitialize the global chassis timer info, ignoring call, still using %p",
G_STRLOC, (void*)chassis_timestamps_global);
return;
} else {
chassis_timestamps_global = g_new0(chassis_timestamps_global_t, 1);
}
timestamps = chassis_timestamps_global;
g_debug("%s: created new global chassis timer info at %p", G_STRLOC, (void*)chassis_timestamps_global);
}
my_timer_init(timestamps);
}
void chassis_timestamps_global_free(chassis_timestamps_t *gl) {
if (NULL == gl) {
g_free(chassis_timestamps_global);
} else {
g_free(gl);
}
}
|