naev 0.12.6
ntracing.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#if HAVE_TRACY
7#include "attributes.h"
8#include "tracy/TracyC.h"
9#include <stdlib.h>
10#define _uninitialized_var( x ) x = *( &( x ) )
11#define NTracingFrameMark TracyCFrameMark
12#define NTracingFrameMarkStart( name ) TracyCFrameMarkStart( name )
13#define NTracingFrameMarkEnd( name ) TracyCFrameMarkEnd( name )
14#define NTracingZone( ctx, active ) TracyCZone( ctx, active )
15#define NTracingZoneName( ctx, name, active ) TracyCZoneN( ctx, name, active )
16#define NTracingZoneEnd( ctx ) TracyCZoneEnd( ctx )
17#define NTracingAlloc( ptr, size ) \
18 do { \
19 _uninitialized_var( ptr ); \
20 TracyCAlloc( ptr, size ) \
21 } while ( 0 )
22#define NTracingFree( ptr ) \
23 do { \
24 if ( ptr != NULL ) { \
25 TracyCFree( ptr ); \
26 }; \
27 } while ( 0 )
28ALWAYS_INLINE static inline void *nmalloc( size_t size )
29{
30 void *ptr = malloc( size );
31 NTracingAlloc( ptr, size );
32 return ptr;
33}
34ALWAYS_INLINE static inline void nfree( void *ptr )
35{
36 NTracingFree( ptr );
37 free( ptr );
38}
39ALWAYS_INLINE static inline void *ncalloc( size_t nmemb, size_t size )
40{
41 void *ptr = calloc( nmemb, size );
42 NTracingAlloc( ptr, nmemb * size );
43 return ptr;
44}
45ALWAYS_INLINE static inline void *nrealloc( void *ptr, size_t size )
46{
47 NTracingFree( ptr );
48 void *newptr = realloc( ptr, size );
49 NTracingAlloc( newptr, size );
50 return newptr;
51}
52#define NTracingMessage( txt, size ) TracyCMessage( txt, size )
53#define NTracingMessageL( txt ) TracyCMessageL( txt )
54#define NTracingPlot( name, val ) TracyCPlot( name, val )
55#define NTracingPlotF( name, val ) TracyCPlotF( name, val )
56#define NTracingPlotI( name, val ) TracyCPlotI( name, val )
57#else /* HAVE_TRACY */
58#define NTracingFrameMark
59#define NTracingFrameMarkStart( name )
60#define NTracingFrameMarkEnd( name )
61#define NTracingZone( ctx, active )
62#define NTracingZoneName( ctx, name, active )
63#define NTracingZoneEnd( ctx )
64#define NTracingAlloc( ptr, size )
65#define NTracingFree( ptr )
66#define nmalloc( size ) malloc( size )
67#define ncalloc( nmemb, size ) calloc( nmemb, size )
68#define nfree( ptr ) free( ptr )
69#define nrealloc( ptr, size ) realloc( ptr, size )
70#define NTracingMessageL( msg )
71#define NTracingPlot( name, val )
72#define NTracingPlotF( name, val )
73#define NTracingPlotI( name, val )
74#endif /* HAVE_TRACY */