1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//=============================================================================
/**
* @file Timeprobe_Test.cpp
*
* $Id: Timeprobe_Test.cpp 93638 2011-03-24 13:16:05Z johnnyw $
*
* This is a simple test of ACE Timeprobes.
*
*
* @author Irfan Pyarali <irfan@cs.wustl.edu>
*/
//=============================================================================
//#define ACE_ENABLE_TIMEPROBES
//#define ACE_MT_TIMEPROBES
//#define ACE_TSS_TIMEPROBES
#include "test_config.h"
#include "ace/Singleton.h"
#include "ace/Synch_Traits.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Null_Mutex.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Timeprobe.h"
#if defined (ACE_ENABLE_TIMEPROBES)
static const char *events_descriptions_0[] =
{
"Event Zero",
"Event One",
"Event Two",
"Event Three",
"Event Four",
"Event Five",
"Event Six",
"Event Seven",
"Event Eight",
"Event Nine"
};
enum
{
EVENT_ZERO = 0,
EVENT_ONE,
EVENT_TWO,
EVENT_THREE,
EVENT_FOUR,
EVENT_FIVE,
EVENT_SIX,
EVENT_SEVEN,
EVENT_EIGHT,
EVENT_NINE
};
static const char *events_descriptions_1[] =
{
"Work start",
"Work end"
};
enum
{
WORK_START = 100,
WORK_END
};
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_1, WORK_START);
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_0, EVENT_ZERO);
#endif /* ACE_ENABLE_TIMEPROBES */
static void
work (int time)
{
ACE_FUNCTION_TIMEPROBE (WORK_START);
ACE_OS::sleep (time);
}
#if !defined (ACE_HAS_PURIFY)
// Test creation of ACE_Singletons during static object construction.
// Timeprobes can do that, when they're enabled. Purify would notice
// the memory in use at program termination.
static int
create_singleton ()
{
int *i = ACE_Singleton <int, ACE_SYNCH_RECURSIVE_MUTEX>::instance ();
*i = 3;
return *i;
}
int static_singleton_creator = create_singleton ();
#endif /* ! ACE_HAS_PURIFY */
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Timeprobe_Test"));
ACE_TIMEPROBE ("Starting Test");
for (int i = 0; i < 3; i++)
{
work (i);
ACE_TIMEPROBE (EVENT_ZERO + i);
}
ACE_TIMEPROBE ("Ending Test");
ACE_TIMEPROBE_PRINT;
ACE_END_TEST;
return 0;
}
|