GetProcessList now cached for 3 seconds
authorAlex Kirhenshtein <alk@netxms.org>
Sun, 4 Aug 2013 20:15:48 +0000 (20:15 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Sun, 4 Aug 2013 20:15:48 +0000 (20:15 +0000)
src/agent/subagents/hpux/proc.cpp

index c95e382..3cd54e4 100644 (file)
@@ -22,6 +22,7 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <sys/pstat.h>
+#include <time.h>
 #include "system.h"
 #include "hpux.h"
 
 #define INFOTYPE_SUM             3
 
 
+//
+// Process cache
+//
+
+#define EXPIRATION               3
+
+static struct pst_status *m_processList = NULL;
+static time_t m_processListUpdated = 0;
+
 //
 // Handler for System.ProcessCount parameter
 //
@@ -62,6 +72,16 @@ static struct pst_status *GetProcessList(int *pnNumProcs)
 {
        int nSize = 0, nCount;
        struct pst_status *pBuffer = NULL;
+   time_t now;
+
+   if (m_processList != NULL)
+   {
+      now = time(NULL);
+      if (now < m_processListUpdated + EXPIRATION)
+      {
+         return m_processList;
+      }
+   }
        
        do
        {
@@ -80,6 +100,9 @@ static struct pst_status *GetProcessList(int *pnNumProcs)
                *pnNumProcs = nCount;
        }
 
+   m_processList = pBuffer;
+   m_processListUpdated = now;
+
        return pBuffer;
 }