Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Timeprobe_Test.cpp
blob9c518837edb072512b95ac458336ef98eb473e2d
2 //=============================================================================
3 /**
4 * @file Timeprobe_Test.cpp
6 * This is a simple test of ACE Timeprobes.
8 * @author Irfan Pyarali <irfan@cs.wustl.edu>
9 */
10 //=============================================================================
13 //#define ACE_ENABLE_TIMEPROBES
14 //#define ACE_MT_TIMEPROBES
15 //#define ACE_TSS_TIMEPROBES
17 #include "test_config.h"
18 #include "ace/Singleton.h"
19 #include "ace/Synch_Traits.h"
20 #include "ace/Recursive_Thread_Mutex.h"
21 #include "ace/Null_Mutex.h"
22 #include "ace/OS_NS_unistd.h"
23 #include "ace/Timeprobe.h"
27 #if defined (ACE_ENABLE_TIMEPROBES)
29 static const char *events_descriptions_0[] =
31 "Event Zero",
32 "Event One",
33 "Event Two",
34 "Event Three",
35 "Event Four",
36 "Event Five",
37 "Event Six",
38 "Event Seven",
39 "Event Eight",
40 "Event Nine"
43 enum
45 EVENT_ZERO = 0,
46 EVENT_ONE,
47 EVENT_TWO,
48 EVENT_THREE,
49 EVENT_FOUR,
50 EVENT_FIVE,
51 EVENT_SIX,
52 EVENT_SEVEN,
53 EVENT_EIGHT,
54 EVENT_NINE
57 static const char *events_descriptions_1[] =
59 "Work start",
60 "Work end"
63 enum
65 WORK_START = 100,
66 WORK_END
69 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_1, WORK_START);
70 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_0, EVENT_ZERO);
72 #endif /* ACE_ENABLE_TIMEPROBES */
74 static void
75 work (int time)
77 ACE_FUNCTION_TIMEPROBE (WORK_START);
78 ACE_OS::sleep (time);
81 #if !defined (ACE_HAS_PURIFY)
82 // Test creation of ACE_Singletons during static object construction.
83 // Timeprobes can do that, when they're enabled. Purify would notice
84 // the memory in use at program termination.
85 static int
86 create_singleton ()
88 int *i = ACE_Singleton <int, ACE_SYNCH_RECURSIVE_MUTEX>::instance ();
89 *i = 3;
91 return *i;
94 int static_singleton_creator = create_singleton ();
95 #endif /* ! ACE_HAS_PURIFY */
97 int
98 run_main (int, ACE_TCHAR *[])
100 ACE_START_TEST (ACE_TEXT ("Timeprobe_Test"));
102 ACE_TIMEPROBE ("Starting Test");
104 for (int i = 0; i < 3; i++)
106 work (i);
107 ACE_TIMEPROBE (EVENT_ZERO + i);
110 ACE_TIMEPROBE ("Ending Test");
112 ACE_TIMEPROBE_PRINT;
114 ACE_END_TEST;
116 return 0;