1 #include "ace/Monitor_Control/Num_Threads_Monitor.h"
3 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
5 #if defined (ACE_LINUX)
6 #include "ace/OS_NS_stdio.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 namespace Monitor_Control
18 const char* Num_Threads_Monitor::default_name_
=
19 "OS/System/NumThreads";
21 Num_Threads_Monitor::Num_Threads_Monitor (const char* name
)
22 : Monitor_Base (name
, Monitor_Control_Types::MC_NUMBER
)
23 #if defined (ACE_HAS_WIN32_PDH)
24 , Windows_Monitor (ACE_TEXT ("\\System\\Threads"))
25 #elif defined (ACE_LINUX)
33 Num_Threads_Monitor::update ()
35 #if defined (ACE_HAS_WIN32_PDH)
37 this->receive (this->value_
);
38 #elif defined (ACE_LINUX)
39 this->file_ptr_
= ACE_OS::fopen (ACE_TEXT ("/proc/self/status"),
42 if (this->file_ptr_
== 0)
44 ACELIB_ERROR ((LM_ERROR
,
45 ACE_TEXT ("Num threads - opening ")
46 ACE_TEXT ("/proc/self/status failed\n")));
53 while ((ACE_OS::fgets (buf_
, sizeof (buf_
), file_ptr_
)) != 0)
55 item
= ACE_OS::strtok (this->buf_
, " \t\n");
56 arg
= ACE_OS::strtok (0, "\n");
58 if (item
== 0 || arg
== 0)
63 if (ACE_OS::strcmp (item
, "Threads:") == 0)
65 sscanf (arg
, "%lu", &this->nthreads_
);
70 /// Stores value and timestamp with thread-safety.
71 this->receive (static_cast<double> (this->nthreads_
));
73 ACE_OS::fclose (this->file_ptr_
);
78 Num_Threads_Monitor::default_name ()
80 return Num_Threads_Monitor::default_name_
;
84 Num_Threads_Monitor::clear_i ()
86 #if defined (ACE_HAS_WIN32_PDH)
90 this->Monitor_Base::clear_i ();
95 ACE_END_VERSIONED_NAMESPACE_DECL
97 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */