/* Title:	statTest.c
 * Description:	get system's information about cpu loading,memeory,hard disk
 * Author:	
 * Date:	
 */
#include "sysStat.h"

typedef struct SysInfo {
	cpuInfo myCpuInfo;
	memInfo myMemInfo;
	swapInfo mySwapInfo;
	hdiskInfo myHdiskInfo;
	procGrpInfo myProcGrpInfo;
} SysInfo;

#define UnitSleepTime	1
#define CpuTimeCount	10
#define MemTimeCount	10
#define SwapTimeCount	10
#define ProcTimeCount	60
#define HdiskTimeCount	3600

int main(int argc, char *argv[])
{
	int sleepCount = 0, i = 0;
	SysInfo sysInfo;
	char *procList = "commProc beatProc";
	sprintf(sysInfo.myProcGrpInfo.procNameList, "%s", procList);
	//printf("%s \n",sysInfo.myProcGrpInfo.procNameList);

	//load system info
	getCpuInfo(&(sysInfo.myCpuInfo));
	getMemInfo(&(sysInfo.myMemInfo));
	getSwapInfo(&(sysInfo.mySwapInfo));
	getHdiskInfo(&(sysInfo.myHdiskInfo));
	getProcGrpInfo(&(sysInfo.myProcGrpInfo));

	//update system info
	while (1) {
		sleep(1);
		sleepCount++;
		if (sleepCount % 1 == 0) {
			getCpuInfo(&(sysInfo.myCpuInfo));
		}

		if (sleepCount % 1 == 0) {
			getMemInfo(&(sysInfo.myMemInfo));
			getSwapInfo(&(sysInfo.mySwapInfo));
			getProcGrpInfo(&(sysInfo.myProcGrpInfo));
		}

		if (sleepCount % 1 == 0) {
			sleepCount = 0;
			getHdiskInfo(&(sysInfo.myHdiskInfo));
		}
		getNetworkStat();

		printf("cpuLoad    = %d %% \n", sysInfo.myCpuInfo.cpuLoad);
		printf("memTotal   = %lu  KB\n", sysInfo.myMemInfo.total);
		printf("memUsed    = %lu  KB\n", sysInfo.myMemInfo.used);
		printf("swapTotal  = %lu  KB\n", sysInfo.mySwapInfo.total);
		printf("swapUsed   = %lu  KB\n", sysInfo.mySwapInfo.used);
		printf("hdiskTotal = %lu  KB\n", sysInfo.myHdiskInfo.total);
		printf("hdiskUsed  = %lu  KB\n", sysInfo.myHdiskInfo.used);
		printf("procNum = %d \n", sysInfo.myProcGrpInfo.procNum);
		for (i = 0; i < sysInfo.myProcGrpInfo.procNum; i++) {
			if (sysInfo.myProcGrpInfo.procInfoArr[i].stat > 0) {
				printf("%s(%lu) is running..\n",
					   sysInfo.myProcGrpInfo.procInfoArr[i].procName,
					   sysInfo.myProcGrpInfo.procInfoArr[i].pid);
			} else {
				printf("%s(%lu) is stopped \n",
					   sysInfo.myProcGrpInfo.procInfoArr[i].procName,
					   sysInfo.myProcGrpInfo.procInfoArr[i].pid);
			}
		}
		printf("\n \n \n");
	}
	return (1);
}
