1 #include "ace/OS_NS_unistd.h"
3 #include "ace/Monitor_Control/Monitor_Control.h"
5 #include "examples/Monitor/MC_Test_Utilities.h"
7 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
9 /// Subclass of ACE_Task_Base, meaning that the override of
10 /// the svc() method below will run in a new thread when
11 /// activate() is called on a class instance.
12 class Monitor_Checker
: public ACE_Task_Base
17 /// Get an instance of the MC service singleton.
18 MC_ADMINMANAGER
* mgr
=
19 ACE_Dynamic_Service
<MC_ADMINMANAGER
>::instance ("MC_ADMINMANAGER");
21 /// Call on the administrator class to look up the desired monitors.
22 ACE::Monitor_Control::Monitor_Base
*memory_monitor
=
23 mgr
->admin ().monitor_point ("OS/Memory/TotalUsage");
25 if (memory_monitor
!= 0)
27 /// Query each monitor for its data every 2 seconds, and call the
28 /// appropriate display function.
29 for (int i
= 0; i
< 10; ++i
)
33 Monitor_Control_Types::Data
data (memory_monitor
->type ());
34 memory_monitor
->retrieve (data
);
35 MC_Test_Utilities::display_memory_usage (data
);
38 memory_monitor
->remove_ref ();
45 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */
48 ACE_TMAIN (int /* argc */, ACE_TCHAR
* /* argv */ [])
50 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
52 /// Set the timer for memory usage check at 2 sec.
53 Monitor_Base
*memory_usage_monitor
=
54 create_os_monitor
<MEMORY_USAGE_MONITOR
> (0, ACE_Time_Value (2));
56 /// Runs the reactor's event loop in a separate thread so the timer(s)
57 /// can run concurrently with the application.
58 START_PERIODIC_MONITORS
;
60 /// Run the monitor checker in a separate thread.
61 Monitor_Checker monitor_checker
;
62 monitor_checker
.activate ();
64 char * str_array
[5] = {0};
66 for (int i
= 0; i
< 10; ++i
)
70 /// Allocate a large string in each of the first 5 loops,
71 /// free them in the last 5 loops.
74 str_array
[i
] = new char[1024*1024*10];
78 delete [] str_array
[i
- 5];
82 /// End the reactor's event loop, stopping the timer(s).
83 STOP_PERIODIC_MONITORS
;
85 memory_usage_monitor
->remove_ref ();
87 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */