Audacity 3.2.0
Diags.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Diags.h
6
7 James Crook
8
9 Provides Macros for recording bad events and performance monitoring.
10 These macros have such low cost that they can be used in release code.
11 They will take minuscule processing time after the first ten times.
12
13**********************************************************************/
14
15#ifndef __AUDACITY_DIAGS__
16#define __AUDACITY_DIAGS__
17
18typedef long t_diag_timer;
19
23 long total;
25 long least;
26 long most;
27 const wchar_t * pMessage;
28};
29
30
31extern void diagnostics_do_diag( t_diag_struct * pDiag );
32extern void diagnostics_do_diag_mem( t_diag_struct * pDiag, long amount );
33extern void diagnostics_do_perfmon_start( t_diag_struct * pDiag, t_diag_struct ** ppRememberMe );
34extern void diagnostics_do_perfmon_stop( t_diag_struct ** ppDiag);
35
36// A constant that sets the maximum number of times we log the message.
37#define DEFAULT_LOG_COUNT (10)
38
39// USAGE:
40// Each of these will do something the first ten times, then just count.
41// They can be reactivated by a GUI.
42//
43// Use DIAG for a simple message. Usually for something bad like an overrun.
44// Use TRACK_MEM to track hungry memory usage, RAM or disk.
45// Use TIMER_START and STOP to time an interval.
46// For the above two, you will need a MAKE_TIMER( timername ) first.
47
48// The 'timername' created here is almost free.
49// It's a pointer that allows both START and STOP to use the same struct.
50#define MAKE_TIMER( timername ) \
51 static t_diag_struct * timername = NULL;
52
53// Note that in all three macros:
54// The {} ensure diag name is not visible outside
55// static ensures struct is initialised just once.
56// No function is called after the countdown is counted out.
57#define DIAG( message ) { \
58 static t_diag_struct diag = { DEFAULT_LOG_COUNT, DEFAULT_LOG_COUNT, 0,0,0,0,wxT(message)};\
59 if( --diag.countdown >=0 )\
60 diagnostics_do_diag( &diag );\
61}
62
63#define TRACK_MEM( message, amount ) { \
64 static t_diag_struct diag = { DEFAULT_LOG_COUNT, DEFAULT_LOG_COUNT, 0,0,0,0,wxT(message)};\
65 if( --diag.countdown >=0 )\
66 diagnostics_do_diag_mem( &diag, amount );\
67}
68
69#define TIMER_START( message, timername )\
70 MAKE_TIMER( timername ); { \
71 static t_diag_struct diag = { DEFAULT_LOG_COUNT, DEFAULT_LOG_COUNT, 0,0,0,0,wxT(message)};\
72 if( --diag.countdown >=0 )\
73 diagnostics_do_perfmon_start( &diag, &timername );\
74}
75
76#define TIMER_STOP( timername ){ \
77 if( timername != NULL )\
78 diagnostics_do_perfmon_stop( &timername );\
79}
80
81
82
83#endif
void diagnostics_do_diag(t_diag_struct *pDiag)
Definition: Diags.cpp:43
void diagnostics_do_perfmon_stop(t_diag_struct **ppDiag)
Definition: Diags.cpp:76
void diagnostics_do_diag_mem(t_diag_struct *pDiag, long amount)
Definition: Diags.cpp:49
long t_diag_timer
Definition: Diags.h:18
void diagnostics_do_perfmon_start(t_diag_struct *pDiag, t_diag_struct **ppRememberMe)
Definition: Diags.cpp:65
long least
Definition: Diags.h:25
long most_recent
Definition: Diags.h:24
long countdown
Definition: Diags.h:21
long initial_count
Definition: Diags.h:22
const wchar_t * pMessage
Definition: Diags.h:27
long most
Definition: Diags.h:26
long total
Definition: Diags.h:23