Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1317 lines
57 KiB

  1. #ifndef TELEMETRY_H
  2. #define TELEMETRY_H
  3. //-------------------------------------------------------------------
  4. // Documentation stuff
  5. //-------------------------------------------------------------------
  6. #ifndef EXPAPI
  7. #define EXPAPI
  8. #endif
  9. #ifndef EXPMACRO
  10. #define EXPMACRO
  11. #endif
  12. #ifndef EXPCONST
  13. #define EXPCONST
  14. #endif
  15. #ifndef EXPOUT
  16. #define EXPOUT
  17. #endif
  18. #ifndef EXPGROUP
  19. #define EXPGROUP(GroupName)
  20. #endif
  21. #ifndef EXPTYPEBEGIN
  22. #define EXPTYPEBEGIN
  23. #endif
  24. #ifndef EXPTYPEEND
  25. #define EXPTYPEEND
  26. #endif
  27. #ifndef EXPTYPE
  28. #define EXPTYPE
  29. #endif
  30. EXPGROUP(_NullGroup)
  31. #define TelemetryRunTimeVersion "2.0P" EXPMACRO
  32. #define LTelemetryRunTimeVersion L"2.0P" EXPMACRO
  33. #define Telemetry2Version "2.0P" EXPMACRO
  34. #define LTelemetry2Version L"2.0P" EXPMACRO
  35. #define TelemetryMajorVersion 2 EXPMACRO
  36. #define TelemetryMinorVersion 0 EXPMACRO
  37. #define TelemetryBuildNumber 56 EXPMACRO
  38. #define TelemetryCustomization 0 EXPMACRO
  39. #ifndef TelemetryToolsVersion
  40. #define TelemetryToolsVersion TelemetryRunTimeVersion
  41. #define LTelemetryToolsVersion LTelemetryRunTimeVersion
  42. #endif
  43. #define TelemetrySalesEMailAddress "[email protected]" EXPMACRO
  44. #define TelemetrySalesPhoneNumber "425-893-4300" EXPMACRO
  45. #define TelemetryCompanyName "RAD Game Tools, Inc." EXPMACRO
  46. #define TelemetryCopyright "Copyright (C) 2009-2014, RAD Game Tools, Inc." EXPMACRO
  47. #define TelemetryTrademarks "Telemetry is a registered trademark of RAD Game Tools" EXPMACRO
  48. #define TelemetrySupportAddress "[email protected]" EXPMACRO
  49. #define TelemetrySupportPage "www.radgametools.com/telemetry.htm" EXPMACRO
  50. #define TelemetryCompanyPage "http://www.radgametools.com" EXPMACRO
  51. #define TelemetryOnLineChangelogAddress "www.radgametools.com/telemetry/changelog.htm" EXPMACRO
  52. #ifndef __RADRES__
  53. EXPGROUP(TMAPI)
  54. //-------------------------------------------------------------------
  55. // Important manifest constants:
  56. //
  57. // --- The following should _not_ be set by the end user! ---
  58. //
  59. // TM_INLINE_FASTTIME - DO NOT CHANGE THIS!!
  60. // TM_DLL - is set to 1 if building the library as a DLL
  61. // TM_API_STATIC - functions are statically linked directly and not going through a function pointer table
  62. // TM_BUILD_LIB - should be set to 1 when building the library
  63. // TM_HARDLINK - we're statically linking (not using a DLL)
  64. //
  65. // TM_IPC_CLIENT - set to 1 if building the library as an IPC client
  66. // * assumes communication is NOT over a network
  67. // * assumes single threading
  68. // TM_IPC_HOST - set to 1 if building the library as an IPC server
  69. // * assumes subprocesses use IPC for communication
  70. // * IPC mechanism not assumed
  71. //
  72. // --- The following can be set by the enduser ---
  73. //
  74. // NTELEMETRY - set to 1 if you want to compile away the library
  75. //
  76. //-------------------------------------------------------------------
  77. #define TM_INLINE_FASTTIME 1
  78. #define TM_MAX_OBJECT_PATH 64 EXPMACRO // Maximum length of a path string
  79. #define TM2_MAX_OBJECT_PATH (1024*8) EXPMACRO // Maximum length of a path string
  80. #define TM_MAX_STRING (1024*8) EXPMACRO // Maximum length of a string that you can pass to Telemetry.
  81. #define TM_MAX_EXTRA_DATA 256 EXPMACRO // Maximum amount of variable length string data
  82. #define TM_MAX_EVENT_FILENAME 320 EXPMACRO // Longest length for a filename used with a Telemetry event
  83. #define TM_VA_LIST ((char const *)1) EXPMACRO // Specifies that a va_list is being passed to the function. See $ug_valist for more information.
  84. #define TM_LOCK_MIN_TIME_BUFSIZE 512 EXPMACRO // Size of buffer necessary for tmSetLockStateMinTime
  85. #ifndef TM_CAT
  86. #define TM_CAT( s1, s2 ) s1##s2
  87. #endif
  88. #ifndef TM_FUNCTION_TYPE
  89. #define TM_FUNCTION_TYPE(name) TM_CAT(name,type)
  90. #endif
  91. //-----------------------------------------------------------------------------
  92. // Base types
  93. //-----------------------------------------------------------------------------
  94. #if defined __RADARM__ || defined __RADWIIU__
  95. #define TM_SLOW 1 EXPMACRO // If defined then reading timestamps is slow on this platforms, so adjust your markup accordingly
  96. #endif
  97. #ifdef TM_DLL
  98. #ifndef __RADINDLL__
  99. #define __RADINDLL__
  100. #endif
  101. #endif
  102. // NOTE: Need to include this before the __RADNT__ check
  103. //#ifndef NTELEMETRY
  104. #include "tmtypes.h"
  105. //#endif
  106. #if !defined __RADQNX__ && !defined __RADSPU__ && !defined __RADNT__ && !defined __RADXENON__ && !defined __RADANDROID__ && !defined __RADSEKRIT__ && !defined __RADPS4__ && !defined __RADPS3__ && !defined __RADIPHONE__ && !defined __RADWIIU__ && !defined __RADLINUX__ && !(defined __RADMAC__ && !defined __RADPPC__) && !defined __RADPSP2__ && !defined NTELEMETRY
  107. #define NTELEMETRY 1
  108. #endif
  109. #if defined __RADSPU__ && !defined TM_IPC_CLIENT
  110. #define TM_IPC_CLIENT 1
  111. #endif
  112. #if defined __RADPS3__ && !defined TM_IPC_HOST
  113. #define TM_IPC_HOST 1
  114. #endif
  115. #if defined __RADSPU__ || defined __RADPS3__
  116. #define TM_SPU_CONTEXT_SIZE (2*1024) EXPMACRO // Required size for a Telemetry context on the SPU
  117. #endif
  118. #ifdef TM_IPC_CLIENT
  119. #define TM_SINGLE_THREADED 1
  120. #endif
  121. #if defined __RADXENON__ || defined __RADSEKRIT__ || defined __RADPS4__ || defined __RADIPHONE__ || defined __RADANDROID__ || defined __RADPS3__ || defined __RADWIIU__ || defined __RADPSP2__ || defined __RADQNX__
  122. #define TM_HARDLINK 1
  123. #endif
  124. #if !defined RADEXPLINK && !defined NTELEMETRY
  125. #define RADEXPLINK
  126. #endif
  127. #ifndef RADDEFSTART
  128. #define RADDEFEND }
  129. #define RADDEFSTART extern "C" {
  130. #endif
  131. #if defined __RADSPU__
  132. #define TM_API_STATIC 1
  133. #endif
  134. #ifndef TM_API
  135. #ifdef TM_API_STATIC
  136. #define TM_API( ret, name, params ) ret RADEXPLINK name params
  137. #else
  138. #define TM_API( ret, name, params ) typedef ret (RADEXPLINK *TM_FUNCTION_TYPE(name))params
  139. #endif
  140. #endif
  141. #ifndef TMCHECKCONTEXT
  142. #ifdef TM_API_STATIC
  143. #define TMCHECKCONTEXTR(c,n,f,z) ( (c) ? ( n f ) : (z) )
  144. #define TMCHECKCONTEXTV(c,n,f) { if (c) { n f ; } }
  145. #else
  146. #define TMCHECKCONTEXTR(c,n,f,z) ( (c) ? ( ((TM_API_STRUCT*)(c))->n f) : (z) )
  147. #define TMCHECKCONTEXTV(c,n,f) { if (c) { ( ((TM_API_STRUCT*)(c))->n f); } }
  148. #endif
  149. #define TMCHECKCONTEXT_VA(c,n,f) { static TmFormatCode tm_fmt; TMCHECKCONTEXTV(c,n,f); }
  150. #define TMCHECKCONTEXT(c,n,f) TMCHECKCONTEXTR(c,n,f,TMERR_INVALID_CONTEXT)
  151. #endif
  152. //-----------------------------------------------------------------------------
  153. // Call stack
  154. //-----------------------------------------------------------------------------
  155. #define TM_MAX_CALLSTACK_DEPTH 32 //This value cannot change without affecting the server protocol!!
  156. EXPTYPE typedef struct _TmCallStack
  157. {
  158. int cs_depth;
  159. void *cs_stack[ TM_MAX_CALLSTACK_DEPTH ];
  160. } TmCallStack;
  161. //-----------------------------------------------------------------------------
  162. // Error codes
  163. //-----------------------------------------------------------------------------
  164. EXPTYPE typedef enum TmErrorCode
  165. {
  166. TM_OK = 0x0000, // Everything is okay
  167. TMERR_DISABLED = 0x0001, // Telemetry has been compiled away with $NTELEMETRY
  168. TMERR_INVALID_CONTEXT = 0x0002, // The context passed to Telemetry was invalid
  169. TMERR_INVALID_PARAM = 0x0003, // Out of range, null pointer, etc.
  170. TMERR_OUT_OF_RESOURCES = 0x0004, // Typically out of available memory, string space, etc.
  171. TMERR_UNINITIALIZED = 0x0006, // A Telemetry API was called before $tmStartup
  172. TMERR_BAD_HOSTNAME = 0x0007, // Could not resolve hostname
  173. TMERR_COULD_NOT_CONNECT = 0x0008, // Could not connect to the server
  174. TMERR_UNKNOWN_NETWORK = 0x0009, // Unknown error in the networking system
  175. TMERR_ALREADY_SHUTDOWN = 0x000A, // $tmShutdown called more than once
  176. TMERR_ARENA_TOO_SMALL = 0x000B, // buffer passed to $tmInitializeContext was too small
  177. TMERR_BAD_HANDSHAKE = 0x000C, // handshake with server failed (protocol error)
  178. TMERR_UNALIGNED = 0x000D, // One more more parameters were not aligned correctly
  179. TMERR_NETWORK_NOT_INITIALIZED = 0x000E, // Network startup functions were not called, e.g. WSAStartup
  180. TMERR_BAD_VERSION = 0x000F, // You're using an out of date version of the Telemetry libraries
  181. TMERR_BAD_TIMER = 0x00A0, // The provided user timer is too coarse for Telemetry
  182. TMERR_UNKNOWN = 0xFFFF // Unknown error occurred
  183. } TmErrorCode;
  184. /*
  185. Standard errors returned by Telemetry.
  186. Standard errors returned by Telemetry. Most Telemetry functions return void, so the
  187. standard Telemetry method for checking errors is to call $tmGetLastError. In some cases, e.g.
  188. when a context is unavailable or unnecessary, a Telemetry API may return an error code directly.
  189. $-
  190. See also $ug_errors
  191. */
  192. //-----------------------------------------------------------------------------
  193. // Printf-style tokens, reserved for Telemetry internal use only
  194. //-----------------------------------------------------------------------------
  195. typedef enum TmPrintfToken
  196. {
  197. TMPRINTF_TOKEN_NONE = 0,
  198. TMPRINTF_TOKEN_CALLSTACK = 1
  199. } TmPrintfToken;
  200. //-----------------------------------------------------------------------------
  201. // Connection status
  202. //-----------------------------------------------------------------------------
  203. EXPTYPE typedef enum TmConnectionStatus
  204. {
  205. TMCS_DISCONNECTED = 0, //Not connected to a server
  206. TMCS_CONNECTING = 1, //Attempting a connection to a server
  207. TMCS_CONNECTED = 2 //Connected to a server
  208. } TmConnectionStatus;
  209. /*
  210. Connection status returned by $tmGetConnectionStatus.
  211. */
  212. #ifndef NTELEMETRY
  213. //-----------------------------------------------------------------------------
  214. // Zone flags
  215. //-----------------------------------------------------------------------------
  216. EXPTYPE typedef enum TmZoneFlag
  217. {
  218. TMZF_NONE = 0x0000, // Zone is normal.
  219. TMZF_STALL = 0x0001, // Zone is stalling while waiting on a lock, etc. Implies thread is busy but can't progress.
  220. TMZF_IDLE = 0x0002, // Zone is sleeping/idle until something new happens. Implies thread is idle.
  221. TMZF_PROFILER_ONLY = 0x0004, // Telemetry 1 only: Only show this zone in the profiler view, not in the zone view
  222. TMZF_MEM_REGION_EXPERIMENTAL = 0x0010, // Only show this zone in the profiler view, not in the zone view
  223. TMZF_PLOT_TIME = 0x0100, // Generate plot of the zone's duration on the server
  224. TMZF_PLOT_TIME_EXPERIMENTAL = TMZF_PLOT_TIME, // Retained for backward compatibility
  225. // Everything from here on out is for Telemetry internal use only, do not use!!!!!
  226. TMZF_INTERNAL_ACCUMULATOR = 0x10000, //For Telemetry internal use only
  227. TMZF_INTERNAL_LOCK_STALL = 0x20000, //For Telemetry internal use only
  228. TMZF_INTERNAL_OPEN_ENDED = 0x40000, //For Telemetry internal use only
  229. TMZF_INTERNAL_CONTINUATION = 0x80000, //For Telemetry internal use only
  230. TMZF_INTERNAL_DISCARD = 0x100000, //For Telemetry internal use only; this constant is used by the run-time and server for different things
  231. TMZF_INTERNAL_DISCARD_SERVER = 0x100000, //For Telemetry internal use only; this constant is shared but used differently by run time and server
  232. TMZF_INTERNAL_NO_INSERT_SERVER = 0x200000, //For Telemetry internal use only (server only)
  233. TMZF_INTERNAL_LOD_ZONE = 0x400000, //For Telemetry internal use only (server only)
  234. // Not really flags...
  235. TMZF_INTERNAL_LOCK_FAILED = 0x10000000, //For Telemetry internal use only
  236. TMZF_INTERNAL_LOCK_SUCCESS = 0x20000000, //For Telemetry internal use only
  237. TMZF_INTERNAL_LOCK_TIMEOUT = 0x30000000, //For Telemetry internal use only
  238. } TmZoneFlag;
  239. /*
  240. Bitmasks that can be ORed together when calling tmZone, tmCoreEnter, tmCoreLeave, tmEnter or tmLeave.
  241. */
  242. #define TMZF_INTERNAL_ANY_MASK ( TMZF_INTERNAL_ACCUMULATOR | TMZF_INTERNAL_LOCK_STALL | TMZF_INTERNAL_OPEN_ENDED | TMZF_INTERNAL_CONTINUATION | TMZF_INTERNAL_LOCK_FAILED | TMZF_INTERNAL_LOCK_TIMEOUT )
  243. //-----------------------------------------------------------------------------
  244. // Timespan flags
  245. //-----------------------------------------------------------------------------
  246. EXPTYPE typedef enum TmTimeSpanFlag
  247. {
  248. TMTSF_NONE = 0x0000, // Timespan is normal.
  249. } TmTimeSpanFlags;
  250. /*
  251. Bitmasks that can be ORed together when calling tmBeginTimeSpan and tmEndTimeSpan
  252. */
  253. //-----------------------------------------------------------------------------
  254. // Plot type
  255. //-----------------------------------------------------------------------------
  256. EXPTYPE typedef enum TmPlotType
  257. {
  258. TMPT_NONE = 0, // Display as raw float data
  259. TMPT_MEMORY = 1, // Display as contextually relevant memory, i.e. bytes, kb, MB, GB, TB, etc.
  260. TMPT_HEX = 2, // Display as hex value based on range
  261. TMPT_INTEGER = 3, // Display as integer, no decimal points
  262. TMPT_UNTYPED = 3, // Data is untyped and should be displayed as an integer (this is the same as TMPT_INTEGER)
  263. TMPT_PERCENTAGE_COMPUTED = 4, // Display as a percentage of the max, i.e. as (value-min)/(max-min), computed by the client
  264. TMPT_PERCENTAGE_DIRECT = 5, // Display as a percentage (i.e. 0.2187 => 21.87%). For I32/U32 it expects 0..100
  265. TMPT_TIME = 6, // Display in timecode format, i.e. hh:mm:dd:ss.xxx
  266. TMPT_TIME_MS = 7, // Floating point milliseconds
  267. TMPT_TIME_US = 8, // Floating point microseconds
  268. TMPT_TIME_CLOCKS = 9, // I64 clock cycles
  269. TMPT_TIME_INTERVAL = 10, // This plot's value should be the delta between this time and the last call to tmPlot for this plot
  270. TMPT_USER = 128, // Reserved for user types
  271. TMPT_MAX = 255
  272. } TmPlotType;
  273. /*
  274. Passed to $(tmPlot) to specify how the Visualizer should present the data.
  275. */
  276. //-----------------------------------------------------------------------------
  277. // Plot flags
  278. //-----------------------------------------------------------------------------
  279. EXPTYPE typedef enum TmPlotFlag
  280. {
  281. TMPF_NONE = 0x0000, // No additional flags
  282. TMPF_MINVAL_ZERO = 0x0001, // Set plot's minval to 0 instead of actual minval
  283. TMPF_FRAMETIME = 0x0002, // This plot is being used to measure frame times
  284. TMPF_INTERNAL_SYNTHETIC = 0x10000 // Internal use only!
  285. } TmPlotFlag;
  286. /*
  287. Passed to $(tmPlot) to specify how the Visualizer should present the data. These are available in Telemetry 2 only!
  288. */
  289. #endif // NTELEMETRY
  290. EXPTYPE typedef struct TmContext* HTELEMETRY;
  291. /*
  292. Opaque handle to a Telemetry context.
  293. Telemetry binds the majority of its state to a context. This context is allocated and
  294. passed in by the application, and must be available and valid through the life of the
  295. Telemetry session. The context is initialized with $tmInitializeContext and shut down
  296. with $tmShutdownContext.
  297. An application can have multiple contexts, but each context will open a separate
  298. connection to the server and create its own individual session. This should rarely
  299. be required, but in some instances is unavoidable, for example you are writing a
  300. middleware component and need to be able to instrument your code without necessarily
  301. having access to the code base in which you're embedded (which, in turn, may have its
  302. own Telemetry context).
  303. */
  304. RADDEFSTART
  305. //-----------------------------------------------------------------------------
  306. // Message flags
  307. //-----------------------------------------------------------------------------
  308. #ifndef NTELEMETRY
  309. EXPTYPE typedef enum TmMessageFlag
  310. {
  311. TMMF_SEVERITY_LOG = 0x0001, // Regular log message
  312. TMMF_SEVERITY_WARNING = 0x0002, // Warning
  313. TMMF_SEVERITY_ERROR = 0x0004, // Error
  314. TMMF_SEVERITY_RESERVED = 0x0008, // For future expansion
  315. TMMF_SEVERITY_MASK = 0xF, // Low 3-bits determine the message type
  316. TMMF_ZONE_LABEL = 0x0010, // Replace zone label with this text
  317. TMMF_ZONE_SUBLABEL = 0x0020, // Print secondary zone label with text
  318. TMMF_ZONE_SHOW_IN_PARENTS = 0x0040, // Show this not only in the zone's tooltip, but also in the tooltips of any parents
  319. TMMF_ZONE_RESERVED01 = 0x0080,
  320. TMMF_ZONE_MASK = 0x00F0,
  321. // We have up to 15 icon types
  322. TMMF_ICON_EXCLAMATION = 0x1000, // Show exclamation marker in the zone view for this message
  323. TMMF_ICON_NOTE = 0x2000, // Show note marker in the zone view for this message
  324. TMMF_ICON_WTF = 0x3000, // Show "question mark/WTF?" marker in the zone view for this message
  325. TMMF_ICON_QUESTION_MARK = TMMF_ICON_WTF,
  326. TMMF_ICON_EXTRA00 = 0x4000, // These are placeholders for now until we get some nicer icons
  327. TMMF_ICON_EXTRA01 = 0x5000, //
  328. TMMF_ICON_EXTRA02 = 0x6000, //
  329. TMMF_ICON_EXTRA03 = 0x7000, //
  330. TMMF_ICON_EXTRA04 = 0x8000, //
  331. TMMF_ICON_MASK = 0xF000,
  332. // Special message tags
  333. TMMF_UNUSED00 = 0x10000,
  334. TMMF_UNUSED01 = 0x20000, // Used by tmSetTimelineSectionName
  335. // Internal use only
  336. // We can expand these later and make them either incremental like icons or do
  337. // an expansion mask and overflow into another variable...
  338. TMMF_INTERNAL_PLOT = 0x10000000,
  339. TMMF_INTERNAL_MEMORY = 0x20000000,
  340. TMMF_INTERNAL_TIMESPAN = 0x30000000,
  341. TMMF_INTERNAL_LOCK = 0x40000000,
  342. TMMF_INTERNAL_ANY_MASK = 0x70000000
  343. } TmMessageFlag;
  344. /*
  345. Passed to $tmMessage to determine how to present the message to the end user.
  346. */
  347. //-----------------------------------------------------------------------------
  348. // Open flags
  349. //-----------------------------------------------------------------------------
  350. EXPTYPE typedef enum TmOpenFlag
  351. {
  352. TMOF_INIT_NETWORKING = 0x0001, // Initialize operating system networking layer. Specify this if you do not already call the platform specific network startup functions (e.g. WSAStartup) prior to $tmOpen.
  353. TMOF_DONT_KILL_OTHER_SESSIONS = 0x0002, // If set the server should NOT kill any other sessions from this machine with the same app name.
  354. // This is an enumeration
  355. TMOF_DISABLE_CONTEXT_SWITCHES = 0x0000, // Disable context switch event tracking entirely. None are sent to server. See $ug_cswitches_overview for more information.
  356. TMOF_MODERATE_CONTEXT_SWITCHES = 0x0010, // Send relevant context switches only (e.g. on PS4 it will not send context switches for the two system cores). See $ug_cswitches_overview for more information.
  357. TMOF_MINIMAL_CONTEXT_SWITCHES = 0x0020, // Currently the same as "moderate" context switches.
  358. TMOF_MAXIMUM_CONTEXT_SWITCHES = 0x0030, // Send all context switches. See $ug_cswitches_overview for more information.
  359. TMOF_CONTEXT_SWITCH_MASK = 0x0030,
  360. TMOF_NO_PDB_LOOKUP = 0x0040, // If specified then don't search all loaded DLLs for PDB signatures
  361. } TmOpenFlag;
  362. /*
  363. Passed to $tmOpen.
  364. */
  365. #ifdef __RADXENON__
  366. #define TMOF_DEFAULT TMOF_MODERATE_CONTEXT_SWITCHES // Default open flags
  367. #else
  368. #define TMOF_DEFAULT 0 // Default open flags
  369. #endif
  370. /*
  371. Flags passed to $tmOpen
  372. */
  373. #define TELEMETRY_DEFAULT_PORT 0 EXPMACRO //Constant used to specify the default Telemetry port when calling $tmOpen
  374. //-----------------------------------------------------------------------------
  375. // Connection type
  376. //-----------------------------------------------------------------------------
  377. EXPTYPE typedef enum TmConnectionType
  378. {
  379. TMCT_TCP, // Connect to Telemetry server over TCP/IP
  380. TMCT_IPC, // Use an IPC connection (not supported on all platforms)
  381. TMCT_FILE, // Store all data to local disk (not supported on all platforms)
  382. TMCT_USER_PROVIDED, // Use the user defined callbacks for all file i/o
  383. } TmConnectionType;
  384. /*
  385. Determines how the application will connect to the Telemetry server.
  386. Specified in $tmOpen. In the future we may support additional communication methods such
  387. as interprocess communication, USB connections, shared files, etc.
  388. $-
  389. For more information on recording-to-disk (instead of recording over a network) see $localfiles.
  390. $-
  391. */
  392. //-----------------------------------------------------------------------------
  393. // Telemetry options
  394. //-----------------------------------------------------------------------------
  395. EXPTYPE typedef enum TmOption
  396. {
  397. TMO_OUTPUT_DEBUG_INFO = 0x0001, // Print debug output to the debugger window if possible
  398. TMO_RECORD_TELEMETRY_STALLS = 0x0002, // Record stalls within Telemetry itself
  399. TMO_RECORD_CALLSTACKS = 0x0004, // Record callstacks if requested
  400. TMO_BOOST_PRIORITY = 0x0008, // Temporarily boost priority for Telemetry events to help with priority inversion issues
  401. TMO_SUPPORT_ZONES = 0x0100, // Send zones
  402. TMO_SUPPORT_MESSAGES = 0x0200, // Send messages
  403. TMO_SUPPORT_LOCK_STATES = 0x0400, // Send lock states
  404. TMO_SUPPORT_MEMORY = 0x0800, // Send memory events
  405. TMO_SUPPORT_PLOT = 0x1000, // Send plots
  406. TMO_SUPPORT_BLOB = 0x2000, // Send user blobs
  407. TMO_PPU_SYNCHRONIZE_SPUS = 0x4000, // Lockstep PPU-to-SPU communication
  408. TMO_SUPPORT_CONTEXT_SWITCHES = 0x8000, // Support context switch recording on supported platforms
  409. TMO_NULL_NETWORK = 0x10000, // Disable network traffic
  410. TMO_SUPPORT_TIMESPANS = 0x20000, // Disable timespans
  411. } TmOption;
  412. /*
  413. Option values that can be toggled during recording using $tmEnable.
  414. */
  415. //-----------------------------------------------------------------------------
  416. // Telemetry variables
  417. //-----------------------------------------------------------------------------
  418. EXPAPI typedef void TmDebugPrinter(char const *msg);
  419. /*
  420. User defined debug print function.
  421. */
  422. typedef int (*TMFNC_USERCB_OPEN)(void* user, char const *fname );
  423. typedef int (*TMFNC_USERCB_CLOSE)(void* user);
  424. typedef int (*TMFNC_USERCB_WRITE)(void* user,void const* data,int datasize);
  425. EXPTYPE typedef enum TmParameter
  426. {
  427. TMP_NONE = 0x0000,
  428. TMP_LOCK_MIN_TIME = 1, // pass in a pointer to TmI32, >= 0 in microseconds
  429. TMP_DEBUG_PRINTER = 2, // pass in a pointer to a $TmDebugPrinter
  430. TMP_TELEMETRY_PREFERRED_CPU = 3, // pass in a pointer to a TmI32 with the preferred CPU for Telemetry's background thread
  431. TMP_USERCB_OPEN = 4,
  432. TMP_USERCB_CLOSE = 5,
  433. TMP_USERCB_WRITE = 6,
  434. TMP_USERCB_DATA = 7,
  435. TMP_EMULATED_SERVER_VERSION = 8,
  436. TMP_SOCKET_BUFFER_SIZE = 9,
  437. } TmParameter;
  438. /*
  439. Parameter values that can be set using $tmSetParameter
  440. */
  441. EXPTYPE typedef enum TmServerConfiguration
  442. {
  443. TMSC_MEM_PLOT_THRESHOLD = 0, // Delta memory usage that triggers a plot for memory usage on the server. Value passed to $tmSetServerConfiguration should be a 64-bit integer.
  444. } TmServerConfiguration;
  445. /*
  446. Parameter values that can be set using $tmSetServerConfiguration
  447. */
  448. EXPTYPE typedef enum TmPlatformInformation
  449. {
  450. TMPI_TELEMETRY_THREAD = 0, // Thread handle of the telemetry processing background thread. Windows/360/XB1/PS3/PS4 only. pIn should be your Telemetry context. pOut should be a pointer to a HANDLE/sys_ppu_thread_t/ScePthread
  451. TMPI_CONTEXT_SWITCH_THREAD = 1, // Thread handle of the context switch processing background thread. Windows Vista/7/360 only. pIn should be your Telemetry context. pOut sould be a pointer to a HANDLE.
  452. TMPI_START_TIME = 2, // Initial start time (in cycles) that Telemetry is basing its relative times from. pIn should be your Telemetry context. pOut should be a pointer to a U64.
  453. } TmPlatformInformation;
  454. /*
  455. Platform information values that can be passed to $tmGetPlatformInformation
  456. */
  457. //-----------------------------------------------------------------------------
  458. // Lock state
  459. //-----------------------------------------------------------------------------
  460. EXPTYPE typedef enum TmLockState
  461. {
  462. TMLS_RELEASED = 0x00000001, // Lock was released
  463. TMLS_LOCKED = 0x00000002, // Lock was acquired
  464. TMLS_DESTROYED = 0x00000004, // Lock was destroyed
  465. TMLS_INTERNAL_MASK = 0xF0000000,
  466. TMLS_INTERNAL_TIMESPAN = 0x10000000, // This is a timespan, not a lock
  467. TMLS_INTERNAL_LOD_LOCK = 0x20000000, // Internally generated by Telemetry, DO NOT USE.
  468. TMLS_INTERNAL_FAKE = 0x40000000, // Internally generated by Telemetry, DO NOT USE.
  469. TMLS_INTERNAL_COUNT = 0x80000000, // Internally generated by Telemetry, DO NOT USE.
  470. } TmLockState;
  471. /*
  472. Lock state value passed to $tmSetLockState
  473. See also $ug_mutexes
  474. */
  475. //-----------------------------------------------------------------------------
  476. // Lock attempt result
  477. //-----------------------------------------------------------------------------
  478. EXPTYPE typedef enum TmLockResult
  479. {
  480. TMLR_SUCCESS = 0, // Lock attempt succeeded
  481. TMLR_FAILED = 1, // Lock attempt failed
  482. TMLR_TIMEOUT = 2, // Lock attempt timed out
  483. } TmLockResult;
  484. /*
  485. Passed to $tmEndTryLock to specify the result of the lock action.
  486. See also $ug_mutexes
  487. */
  488. //-----------------------------------------------------------------------------
  489. // Telemetry statistics
  490. //-----------------------------------------------------------------------------
  491. EXPTYPE typedef enum TmStat
  492. {
  493. TMSTAT_NUM_ALLOCS_DEPRECATED, // Number of allocs this tick
  494. TMSTAT_NUM_FREES_DEPRECATED, // Number of frees this tick
  495. TMSTAT_NUM_TICKS_DEPRECATED, // Number of ticks so far
  496. } TmStat;
  497. /*
  498. Passed to $tmGetStati
  499. */
  500. #endif
  501. #ifndef NTELEMETRY
  502. #if defined __RADPS3__
  503. #define TM_NUM_SPUS 6
  504. TM_API( TmErrorCode, tmPPUCoreGetListener, ( HTELEMETRY cx, int const kNdx, TmU32 *pListener ) );
  505. TM_API( TmErrorCode, tmPPUCoreRegisterSPUProgram, ( HTELEMETRY cx, TmU64 const kGuid, void const *imagebase, unsigned int const kImageSize, int const kRdOnlyOffset ) );
  506. #endif
  507. #if defined __RADSPU__
  508. TM_API( TmErrorCode, tmSPUCoreBindContextToListener, ( HTELEMETRY *pcx, void * mem, TmU32 kPPUListener, char const *imagename, ...) );
  509. TM_API( TmErrorCode, tmSPUCoreUpdateTime, ( HTELEMETRY cx ) );
  510. TM_API( TmErrorCode, tmSPUCoreFlushImage, ( HTELEMETRY cx ) );
  511. #endif
  512. TM_API( TmU32, tmCoreGetVersion, ( void ) );
  513. TM_API( TmErrorCode, tmCoreCheckVersion, ( HTELEMETRY cx, TmU32 const major, TmU32 const minor, TmU32 const build, TmU32 const cust ) );
  514. TM_API( TmErrorCode, tmCoreGetPlatformInformation, ( void* obj, TmPlatformInformation const kInfo, void* dst, TmU32 const kDstSize ) );
  515. TM_API( TmErrorCode, tmCoreGetLastError, ( HTELEMETRY cx ) );
  516. TM_API( TmErrorCode, tmCoreGetSessionName, ( HTELEMETRY cx, char *dst, int const kDstSize ) );
  517. TM_API( TmConnectionStatus, tmCoreGetConnectionStatus, ( HTELEMETRY cx ) );
  518. #ifndef __RADSPU__
  519. RADDEFFUNC typedef TmU64 TMUSERTIMERFNC( void ); // User defined timing function
  520. TM_API( TmErrorCode, tmCoreStartup, ( void ) );
  521. TM_API( TmErrorCode, tmCoreStartupEx, ( TMUSERTIMERFNC *fnc ) );
  522. TM_API( TmErrorCode, tmCoreInitializeContext, ( EXPOUT HTELEMETRY * pcx, void * pArena, TmU32 const kArenaSize ) );
  523. TM_API( void, tmCoreShutdownContext, ( HTELEMETRY cx ) );
  524. TM_API( void, tmCoreShutdown, ( void ) );
  525. TM_API( TmErrorCode, tmCoreOpen, ( HTELEMETRY cx, char const * kpAppName,
  526. char const * kpBuildInfo,
  527. char const * kpServerAddress,
  528. TmConnectionType const kConnection,
  529. TmU16 const kServerPort,
  530. TmU32 const kFlags,
  531. int const kTimeoutMS ) );
  532. #endif
  533. TM_API( void, tmCoreClose, ( HTELEMETRY cx ) );
  534. TM_API( void , tmCoreSetDebugZoneLevel, ( HTELEMETRY cx, int const v ) );
  535. TM_API( void , tmCoreCheckDebugZoneLevel, ( HTELEMETRY cx, int const v ) );
  536. TM_API( void , tmCoreUnwindToDebugZoneLevel, ( HTELEMETRY cx, int const v ) );
  537. TM_API( char const *, tmCoreDynamicString, ( HTELEMETRY cx, char const * s ) );
  538. TM_API( void, tmCoreClearStaticString, ( HTELEMETRY cx, char const * s ) );
  539. TM_API( void, tmCoreSetVariable, ( HTELEMETRY cx, char const *kpKey, TmFormatCode* pFormatCode, char const *kpValueFmt, ... ) );
  540. TM_API( void, tmCoreSetTimelineSectionName, ( HTELEMETRY cx, TmFormatCode *pFormatCode, char const * kpFmt, ... ) );
  541. TM_API( void, tmCoreThreadName, ( HTELEMETRY cx, TmU32 const kThreadID, TmFormatCode *pFormatCode, char const * kpFmt, ... ) );
  542. TM_API( void, tmCoreGetFormatCode, ( TmFormatCode* pCode, char const * kpFmt ) );
  543. TM_API( void, tmCoreEnable, ( HTELEMETRY cx, TmOption const kOption, int const kValue ) );
  544. TM_API( int , tmCoreIsEnabled, ( HTELEMETRY cx, TmOption const kOption ) );
  545. TM_API( void, tmCoreSetParameter, ( HTELEMETRY cx, TmParameter const kParam, void const *kpValue ) );
  546. TM_API( void, tmCoreSetServerConfiguration, ( HTELEMETRY cx, TmServerConfiguration const kConfiguration, void const *kpValue ) );
  547. TM_API( void, tmCoreTick, ( HTELEMETRY cx ) );
  548. TM_API( void, tmCoreFlush, ( HTELEMETRY cx ) );
  549. TM_API( void, tmCorePause, ( HTELEMETRY cx, int const kPause ) );
  550. TM_API( int, tmCoreIsPaused, ( HTELEMETRY cx ) );
  551. TM_API( void, tmCoreEnter, (HTELEMETRY cx, TmU64 *matchid, TmU32 const kThreadId, TmU64 const kThreshold, TmU32 const kFlags, char const *kpLocation, TmU32 const kLine, TmFormatCode* pFmtCode, char const *kpFmt, ... ) );
  552. TM_API( void, tmCoreLeave, ( HTELEMETRY cx, TmU64 const kMatchID, TmU32 const kThreadId, char const *kpLocation, int const kLine ) );
  553. TM_API( void, tmCoreEmitAccumulationZone, ( HTELEMETRY cx, TmU64 * pAccum, TmU64 const kZoneTotal, TmU32 const kCount, TmU32 const kZoneFlags, char const *kpLocation, TmU32 const kLine, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  554. TM_API( TmU64, tmCoreGetLastContextSwitchTime, (HTELEMETRY cx) );
  555. TM_API( void, tmCoreLockName, ( HTELEMETRY cx, void const *kpPtr, TmFormatCode* pFmtCode, char const * kpFmt, ... ) );
  556. TM_API( void, tmCoreSetLockState, ( HTELEMETRY cx, void const *kpPtr, TmLockState const kState, char const * kLocation, TmU32 const kLine, TmFormatCode *pFormatCode, char const *kpFmt, ... ) );
  557. TM_API( int, tmCoreSetLockStateMinTime, ( HTELEMETRY cx, void* buf, void const *kpPtr, TmLockState const kState, char const * kLocation, TmU32 const kLine, TmFormatCode *pFormatCode, char const *kpFmt, ... ) );
  558. TM_API( void, tmCoreBeginTimeSpan, ( HTELEMETRY cx, TmU64 const kId, TmU32 const kFlags, TmU64 const kTime, char const *kpLocation, TmU32 const kLine, TmFormatCode *pFmtCode, char const *kpFmt, ... ) );
  559. TM_API( void, tmCoreEndTimeSpan, ( HTELEMETRY cx, TmU64 const kId, TmU32 const kFlags, TmU64 const kTime, char const *kpLocation, TmU32 const kLine, TmFormatCode *pFmtCode, char const *kpFmt, ... ) );
  560. TM_API( void, tmCoreSignalLockCount, ( HTELEMETRY cx, char const *kpLocation, TmU32 const kLine, void const * kPtr, TmU32 const kCount, TmFormatCode* pFmtCode, char const *kpName, ... ) );
  561. TM_API( void, tmCoreTryLock, ( HTELEMETRY cx, TmU64 *matchid, TmU64 const kThreshold, char const *kpLocation, TmU32 const kLine, void const * kPtr, TmFormatCode* pFmtCode, char const *kpFmt, ... ) );
  562. TM_API( void, tmCoreEndTryLock, ( HTELEMETRY cx, TmU64 const kMatchId, char const *kpLocation, int const kLine, TmFormatCode* pFmt, void const * kPtr, TmLockResult const kResult ) );
  563. TM_API( TmI32, tmCoreGetStati, ( HTELEMETRY cx, TmStat const kStat ) );
  564. TM_API( void, tmCoreMessage, ( HTELEMETRY cx, TmU32 const kThreadId, TmU32 const kFlags, TmFormatCode* pFmtCode, char const * kpFmt, ... ) );
  565. TM_API( void, tmCoreAlloc, ( HTELEMETRY cx, void const * kPtr, TmU64 const kSize, char const *kpLocation, TmU32 const kLine, TmFormatCode *pFmtCode, char const *kpFmt, ... ) );
  566. TM_API( void, tmCoreFree, ( HTELEMETRY cx, void const * kpPtr, char const *kpLocation, int const kLine, TmFormatCode *pFmtCode ) );
  567. TM_API( void, tmCorePlot, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, float const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  568. TM_API( void, tmCorePlotI32, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, TmI32 const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  569. TM_API( void, tmCorePlotU32, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, TmU32 const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  570. TM_API( void, tmCorePlotI64, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, TmI64 const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  571. TM_API( void, tmCorePlotU64, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, TmU64 const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  572. TM_API( void, tmCorePlotF64, ( HTELEMETRY cx, TmI64 const kTSC, TmPlotType const kType, TmU32 const kFlags, double const kValue, TmFormatCode *pFmtCode, char const * kpFmt, ... ) );
  573. TM_API( void, tmCoreBlob, ( HTELEMETRY cx, void const * kpData, int const kDataSize, char const *kpPluginIdentifier, TmFormatCode* pFmtCode, char const * kpFmt, ... ) );
  574. TM_API( void, tmCoreDisjointBlob, ( HTELEMETRY cx, int const kNumPieces, void const ** kpData, int const *kDataSize, char const *kpPluginIdentifier, TmFormatCode* pFmtCode, char const * kpFmt, ... ) );
  575. TM_API( void, tmCoreUpdateSymbolData, ( HTELEMETRY cx ) );
  576. TM_API( int, tmCoreSendCallStack, ( HTELEMETRY cx, TmCallStack const * kpCallStack, int const kSkip ) );
  577. TM_API( int, tmCoreGetCallStack, ( HTELEMETRY cx, TmCallStack * pCallStack ) );
  578. TM_API( int, tmCoreSendCallStackR, ( HTELEMETRY cx, TmCallStack const * kpCallStack, int const kSkip ) );
  579. TM_API( int, tmCoreGetCallStackR, ( HTELEMETRY cx, TmCallStack * pCallStack ) );
  580. #ifndef TM_API_STATIC
  581. typedef struct TM_API_STRUCT
  582. {
  583. // NOTE: Order of this must be preserved, new functions should be added to the end
  584. #define TM_API_S(name) TM_FUNCTION_TYPE(name) name
  585. TM_API_S( tmCoreCheckVersion );
  586. TM_API_S( tmCoreUpdateSymbolData );
  587. TM_API_S( tmCoreGetLastContextSwitchTime );
  588. #ifndef __RADSPU__
  589. TM_API_S( tmCoreTick );
  590. #endif
  591. TM_API_S( tmCoreFlush );
  592. TM_API_S( tmCoreDynamicString );
  593. TM_API_S( tmCoreClearStaticString );
  594. TM_API_S( tmCoreSetVariable );
  595. TM_API_S( tmCoreGetFormatCode );
  596. TM_API_S( tmCoreGetSessionName );
  597. TM_API_S( tmCoreGetLastError );
  598. TM_API_S( tmCoreShutdownContext );
  599. TM_API_S( tmCoreGetConnectionStatus );
  600. TM_API_S( tmCoreSetTimelineSectionName );
  601. TM_API_S( tmCoreEnable );
  602. TM_API_S( tmCoreIsEnabled );
  603. #ifndef __RADSPU__
  604. TM_API_S( tmCoreOpen );
  605. #endif
  606. TM_API_S( tmCoreClose );
  607. TM_API_S( tmCorePause );
  608. TM_API_S( tmCoreIsPaused );
  609. TM_API_S( tmCoreEnter );
  610. TM_API_S( tmCoreLeave );
  611. TM_API_S( tmCoreThreadName );
  612. TM_API_S( tmCoreLockName );
  613. TM_API_S( tmCoreTryLock );
  614. TM_API_S( tmCoreEndTryLock );
  615. TM_API_S( tmCoreSignalLockCount );
  616. TM_API_S( tmCoreSetLockState );
  617. TM_API_S( tmCoreAlloc );
  618. TM_API_S( tmCoreFree );
  619. TM_API_S( tmCoreGetStati );
  620. TM_API_S( tmCoreBeginTimeSpan );
  621. TM_API_S( tmCoreEndTimeSpan );
  622. TM_API_S( tmCorePlot );
  623. TM_API_S( tmCorePlotI32 );
  624. TM_API_S( tmCorePlotU32 );
  625. TM_API_S( tmCorePlotI64 );
  626. TM_API_S( tmCorePlotU64 );
  627. TM_API_S( tmCorePlotF64 );
  628. TM_API_S( tmCoreBlob );
  629. TM_API_S( tmCoreDisjointBlob );
  630. TM_API_S( tmCoreMessage );
  631. TM_API_S( tmCoreSendCallStack );
  632. TM_API_S( tmCoreGetCallStack );
  633. TM_API_S( tmCoreSetDebugZoneLevel );
  634. TM_API_S( tmCoreCheckDebugZoneLevel );
  635. TM_API_S( tmCoreUnwindToDebugZoneLevel );
  636. TM_API_S( tmCoreEmitAccumulationZone );
  637. TM_API_S( tmCoreSetLockStateMinTime );
  638. TM_API_S( tmCoreSetParameter );
  639. #if defined __RADPS3__ && !defined TM_API_STATIC
  640. TM_API_S( tmPPUCoreGetListener );
  641. TM_API_S( tmPPUCoreRegisterSPUProgram );
  642. #endif
  643. // If adding anything after here make sure to update stubs!
  644. TM_API_S( tmCoreSendCallStackR );
  645. TM_API_S( tmCoreGetCallStackR );
  646. TM_API_S( tmCoreSetServerConfiguration );
  647. } TM_API_STRUCT;
  648. #endif // !TM_API_STATIC
  649. #endif //NTELEMETRY
  650. RADDEFEND
  651. #if !defined TM_API_STATIC && !defined NTELEMETRY
  652. // snag API function
  653. typedef void (RADEXPLINK *tmGetAPIproc)( void * buffer );
  654. #endif
  655. //----------------------------------------------------------------------------
  656. // If NTELEMETRY is defined then all Telemetry calls are compiled away by
  657. // the preprocessor.
  658. //----------------------------------------------------------------------------
  659. #ifdef NTELEMETRY
  660. #define TM_VAR(x)
  661. #define tmUpdateSymbolData(cx)
  662. #define tmSetDebugZoneLevel(cx,n)
  663. #define tmCheckDebugZoneLevel(cx,n)
  664. #define tmUnwindToDebugZoneLevel(cx,n)
  665. #define tmGetLastError(cx) TM_OK
  666. #define tmShutdownContext(cx)
  667. #define tmGetLastContextSwitchTime(cx) 0
  668. #define tmGetAccumulationStart(cx) 0
  669. #define tmEnterAccumulationZone(cx,z)
  670. #define tmLeaveAccumulationZone(cx,z)
  671. #define tmGetFormatCode(cx,s,t)
  672. #define tmDynamicString(cx,s) 0
  673. #define tmTick(cx)
  674. #define tmFlush(cx)
  675. #define tmPause(cx,p)
  676. #define tmIsPaused(cx) 0
  677. #define tmClearStaticString(cx,s)
  678. #define tmEnable(cx,flag,value)
  679. #define tmIsEnabled(cx,flag) 0
  680. #define tmSetParameter(cx,param,v)
  681. #define tmSetServerConfiguration(cx,param,v)
  682. #define tmOpen(cx,appname,buildinfo,servername,contype,serverport,flags,timeout) TMERR_DISABLED
  683. #define tmClose(cx)
  684. #define tmGetConnectionStatus(cx) TMCS_DISCONNECTED
  685. #define tmFree(cx,ptr)
  686. #define tmLeave(cx)
  687. #ifndef __RADNOVARARGMACROS__
  688. #define tmGetSessionName(...)
  689. #define tmEndTryLock(...)
  690. #define tmEndTryLockEx(...)
  691. #define tmSetLockState(...)
  692. #define tmSetLockStateEx(...)
  693. #define tmSetLockStateMinTime(...) 0
  694. #define tmSetLockStateMinTimeEx(...) 0
  695. #define tmSignalLockCount(...)
  696. #define tmCheckVersion(...) 0
  697. #define tmGetCallStack(...) 0
  698. #define tmSendCallStack( ... ) TMPRINTF_TOKEN_NONE
  699. #define tmGetVersion(...) 0
  700. #define tmStartup(...) TMERR_DISABLED
  701. #define tmStartupEx(...) TMERR_DISABLED
  702. #define tmGetPlatformInformation(...) TMERR_DISABLED
  703. #define tmInitializeContext(...) TMERR_DISABLED
  704. #define tmShutdown(...) TMERR_DISABLED
  705. #define tmEnter(...)
  706. #define tmEnterEx(...)
  707. #define tmZone(...)
  708. #define tmZoneFiltered(...)
  709. #define tmLeaveEx(...)
  710. #define tmBeginTimeSpan(...)
  711. #define tmEndTimeSpan(...)
  712. #define tmEmitAccumulationZone(...)
  713. #define tmGetStati(...) 0
  714. #define tmSetVariable(...)
  715. #define tmBlob(...)
  716. #define tmDisjointBlob(...)
  717. #define tmSetTimelineSectionName(...)
  718. #define tmThreadName(...)
  719. #define tmLockName(...)
  720. #define tmMessage(...)
  721. #define tmMessageEx(...)
  722. #define tmAlloc(...)
  723. #define tmAllocEx(...)
  724. #define tmTryLock(...)
  725. #define tmTryLockEx(...)
  726. #define tmPlot(...)
  727. #define tmPlotF32(...)
  728. #define tmPlotF64(...)
  729. #define tmPlotI32(...)
  730. #define tmPlotU32(...)
  731. #define tmPlotS32(...)
  732. #define tmPlotI64(...)
  733. #define tmPlotU64(...)
  734. #define tmPlotS64(...)
  735. #define tmPlotAt(...)
  736. #define tmPlotF32At(...)
  737. #define tmPlotF64At(...)
  738. #define tmPlotI32At(...)
  739. #define tmPlotU32At(...)
  740. #define tmPlotS32At(...)
  741. #define tmPlotI64At(...)
  742. #define tmPlotU64At(...)
  743. #define tmPlotS64At(...)
  744. #define tmPPUGetListener(...)
  745. #define tmPPURegisterSPUProgram(...)
  746. #define tmSPUBindContextToListener(...)
  747. #define tmSPUUpdateTime(...)
  748. #define tmSPUFlushImage(...)
  749. #endif // __RADNOVARARGMACROS__
  750. #else // !NTELEMETRY
  751. //----------------------------------------------------------------------------
  752. // Variable declaration macro so that if you compile with NTELEMETRY
  753. // the Telemetry specific variable declarations go away (helps when compiling
  754. // with warnings-as-errors).
  755. //----------------------------------------------------------------------------
  756. #define TM_VAR(x) x
  757. //----------------------------------------------------------------------------
  758. // C++ helper for entering/exiting zones
  759. //----------------------------------------------------------------------------
  760. #if defined(__cplusplus) && !defined(TM_NO_ZCLASS)
  761. #define TMLINENAME3(name,line) name##line
  762. #define TMLINENAME2( name, line ) TMLINENAME3(name,line)
  763. #define TMLINENAME( name ) TMLINENAME2(name,__LINE__)
  764. #define tmZoneFiltered(cx,mintime,flags,name,...) TmU64 TMLINENAME(tm_id) = 0; \
  765. TMCHECKCONTEXT_VA(cx,tmCoreEnter,(cx,&(TMLINENAME(tm_id)),0,mintime,(flags),__FILE__, __LINE__, &tm_fmt, name,##__VA_ARGS__));\
  766. Tm_Zone TMLINENAME(tm_ZoneProfiler)(cx,TMLINENAME(tm_id));
  767. #define tmZone(cx,flags,name,...) tmZoneFiltered(cx,0,flags,name,##__VA_ARGS__)
  768. //Zone helper
  769. class Tm_Zone
  770. {
  771. private:
  772. TmU64 z_id;
  773. HTELEMETRY z_cx;
  774. public:
  775. inline Tm_Zone(HTELEMETRY cx, TmU64 const kMatchID )
  776. {
  777. z_cx = cx;
  778. z_id = kMatchID;
  779. }
  780. inline ~Tm_Zone()
  781. {
  782. TMCHECKCONTEXTV(z_cx,tmCoreLeave,(z_cx,z_id,0,0,0));
  783. }
  784. };
  785. #endif //__cplusplus
  786. #if (!(defined(TM_DLL) && (TM_DLL==1)))
  787. // startup and shutdown functions (part of loading lib, not DLL)
  788. #ifndef __RADINDLL__
  789. RADDEFSTART
  790. #endif
  791. #if defined TM_API_STATIC
  792. #define tmStartup tmCoreStartup
  793. #define tmStartupEx tmCoreStartupEx
  794. #define tmShutdown tmCoreShutdown
  795. #define tmGetVersion tmCoreGetVersion
  796. #define tmInitializeContext tmCoreInitializeContext
  797. #define tmGetPlatformInformation tmCoreGetPlatformInformation
  798. #else
  799. RADDEFFUNC TmErrorCode RADEXPLINK tmStartup( void );
  800. RADDEFFUNC TmErrorCode RADEXPLINK tmStartupEx( TMUSERTIMERFNC *fnc );
  801. RADDEFFUNC TmErrorCode RADEXPLINK tmShutdown( void );
  802. RADDEFFUNC TmU32 RADEXPLINK tmGetVersion( void );
  803. RADDEFFUNC TmErrorCode RADEXPLINK tmInitializeContext( EXPOUT HTELEMETRY * pcx, void * pArena, TmU32 const kArenaSize );
  804. RADDEFFUNC TmErrorCode RADEXPLINK tmGetPlatformInformation( void* obj, TmPlatformInformation const kInfo, void *dst, TmU32 const kSize );
  805. #endif
  806. #ifndef __RADINDLL__
  807. RADDEFEND
  808. #endif
  809. #define tmCheckVersion( cx,major,minor,build,cust) TMCHECKCONTEXTR(cx,tmCoreCheckVersion,(cx,major,minor,build,cust),0)
  810. #ifdef __RADPS3__
  811. #define tmPPUGetListener(cx,n,p) TMCHECKCONTEXTR(cx,tmPPUCoreGetListener,(cx,n,p),TMERR_DISABLED)
  812. #define tmPPURegisterSPUProgram(cx,guid,address,s,ro_offset) TMCHECKCONTEXTR(cx,tmPPUCoreRegisterSPUProgram,(cx,guid,address,s,ro_offset),TMERR_DISABLED)
  813. #endif
  814. #ifdef __RADSPU__
  815. #define tmSPUUpdateTime(cx) TMCHECKCONTEXTV(cx,tmSPUCoreUpdateTime,(cx))
  816. #define tmSPUFlushImage(cx) TMCHECKCONTEXTV(cx,tmSPUCoreFlushImage,(cx))
  817. #endif
  818. #define tmUpdateSymbolData(cx) TMCHECKCONTEXTV(cx,tmCoreUpdateSymbolData,(cx))
  819. #define tmGetSessionName(cx,a,b) TMCHECKCONTEXTR(cx,tmCoreGetSessionName,(cx,a,b),TMERR_DISABLED)
  820. #define tmUnwindToDebugZoneLevel(cx,n) TMCHECKCONTEXTV(cx,tmCoreUnwindToDebugZoneLevel,(cx,n))
  821. #define tmSetDebugZoneLevel(cx,n) TMCHECKCONTEXTV(cx,tmCoreSetDebugZoneLevel,(cx,n))
  822. #define tmCheckDebugZoneLevel(cx,n) TMCHECKCONTEXTV(cx,tmCoreCheckDebugZoneLevel,(cx,n))
  823. #define tmGetCallStack(cx,p) TMCHECKCONTEXTR(cx,tmCoreGetCallStack,(cx,p),0)
  824. #define tmSendCallStack(cx,p) TMCHECKCONTEXTR(cx,tmCoreSendCallStack,(cx,p,0),TMPRINTF_TOKEN_NONE)
  825. #define tmSendCallStackWithSkip(cx,p,s) TMCHECKCONTEXTR(cx,tmCoreSendCallStack,(cx,p,s),TMPRINTF_TOKEN_NONE)
  826. #define tmGetCallStackR(cx,p) TMCHECKCONTEXTR(cx,tmCoreGetCallStackR,(cx,p),0)
  827. #define tmSendCallStackR(cx,p) TMCHECKCONTEXTR(cx,tmCoreSendCallStackR,(cx,p,0),TMPRINTF_TOKEN_NONE)
  828. #define tmSendCallStackWithSkipR(cx,p,s) TMCHECKCONTEXTR(cx,tmCoreSendCallStackR,(cx,p,s),TMPRINTF_TOKEN_NONE)
  829. #define tmGetLastError(cx) TMCHECKCONTEXT(cx,tmCoreGetLastError,(cx))
  830. #define tmShutdownContext(cx) TMCHECKCONTEXTV(cx,tmCoreShutdownContext,(cx))
  831. #define tmGetLastContextSwitchTime(cx) TMCHECKCONTEXTR(cx,tmCoreGetLastContextSwitchTime,(cx),0)
  832. #define tmGetAccumulationStart(cx) ((cx) ? tmFastTime() : 0)
  833. #define tmEnterAccumulationZone(cx,z) { if (cx) (z) -= tmFastTime(); }
  834. #define tmLeaveAccumulationZone(cx,z) { if (cx) (z) += tmFastTime(); }
  835. #define tmGetFormatCode(cx,s,t) TMCHECKCONTEXTV(cx,tmCoreGetFormatCode,(s,t))
  836. #define tmDynamicString(cx,s) TMCHECKCONTEXTR(cx,tmCoreDynamicString,(cx,s),0)
  837. #define tmClearStaticString(cx,s) TMCHECKCONTEXTV(cx,tmCoreClearStaticString,(cx,s))
  838. #define tmEnable(cx,flag,value) TMCHECKCONTEXTV(cx,tmCoreEnable,(cx,flag,value))
  839. #define tmIsEnabled(cx,flag) TMCHECKCONTEXT(cx,tmCoreIsEnabled,(cx,flag))
  840. #define tmSetParameter(cx,p,v) TMCHECKCONTEXTV(cx,tmCoreSetParameter,(cx,p,v))
  841. #define tmSetServerConfiguration(cx,p,v) TMCHECKCONTEXTV(cx,tmCoreSetServerConfiguration,(cx,p,v))
  842. #define tmOpen(cx,appname,buildinfo,servername,contype,serverport,flags,timeout) TMCHECKCONTEXT(cx,tmCoreOpen,(cx,appname,buildinfo,servername,contype,serverport,flags,timeout))
  843. #define tmClose(cx) TMCHECKCONTEXTV(cx,tmCoreClose,(cx))
  844. #define tmTick(cx) TMCHECKCONTEXTV(cx,tmCoreTick,(cx))
  845. #define tmFlush(cx) TMCHECKCONTEXTV(cx,tmCoreFlush,(cx))
  846. #define tmPause(cx,pause) TMCHECKCONTEXTV(cx,tmCorePause,(cx,pause))
  847. #define tmIsPaused(cx) TMCHECKCONTEXTR(cx,tmCoreIsPaused,(cx),0)
  848. #define tmGetConnectionStatus(cx) TMCHECKCONTEXTR(cx,tmCoreGetConnectionStatus,(cx),TMCS_DISCONNECTED)
  849. #define tmGetStati( c, stat ) TMCHECKCONTEXT(cx,tmCoreGetStati,( cx, stat ))
  850. #define tmLeave(cx) TMCHECKCONTEXTV(cx,tmCoreLeave,(cx,0,0,__FILE__,__LINE__))
  851. #define tmLeaveEx(cx,match,tid,f,l) TMCHECKCONTEXTV(cx,tmCoreLeave,(cx,match,tid,f,l))
  852. #define tmFree(cx,ptr) TMCHECKCONTEXT_VA(cx,tmCoreFree,(cx,ptr,__FILE__, __LINE__, &tm_fmt))
  853. #ifndef __RADNOVARARGMACROS__
  854. #ifdef __RADSPU__
  855. #define tmSPUBindContextToListener(pcx,mem,pptr,imagename,...) TMCHECKCONTEXTV(pcx,tmSPUCoreBindContextToListener,(pcx,mem,pptr,imagename,##__VA_ARGS__))
  856. #endif
  857. #define tmTryLock(cx,ptr,name,...) TMCHECKCONTEXT_VA(cx,tmCoreTryLock,(cx,0,0,__FILE__,__LINE__,ptr,&tm_fmt,name,##__VA_ARGS__))
  858. #define tmTryLockEx(cx,matchid,threshold,file,line,ptr,name,...) TMCHECKCONTEXT_VA(cx,tmCoreTryLock,(cx,matchid,threshold,file,line,ptr,&tm_fmt,name,##__VA_ARGS__))
  859. #define tmEndTryLock(cx,m,result) TMCHECKCONTEXT_VA(cx,tmCoreEndTryLock,(cx,0,__FILE__,__LINE__,&tm_fmt, m,result))
  860. #define tmEndTryLockEx(cx,matchid,file,line,m,result) TMCHECKCONTEXT_VA(cx,tmCoreEndTryLock,(cx,matchid,file,line,&tm_fmt,m,result))
  861. #define tmBeginTimeSpan(cx,id,flags,name,...) TMCHECKCONTEXT_VA(cx,tmCoreBeginTimeSpan,(cx,id,flags,0,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  862. #define tmEndTimeSpan(cx,id,flags,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEndTimeSpan,(cx,id,flags,0,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  863. #define tmBeginTimeSpanEx(cx,id,flags,t,file,line,name,...) TMCHECKCONTEXT_VA(cx,tmCoreBeginTimeSpan,(cx,id,flags,t,file,line,&tm_fmt,name,##__VA_ARGS__))
  864. #define tmEndTimeSpanEx(cx,id,flags,t,file,line,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEndTimeSpan,(cx,id,flags,t,file,line,&tm_fmt,name,##__VA_ARGS__))
  865. #define tmBeginTimeSpanAt(cx,id,flags,t,name,...) TMCHECKCONTEXT_VA(cx,tmCoreBeginTimeSpan,(cx,id,flags,t,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  866. #define tmEndTimeSpanAt(cx,id,flags,t,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEndTimeSpan,(cx,id,flags,t,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  867. #define tmSignalLockCount(cx,m,cnt,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSignalLockCount,(cx,__FILE__,__LINE__,m,cnt,&tm_fmt,name,##__VA_ARGS__))
  868. #define tmSetLockState(cx,lockptr,state,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSetLockState,(cx,lockptr,state,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__ ))
  869. #define tmSetLockStateEx(cx,file,line,lockptr,state,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSetLockState,(cx,lockptr,state,file,line,&tm_fmt,name,##__VA_ARGS__ ))
  870. #define tmSetLockStateMinTime(cx,buf,lockptr,state,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSetLockStateMinTime,(cx,buf,lockptr,state,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__ ))
  871. #define tmSetLockStateMinTimeEx(cx,buf,file,line,lockptr,state,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSetLockStateMinTime,(cx,buf,lockptr,state,file,line,&tm_fmt,name,##__VA_ARGS__ ))
  872. #define tmThreadName(cx,threadid,name,...) TMCHECKCONTEXT_VA(cx,tmCoreThreadName,(cx,threadid,&tm_fmt,name,##__VA_ARGS__))
  873. #define tmLockName(cx,ptr,name,...) TMCHECKCONTEXT_VA(cx,tmCoreLockName,(cx,ptr,&tm_fmt,name,##__VA_ARGS__))
  874. #define tmEmitAccumulationZone(cx,flags,acc,count,ztotal,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEmitAccumulationZone,(cx,acc,ztotal,count,flags,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  875. #define tmSetVariable(cx,key,v,...) TMCHECKCONTEXT_VA(cx,tmCoreSetVariable,(cx,key,&tm_fmt,v,##__VA_ARGS__))
  876. #define tmSetTimelineSectionName(cx,name,...) TMCHECKCONTEXT_VA(cx,tmCoreSetTimelineSectionName,(cx,&tm_fmt,name,##__VA_ARGS__))
  877. #define tmEnter(cx,flags,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEnter,(cx,0,0,0,flags,__FILE__,__LINE__,&tm_fmt,name,##__VA_ARGS__))
  878. #define tmEnterEx(cx,matchid,tid,threshold,file,line,flags,name,...) TMCHECKCONTEXT_VA(cx,tmCoreEnter,(cx,matchid,tid,threshold,flags,file,line,&tm_fmt,name,##__VA_ARGS__))
  879. #define tmAlloc(cx,ptr,size,name,...) TMCHECKCONTEXT_VA(cx,tmCoreAlloc,(cx,ptr,size,__FILE__,__LINE__, &tm_fmt, name,##__VA_ARGS__))
  880. #define tmAllocEx(cx,file,line,ptr,size, name,...) TMCHECKCONTEXT_VA(cx,tmCoreAlloc,(cx,ptr,size,file,line, &tm_fmt,name,##__VA_ARGS__))
  881. #define tmMessage(cx,flags,s,...) TMCHECKCONTEXT_VA(cx,tmCoreMessage,(cx,0,flags,&tm_fmt,s,##__VA_ARGS__))
  882. #define tmMessageEx(cx,tid,flags,s,...) TMCHECKCONTEXT_VA(cx,tmCoreMessage,(cx,tid,flags,&tm_fmt,s,##__VA_ARGS__))
  883. #define tmPlot(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlot,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  884. #define tmPlotF32(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlot,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  885. #define tmPlotF64(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotF64,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  886. #define tmPlotI32(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotI32,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  887. #define tmPlotU32(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotU32,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  888. #define tmPlotI64(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotI64,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  889. #define tmPlotU64(cx,type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotU64,(cx,0,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  890. #define tmPlotAt(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlot,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  891. #define tmPlotF32At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlot,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  892. #define tmPlotF64At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotF64,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  893. #define tmPlotI32At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotI32,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  894. #define tmPlotU32At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotU32,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  895. #define tmPlotI64At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotI64,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  896. #define tmPlotU64At(cx,tsc, type,flags,val,name,...) TMCHECKCONTEXT_VA(cx,tmCorePlotU64,(cx,tsc,type,flags,val,&tm_fmt,name,##__VA_ARGS__))
  897. #define tmBlob(cx,chunk,size,pluginid,name,...) TMCHECKCONTEXT_VA(cx,tmCoreBlob,(cx,chunk,size,pluginid,&tm_fmt,name,##__VA_ARGS__))
  898. #define tmDisjointBlob(cx,num_args,chunks,sizes,plugind,name,...) TMCHECKCONTEXT_VA(cx,tmCoreDisjointBlob,(cx,num_args,chunks,sizes,pluginid,&tm_fmt,name,##__VA_ARGS__))
  899. #endif
  900. #endif
  901. #endif // !NTELEMETRY
  902. #if ( defined __RADNT__ || defined __RADLINUX__ || defined __RADMAC__ ) && !defined TM_API_STATIC && !defined __RADDURANGO__
  903. RADDEFSTART
  904. RADDEFFUNC int RADEXPLINK tmLoadTelemetryEx( int const major, int const minor, int const build, int const cust, int const kUseCheckedDLL );
  905. #define TM_LOAD_CHECKED_LIBRARY 1
  906. #define TM_LOAD_RELEASE_LIBRARY 0
  907. #ifndef NTELEMETRY
  908. #define tmLoadTelemetry( kUseCheckedDLL ) tmLoadTelemetryEx( TelemetryMajorVersion, TelemetryMinorVersion, TelemetryBuildNumber, TelemetryCustomization, kUseCheckedDLL )
  909. #else
  910. #define tmLoadTelemetry(...) 1
  911. #endif
  912. RADDEFEND
  913. #else
  914. #define tmLoadTelemetry(...) 1
  915. #endif
  916. #ifdef EXPGROUP
  917. #undef EXPGROUP
  918. #endif
  919. #define EXPGROUP()
  920. EXPGROUP()
  921. #undef EXPGROUP
  922. // ----------------------------------------------------------------------------
  923. // Define a fast time retrieval macro for this platform
  924. // ----------------------------------------------------------------------------
  925. #ifdef NTELEMETRY
  926. #define tmFastTime() 0
  927. #elif defined TM_INLINE_FASTTIME
  928. // Enable intrinsic RDTSC if available
  929. #if defined _MSC_VER && _MSC_VER >= 1400 && defined __RADX86__
  930. #pragma warning(disable:4505)
  931. #pragma warning(disable:4995)
  932. RADDEFFUNC unsigned __int64 __rdtsc(void);
  933. #pragma intrinsic(__rdtsc)
  934. #endif
  935. // SPU
  936. #if defined __RADSPU__
  937. #ifndef _SPU_INTRINSICS_H
  938. #include <spu_intrinsics.h>
  939. #endif
  940. #ifdef __cplusplus
  941. extern "C" TmU64 tm_spu_ppu_time;
  942. extern "C" TmU64 tm_spu_last_time;
  943. #else
  944. extern TmU64 tm_spu_ppu_time;
  945. extern TmU64 tm_spu_last_time;
  946. #endif
  947. static RADINLINE U32 __tmFastTimeSPU()
  948. {
  949. U32 dec = spu_readch(SPU_RdDec);
  950. U32 tsc = - dec;
  951. return tsc;
  952. }
  953. static RADINLINE U64 tmFastTime()
  954. {
  955. U64 const now = __tmFastTimeSPU();
  956. U64 t;
  957. if ( ( now & 0xFFFFFFFF ) < ( tm_spu_ppu_time & 0xFFFFFFFF ) )
  958. {
  959. t = now | ( ( tm_spu_ppu_time + 0x100000000LL ) & (~0xFFFFFFFFLL) );
  960. }
  961. else
  962. {
  963. t = now | ( tm_spu_ppu_time & (~0xFFFFFFFFLL ));
  964. }
  965. // Check to see if our time has wrapped/reversed
  966. if ( tm_spu_last_time > t )
  967. {
  968. t += 0x100000000LL;
  969. }
  970. tm_spu_last_time = t;
  971. return t;
  972. }
  973. // 32-bit Windows uses RDTSC
  974. #elif defined __RADNT__ && !defined __RADX64__
  975. // If intrinsics are available, use them
  976. #if defined _MSC_VER && _MSC_VER >= 1400
  977. #define tmFastTime() __rdtsc() // available as intrinsic on Visual Studio
  978. // Otherwise resort to inline assembly
  979. #else
  980. static __declspec(naked) unsigned __int64 tmFastTime()
  981. {
  982. __asm rdtsc;
  983. __asm ret;
  984. }
  985. #endif
  986. // On 64-bit windows we can use __rdtsc directly
  987. #elif defined __RADWIN__ && defined __RADX64__ && defined _MSC_VER
  988. #define tmFastTime() __rdtsc()
  989. // Mac and Linux imply GCC inline asm available
  990. #elif defined __RADMAC__ || ( ( defined __RADLINUX__ || defined __RADQNX__ ) && ( defined __RADX86__ || defined __RADX64__) ) || defined __RADPS4__
  991. static inline unsigned long long tmFastTime()
  992. {
  993. TmU32 lo, hi;
  994. asm volatile ("rdtsc" : "=a" (lo), "=d" (hi) );
  995. return (TmU64) hi << 32 | lo;
  996. }
  997. // On QNX this is the best we can hope for, unfortunately it may not be synced across
  998. // processors so we need to watch out for that
  999. #elif defined ( __RADQNX__ )
  1000. #include <sys/neutrino.h>
  1001. #include <inttypes.h>
  1002. static RADINLINE U64 tmFastTime()
  1003. {
  1004. return ClockCycles();
  1005. }
  1006. // On ARM Linux platforms (including Android) we have to hope that clock_gettime
  1007. // will be of sufficient accuracy
  1008. #elif defined __RADANDROID__
  1009. #include <time.h>
  1010. static inline unsigned long long tmFastTime()
  1011. {
  1012. // We're scaling by 1000 to get closer to a nanosecondish scale. Keep in mind
  1013. // that clock() is 32-bits and will wrap every ~72 minutes, so if you want higher
  1014. // precision and/or longer duration you should implement this with user timers
  1015. return clock() * 1000ULL;
  1016. }
  1017. #elif ( defined __RADLINUX__ && defined __RADARM__ )
  1018. #include <time.h>
  1019. static inline unsigned long long tmFastTime()
  1020. {
  1021. struct timespec t;
  1022. clock_gettime( CLOCK_MONOTONIC_RAW, &t );
  1023. return t.tv_sec * 1000000000ULL + t.tv_nsec;
  1024. }
  1025. // Xenon or PS3 we assume __mftb is available
  1026. // PowerPC platforms can use MFTB
  1027. #elif defined __RADPS3__
  1028. // PS3 we assume __mftb is available
  1029. #define tmFastTime() __extension__ \
  1030. ({ unsigned long long __macro_result; \
  1031. __asm__ volatile ("1: mftb %[current_tb]\n" \
  1032. "\tcmpwi 7, %[current_tb], 0\n" \
  1033. "\tbeq- 7, 1b" \
  1034. : [current_tb] "=r" (__macro_result): \
  1035. :"cr7"); \
  1036. __macro_result; })
  1037. #elif defined __RADXENON__
  1038. // Xenon we assume __mftb is available
  1039. #if defined __RADXENON__
  1040. RADDEFFUNC unsigned __int64 __mftb(); //From <PPCIntrinsics.h>
  1041. #pragma intrinsic(__mftb)
  1042. #endif
  1043. // check for weird sample and re-read
  1044. static RADINLINE U64 tmFastTime()
  1045. {
  1046. U64 a;
  1047. a = __mftb();
  1048. if ( ( a & 0xffffffff ) < 500 )
  1049. a = __mftb();
  1050. return a;
  1051. }
  1052. #elif defined __RADIPHONE__
  1053. RADDEFFUNC U64 mach_absolute_time();
  1054. static RADINLINE U64 tmFastTime()
  1055. {
  1056. return mach_absolute_time();
  1057. }
  1058. #elif defined __RADWIIU__
  1059. RADDEFFUNC unsigned int __MFTB(void); // in case aren't previously defined
  1060. RADDEFFUNC unsigned int __MFTBU(void);
  1061. static RADINLINE U64 tmFastTime()
  1062. {
  1063. U64 a = (U64) __MFTB() | ((U64) __MFTBU() << 32);
  1064. if ( ( a & 0xffffffff ) < 500 )
  1065. a = (U64) __MFTB() | ((U64) __MFTBU() << 32);
  1066. return a;
  1067. }
  1068. #elif defined __RADPSP2__
  1069. #include <libperf.h>
  1070. #define tmFastTime() scePerfGetTimebaseValue()
  1071. #else
  1072. #error tmFastTime not defined for this platform
  1073. #endif
  1074. #endif // NTELEMETRY
  1075. #endif //__RADRES__
  1076. #endif //TELEMETRY_H