~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to src/chassis-timings.c

  • Committer: Kay Roepke
  • Date: 2009-06-03 12:51:29 UTC
  • mto: This revision was merged to the branch mainline in revision 639.
  • Revision ID: kay@sun.com-20090603125129-26oso9ov7yinwocg
add autoconf/aclocal files we should never commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
3
 
 
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
7
 
 License.
8
 
 
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.
13
 
 
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
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ */
20
 
 
21
 
#include <glib.h>
22
 
 
23
 
#include "chassis-timings.h"
24
 
#include "glib-ext.h"
25
 
 
26
 
#define MICROS_IN_SEC 1000000
27
 
 
28
 
chassis_timestamps_global_t *chassis_timestamps_global = NULL;
29
 
 
30
 
chassis_timestamp_t *chassis_timestamp_new(void) {
31
 
        chassis_timestamp_t *ts;
32
 
 
33
 
        ts = g_new0(chassis_timestamp_t, 1);
34
 
 
35
 
        return ts;
36
 
}
37
 
 
38
 
void chassis_timestamp_init_now(chassis_timestamp_t *ts,
39
 
                const char *name,
40
 
                const char *filename,
41
 
                gint line) {
42
 
 
43
 
        ts->name = name;
44
 
        ts->filename = filename;
45
 
        ts->line = line;
46
 
        ts->usec = my_timer_microseconds();
47
 
        ts->cycles = my_timer_cycles();
48
 
        ts->ticks = my_timer_ticks();
49
 
}
50
 
 
51
 
void chassis_timestamp_free(chassis_timestamp_t *ts) {
52
 
        g_free(ts);
53
 
}
54
 
 
55
 
chassis_timestamps_t *chassis_timestamps_new(void) {
56
 
        chassis_timestamps_t *ts;
57
 
 
58
 
        ts = g_new0(chassis_timestamps_t, 1);
59
 
        ts->timestamps = g_queue_new();
60
 
 
61
 
        return ts;
62
 
}
63
 
 
64
 
void chassis_timestamps_free(chassis_timestamps_t *ts) {
65
 
        chassis_timestamp_t *t;
66
 
 
67
 
        while ((t = g_queue_pop_head(ts->timestamps))) chassis_timestamp_free(t);
68
 
        g_queue_free(ts->timestamps);
69
 
        g_free(ts);
70
 
}
71
 
 
72
 
void chassis_timestamps_add(chassis_timestamps_t *ts,
73
 
                const char *name,
74
 
                const char *filename,
75
 
                gint line) {
76
 
        chassis_timestamp_t *t;
77
 
 
78
 
        t = chassis_timestamp_new();
79
 
        chassis_timestamp_init_now(t, name, filename, line);
80
 
 
81
 
        g_queue_push_tail(ts->timestamps, t);
82
 
}
83
 
 
84
 
guint64 chassis_get_rel_milliseconds() {
85
 
        return my_timer_milliseconds();
86
 
}
87
 
 
88
 
guint64 chassis_get_rel_microseconds() {
89
 
        return my_timer_microseconds();
90
 
}
91
 
 
92
 
guint64 chassis_calc_rel_microseconds(guint64 start, guint64 stop) {
93
 
#ifdef WIN32
94
 
        guint64 frequency;
95
 
        g_assert(chassis_timestamps_global != NULL);
96
 
        frequency = chassis_timestamps_global->microseconds_frequency;
97
 
        if (0 == frequency) {
98
 
                g_critical("High resolution counter QueryPerformanceCounter not available on this system. All timer values will be meaningless.");
99
 
                return stop - start;
100
 
        }
101
 
        return (guint64) ((stop - start) * (1.0 / frequency) * MICROS_IN_SEC);
102
 
#else
103
 
        return stop - start;
104
 
#endif
105
 
}
106
 
 
107
 
guint64 chassis_get_rel_nanoseconds() {
108
 
        return my_timer_nanoseconds();
109
 
}
110
 
 
111
 
 
112
 
void chassis_timestamps_global_init(chassis_timestamps_global_t *gl) {
113
 
        chassis_timestamps_global_t *timestamps = gl;
114
 
 
115
 
        if (NULL == 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);
119
 
                        return;
120
 
                } else {
121
 
                        chassis_timestamps_global = g_new0(chassis_timestamps_global_t, 1);
122
 
                }
123
 
                timestamps = chassis_timestamps_global;
124
 
                g_debug("%s: created new global chassis timer info at %p", G_STRLOC, (void*)chassis_timestamps_global);
125
 
        }
126
 
        my_timer_init(timestamps);
127
 
}
128
 
 
129
 
void chassis_timestamps_global_free(chassis_timestamps_t *gl) {
130
 
        if (NULL == gl) {
131
 
                g_free(chassis_timestamps_global);
132
 
        } else {
133
 
                g_free(gl);
134
 
        }
135
 
}