Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Monitor_Control / Num_Threads_Monitor.cpp
blobc42fac4f0983d8042edb31097608037809bfc412
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"
7 #endif
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 namespace ACE
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)
26 , file_ptr_ (0)
27 , nthreads_ (0UL)
28 #endif
32 void
33 Num_Threads_Monitor::update ()
35 #if defined (ACE_HAS_WIN32_PDH)
36 this->update_i ();
37 this->receive (this->value_);
38 #elif defined (ACE_LINUX)
39 this->file_ptr_ = ACE_OS::fopen (ACE_TEXT ("/proc/self/status"),
40 ACE_TEXT ("r"));
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")));
47 return;
50 char *item = 0;
51 char *arg = 0;
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)
60 continue;
63 if (ACE_OS::strcmp (item, "Threads:") == 0)
65 sscanf (arg, "%lu", &this->nthreads_);
66 break;
70 /// Stores value and timestamp with thread-safety.
71 this->receive (static_cast<double> (this->nthreads_));
73 ACE_OS::fclose (this->file_ptr_);
74 #endif
77 const char*
78 Num_Threads_Monitor::default_name ()
80 return Num_Threads_Monitor::default_name_;
83 void
84 Num_Threads_Monitor::clear_i ()
86 #if defined (ACE_HAS_WIN32_PDH)
87 this->clear_impl ();
88 #endif
90 this->Monitor_Base::clear_i ();
95 ACE_END_VERSIONED_NAMESPACE_DECL
97 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */