]> git.cworth.org Git - vogl/blob - src/libtelemetry/libtelemetry.h
Initial vogl checkin
[vogl] / src / libtelemetry / libtelemetry.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 /*
27  * libtelemetry.h
28  */
29 #ifndef _LIBTELEMETRY_H
30 #define _LIBTELEMETRY_H
31
32 #if defined( USE_TELEMETRY )
33
34 /* 
35  * USE_TELEMETRY
36  */
37 #include "../telemetry/include/telemetry.h"
38
39 #define SO_API_EXPORT extern "C" __attribute__((visibility ("default")))
40 #define SO_GLOBAL_EXPORT extern "C" __attribute__((visibility ("default")))
41
42 typedef struct telemetry_info_t
43 {
44     HTELEMETRY ctx[8];
45 } telemetry_ctx_t;
46 SO_GLOBAL_EXPORT telemetry_info_t g_tminfo;
47 // Don't reference g_tminfo directly - use get_tminfo(). This works around
48 //  a bug where the application and so each had separate copies of g_tminfo
49 //  for some reason.
50 // http://netwinder.osuosl.org/users/p/patb/public_html/elf_relocs.html (see R_386_COPY here)
51 // http://www.technovelty.org/c/what-exactly-does-bsymblic-do.html (what does -Bsymbolic do)
52 // http://stackoverflow.com/questions/8623657/multiple-instances-of-singleton-across-shared-libraries-on-linux
53 // readelf --relocs and readelf --dynamic will help debug this.
54 // also LD_DEBUG=bindings
55 inline telemetry_info_t& get_tminfo() { return g_tminfo; }
56
57 #define TELEMETRY_LEVEL_MIN 0
58 #define TELEMETRY_LEVEL_MAX 3
59 #define TELEMETRY_LEVEL0 get_tminfo().ctx[0]
60 #define TELEMETRY_LEVEL1 get_tminfo().ctx[1]
61 #define TELEMETRY_LEVEL2 get_tminfo().ctx[2]
62 #define TELEMETRY_LEVEL3 get_tminfo().ctx[3]
63
64 SO_API_EXPORT void telemetry_tick();
65
66 SO_API_EXPORT void telemetry_set_servername(const char *servername);
67 SO_API_EXPORT const char *telemetry_get_servername();
68
69 SO_API_EXPORT void telemetry_set_appname(const char *appname);
70 SO_API_EXPORT const char *telemetry_get_appname();
71
72 SO_API_EXPORT void telemetry_set_level(int level);
73 SO_API_EXPORT int telemetry_get_level();
74
75 #else
76
77 /* 
78  * !USE_TELEMETRY
79  */
80 #define NTELEMETRY 1
81
82 #define TELEMETRY_LEVEL_MIN 0
83 #define TELEMETRY_LEVEL_MAX 3
84 #define TELEMETRY_LEVEL0 NULL
85 #define TELEMETRY_LEVEL1 NULL
86 #define TELEMETRY_LEVEL2 NULL
87 #define TELEMETRY_LEVEL3 NULL
88
89 #define telemetry_tick()
90
91 #define telemetry_set_servername(_servername)
92 #define telemetry_get_servername() ""
93
94 #define telemetry_set_appname(_appname)
95 #define telemetry_get_appname() ""
96
97 #define telemetry_set_level(_level)
98 #define telemetry_get_level() -1
99
100 #define TMERR_DISABLED 1
101 #define TMPRINTF_TOKEN_NONE 0
102
103 #define tmGetSessionName(...)
104 #define tmEndTryLock(...)
105 #define tmEndTryLockEx(...)
106 #define tmSetLockState(...)
107 #define tmSetLockStateEx(...)
108 #define tmSetLockStateMinTime(...) 0
109 #define tmSetLockStateMinTimeEx(...) 0
110 #define tmSignalLockCount(...)
111
112 #define tmCheckVersion(...) 0
113 #define tmGetCallStack(...) 0
114 #define tmSendCallStack( ... ) TMPRINTF_TOKEN_NONE
115 #define tmGetCallStackR(...) 0
116 #define tmSendCallStackR(...) TMPRINTF_TOKEN_NONE
117 #define tmSendCallStackWithSkipR(...) TMPRINTF_TOKEN_NONE
118
119 #define tmGetVersion(...) 0
120 #define tmStartup(...)  TMERR_DISABLED
121 #define tmGetPlatformInformation(...) TMERR_DISABLED
122 #define tmInitializeContext(...) TMERR_DISABLED
123 #define tmShutdown(...) TMERR_DISABLED
124
125 #define tmEnter(...)
126 #define tmEnterEx(...)
127 #define tmZone(...) 
128 #define tmZoneFiltered(...)
129 #define tmLeaveEx(...)
130
131 #define tmBeginTimeSpan(...)
132 #define tmEndTimeSpan(...)
133
134 #define tmEmitAccumulationZone(...)
135
136 #define tmGetStati(...) 0
137
138 #define tmSetVariable(...)
139
140 #define tmBlob(...)
141 #define tmDisjointBlob(...)
142 #define tmSetTimelineSectionName(...)
143 #define tmThreadName(...)
144 #define tmLockName(...)
145 #define tmMessage(...)
146 #define tmAlloc(...)
147 #define tmAllocEx(...)
148
149 #define tmTryLock(...)
150 #define tmTryLockEx(...)
151     
152 #define tmPlot(...)
153 #define tmPlotF32(...)
154 #define tmPlotF64(...)
155 #define tmPlotI32(...)
156 #define tmPlotU32(...)
157 #define tmPlotS32(...)
158 #define tmPlotI64(...)
159 #define tmPlotU64(...)
160 #define tmPlotS64(...)
161
162 #define tmPPUGetListener(...) TMERR_DISABLED
163 #define tmPPURegisterSPUProgram(...) TMERR_DISABLED
164 #define tmSPUBindContextToListener(...) 
165 #define tmSPUUpdateTime(...)
166 #define tmSPUFlushImage(...)
167
168 #define TM_CONTEXT_LITE(val) ((char*)(val))
169 #define TM_CONTEXT_FULL(val) ((char*)(val))
170
171 typedef char *HTELEMETRY;
172
173 #endif // !USE_TELEMETRY
174
175 #endif // _LIBTELEMETRY_H