41 #include "safec_lib.h"
43 GHashTable* hostIf_DeviceProcessStatusInterface::ifHash = NULL;
44 GMutex* hostIf_DeviceProcessStatusInterface::m_mutex = NULL;
56 ifHash = g_hash_table_new(NULL,NULL);
65 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create Ethernet Interface instance..\n");
67 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
72 GList* hostIf_DeviceProcessStatusInterface::getAllInstances()
75 return g_hash_table_get_keys(ifHash);
83 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
88 void hostIf_DeviceProcessStatusInterface::closeAllInstances()
92 GList* tmp_list = g_hash_table_get_values (ifHash);
97 tmp_list = tmp_list->next;
103 void hostIf_DeviceProcessStatusInterface::getLock()
107 m_mutex = g_mutex_new();
109 g_mutex_lock(m_mutex);
112 void hostIf_DeviceProcessStatusInterface::releaseLock()
114 g_mutex_unlock(m_mutex);
117 hostIf_DeviceProcessStatusInterface::hostIf_DeviceProcessStatusInterface(
int devid)
120 bCalledCPUUsage =
false;
121 bCalledProcessNumberOfEntries =
false;
123 backupProcessNumberOfEntries = 0;
126 int hostIf_DeviceProcessStatusInterface::getProcessStatusCPUUsage() {
129 char cmd[64] = {
'\0'};
131 char resultBuffer[1024]= {
'\0'};
132 unsigned long total_jiffies_1 = 0, total_jiffies_2 = 0;
133 unsigned long work_jiffies_1 = 0, work_jiffies_2 = 0;
134 long long unsigned int mUser = 0, mNice = 0, mSystem = 0, mIdle = 0, mIOwait = 0, mIrq = 0, mSoftirq = 0;
135 unsigned int uiCpuUsage = 0;
136 unsigned int temp = 0;
138 memset(cmd,
'\0',
sizeof(cmd));
139 rc=strcpy_s(cmd,
sizeof(cmd),
"grep '^cpu ' /proc/stat");
147 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error popen\n", __FUNCTION__);
151 if(fgets(resultBuffer,1024,fp)!=NULL) {
152 sscanf(resultBuffer,
"%*s %llu %llu %llu %llu %llu %llu %llu",&mUser,&mNice,&mSystem,&mIdle, &mIOwait, &mIrq, &mSoftirq);
158 total_jiffies_1 = mUser + mNice + mSystem + mIdle + mIOwait + mIrq + mSoftirq;
159 work_jiffies_1 = mUser + mNice + mSystem;
166 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error popen\n", __FUNCTION__);
170 if(fgets(resultBuffer,1024,fp)!=NULL) {
171 sscanf(resultBuffer,
"%*s %llu %llu %llu %llu %llu %llu %llu",&mUser,&mNice,&mSystem,&mIdle, &mIOwait, &mIrq, &mSoftirq);
176 total_jiffies_2 = mUser + mNice + mSystem + mIdle + mIOwait + mIrq + mSoftirq;
177 work_jiffies_2 = mUser + mNice + mSystem;
179 temp = total_jiffies_2 - total_jiffies_1;
183 uiCpuUsage = ((work_jiffies_2 - work_jiffies_1)*100)/(temp);
185 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): CpuUsage = [%u]\n", __FUNCTION__, uiCpuUsage);
210 int uiCpuUsage = getProcessStatusCPUUsage();
215 stMsgData->
paramtype = hostIf_IntegerType;
217 if(bCalledCPUUsage && pChanged &&(backupCPUUsage != uiCpuUsage))
221 bCalledCPUUsage =
true;
222 backupCPUUsage = uiCpuUsage;