Re: "System.CPU.Usage"

From: Alex Kirhenshtein <alk_at_DOMAIN_REMOVED>
Date: Tue, 24 Apr 2007 15:41:40 +0300

Lobahin Ilya wrote:
>
> Linux zebra 2.6.17-gentoo-r4 #2 SMP Thu Aug 24 14:40:29 MSD 2006 i686 Intel(R) Xeon(TM) CPU 3.40GHz GNU/Linux
>
> В Багтрекере вроде вот эта задача http://www.netxms.org/bugtrack/view.php?id=128
>

Ага, неуловимый баг.

В аттаче патчик, который добавляет много дебага в cpu usage и около,
попробуй наложить, когда будет время. Дебаг пишется прямо в stdout, так
что запускать лучше через tee. В принципе, достаточно запустить и разок
nxget-ом попробовать получить cpu usage.

wbr, alex.

diff -ur netxms-0.2.16/src/agent/subagents/linux/system.cpp netxms-0.2.16.new/src/agent/subagents/linux/system.cpp
--- netxms-0.2.16/src/agent/subagents/linux/system.cpp 2007-02-05 13:28:21.000000000 +0200
+++ netxms-0.2.16.new/src/agent/subagents/linux/system.cpp 2007-04-24 15:33:56.000000000 +0300
@@ -352,8 +352,15 @@
 static float m_cpuUsage[CPU_USAGE_SLOTS];
 static int m_currentSlot = 0;
 
+#define B(x) printf("### Before " x "(), thread=%08x, line %d\n", pthread_self(), __LINE__);
+#define A(x) printf("### After " x "(), thread=%08x, line %d\n", pthread_self(), __LINE__);
+#define MutexLock(x, y) {B("MutexLock"); MutexLock(x, y); A("MutexLock");}
+#define MutexUnlock(x) {B("MutexUnlock"); MutexUnlock(x);A("MutexUnlock");}
+#define MutexDestroy(x) {B("MutexDestroy"); MutexDestroy(x);A("MutexDestroy");}
+
 static void CpuUsageCollector()
 {
+ printf("### CpuUsageCollector() IN\n"); fflush(stdout);
         FILE *hStat = fopen("/proc/stat", "r");
 
         if (hStat != NULL)
@@ -397,10 +404,14 @@
                 }
                 fclose(hStat);
         }
+
+ printf("### CpuUsageCollector() OUT\n"); fflush(stdout);
 }
 
 static THREAD_RESULT THREAD_CALL CpuUsageCollectorThread(void *pArg)
 {
+ printf("### CpuUsageCollectorThread() IN\n"); fflush(stdout);
+
         setlocale(LC_NUMERIC, "C");
         while (m_stopCollectorThread == false)
         {
@@ -412,6 +423,8 @@
                 ThreadSleepMs(1000); // sleep 1 second
         }
 
+ printf("### CpuUsageCollectorThread() OUT\n"); fflush(stdout);
+
         return THREAD_OK;
 }
 
@@ -419,7 +432,11 @@
 {
         int i;
 
+ printf("### StartCpuUsageCollector() IN\n"); fflush(stdout);
+
+ B("MutexCreate");
         m_cpuUsageMutex = MutexCreate();
+ A("MutexCreate");
 
         for (i = 0; i < CPU_USAGE_SLOTS; i++)
         {
@@ -444,16 +461,27 @@
 
         // start collector
         m_cpuUsageCollector = ThreadCreateEx(CpuUsageCollectorThread, 0, NULL);
+
+ printf("### StartCpuUsageCollector() OUT\n"); fflush(stdout);
 }
 
 void ShutdownCpuUsageCollector(void)
 {
+ printf("### ShutdownCpuUsageCollector() IN\n"); fflush(stdout);
+
         MutexLock(m_cpuUsageMutex, INFINITE);
         m_stopCollectorThread = true;
         MutexUnlock(m_cpuUsageMutex);
 
+ printf("### ShutdownCpuUsageCollector() ThreadJoin()\n"); fflush(stdout);
+
         ThreadJoin(m_cpuUsageCollector);
+
+ printf("### ShutdownCpuUsageCollector() joined\n"); fflush(stdout);
+
         MutexDestroy(m_cpuUsageMutex);
+
+ printf("### ShutdownCpuUsageCollector() OUT\n"); fflush(stdout);
 }
 
 LONG H_CpuUsage(char *pszParam, char *pArg, char *pValue)
@@ -462,6 +490,8 @@
         int i;
         int count;
 
+ printf("### H_CpuUsage() IN\n"); fflush(stdout);
+
         MutexLock(m_cpuUsageMutex, INFINITE);
 
         switch (CAST_FROM_POINTER(pArg, int))
@@ -495,6 +525,8 @@
 
         MutexUnlock(m_cpuUsageMutex);
 
+ printf("### H_CpuUsage() OUT\n"); fflush(stdout);
+
         return SYSINFO_RC_SUCCESS;
 }
 
Received on Tue Apr 24 2007 - 15:41:40 EEST

This archive was generated by hypermail 2.2.0 : Tue Apr 24 2007 - 15:41:36 EEST