Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Control/Num_Threads_Monitor.h"
00004
00005 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
00006
00007 #if defined (linux)
00008 #include "ace/OS_NS_stdio.h"
00009 #endif
00010
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 namespace ACE
00014 {
00015 namespace Monitor_Control
00016 {
00017 const char* Num_Threads_Monitor::default_name_ =
00018 "OS/System/NumThreads";
00019
00020 Num_Threads_Monitor::Num_Threads_Monitor (const char* name)
00021 : Monitor_Base (name, Monitor_Control_Types::MC_NUMBER)
00022 #if defined (ACE_HAS_WIN32_PDH)
00023 , Windows_Monitor (ACE_TEXT ("\\System\\Threads"))
00024 #elif defined (linux)
00025 , file_ptr_ (0)
00026 , nthreads_ (0UL)
00027 #endif
00028 {
00029 }
00030
00031 void
00032 Num_Threads_Monitor::update (void)
00033 {
00034 #if defined (ACE_HAS_WIN32_PDH)
00035 this->update_i ();
00036 this->receive (this->value_);
00037 #elif defined (linux)
00038 this->file_ptr_ = ACE_OS::fopen (ACE_TEXT ("/proc/self/status"),
00039 ACE_TEXT ("r"));
00040
00041 if (this->file_ptr_ == 0)
00042 {
00043 ACE_ERROR ((LM_ERROR,
00044 ACE_TEXT ("Num threads - opening ")
00045 ACE_TEXT ("/proc/self/status failed\n")));
00046 return;
00047 }
00048
00049 char *item = 0;
00050 char *arg = 0;
00051
00052 while ((ACE_OS::fgets (buf_, sizeof (buf_), file_ptr_)) != 0)
00053 {
00054 item = ACE_OS::strtok (this->buf_, " \t\n");
00055 arg = ACE_OS::strtok (0, "\n");
00056
00057 if (item == 0 || arg == 0)
00058 {
00059 continue;
00060 }
00061
00062 if (ACE_OS::strcmp (item, "Threads:") == 0)
00063 {
00064 sscanf (arg, "%lu", &this->nthreads_);
00065 break;
00066 }
00067 }
00068
00069
00070 this->receive (static_cast<double> (this->nthreads_));
00071
00072 ACE_OS::fclose (this->file_ptr_);
00073 #endif
00074 }
00075
00076 const char*
00077 Num_Threads_Monitor::default_name (void)
00078 {
00079 return Num_Threads_Monitor::default_name_;
00080 }
00081
00082 void
00083 Num_Threads_Monitor::clear_i (void)
00084 {
00085 #if defined (ACE_HAS_WIN32_PDH)
00086 this->clear_impl ();
00087 #endif
00088
00089 this->Monitor_Base::clear_i ();
00090 }
00091 }
00092 }
00093
00094 ACE_END_VERSIONED_NAMESPACE_DECL
00095
00096 #endif