2
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; version 2 of the
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23
#include "chassis-timings.h"
26
#define MICROS_IN_SEC 1000000
28
chassis_timestamps_global_t *chassis_timestamps_global = NULL;
30
chassis_timestamp_t *chassis_timestamp_new(void) {
31
chassis_timestamp_t *ts;
33
ts = g_new0(chassis_timestamp_t, 1);
38
void chassis_timestamp_init_now(chassis_timestamp_t *ts,
44
ts->filename = filename;
46
ts->usec = my_timer_microseconds();
47
ts->cycles = my_timer_cycles();
48
ts->ticks = my_timer_ticks();
51
void chassis_timestamp_free(chassis_timestamp_t *ts) {
55
chassis_timestamps_t *chassis_timestamps_new(void) {
56
chassis_timestamps_t *ts;
58
ts = g_new0(chassis_timestamps_t, 1);
59
ts->timestamps = g_queue_new();
64
void chassis_timestamps_free(chassis_timestamps_t *ts) {
65
chassis_timestamp_t *t;
67
while ((t = g_queue_pop_head(ts->timestamps))) chassis_timestamp_free(t);
68
g_queue_free(ts->timestamps);
72
void chassis_timestamps_add(chassis_timestamps_t *ts,
76
chassis_timestamp_t *t;
78
t = chassis_timestamp_new();
79
chassis_timestamp_init_now(t, name, filename, line);
81
g_queue_push_tail(ts->timestamps, t);
84
guint64 chassis_get_rel_milliseconds() {
85
return my_timer_milliseconds();
88
guint64 chassis_get_rel_microseconds() {
89
return my_timer_microseconds();
92
guint64 chassis_calc_rel_microseconds(guint64 start, guint64 stop) {
95
g_assert(chassis_timestamps_global != NULL);
96
frequency = chassis_timestamps_global->microseconds_frequency;
98
g_critical("High resolution counter QueryPerformanceCounter not available on this system. All timer values will be meaningless.");
101
return (guint64) ((stop - start) * (1.0 / frequency) * MICROS_IN_SEC);
107
guint64 chassis_get_rel_nanoseconds() {
108
return my_timer_nanoseconds();
112
void chassis_timestamps_global_init(chassis_timestamps_global_t *gl) {
113
chassis_timestamps_global_t *timestamps = gl;
116
if (NULL != chassis_timestamps_global) {
117
g_warning("%s: invalid attempt to reinitialize the global chassis timer info, ignoring call, still using %p",
118
G_STRLOC, (void*)chassis_timestamps_global);
121
chassis_timestamps_global = g_new0(chassis_timestamps_global_t, 1);
123
timestamps = chassis_timestamps_global;
124
g_debug("%s: created new global chassis timer info at %p", G_STRLOC, (void*)chassis_timestamps_global);
126
my_timer_init(timestamps);
129
void chassis_timestamps_global_free(chassis_timestamps_t *gl) {
131
g_free(chassis_timestamps_global);