sync from windows

This commit is contained in:
Your Name
2021-07-21 17:55:22 +08:00
parent 34fe72877e
commit 499a738901
9 changed files with 64 additions and 55 deletions
+21 -5
View File
@@ -2,22 +2,38 @@
// Created by Iain on 2021/7/17.
//
#include "SystemInfo.h"
#include<stdio.h>
#include <string.h>
#define BUFFER_SIZE_MEMINFO 128
#define SYSTEM_CPU_INFO_PATH "/proc/stat"
#define SYSTEM_MEM_INFO_PATH "/proc/meminfo"
void updateSystemMem(unsigned int *all, unsigned int *fre, float *useage) {
void updateSystemCPU(Sys_CPU_Time *cpuInfo) {
char buf[BUFFER_SIZE_MEMINFO]; /*缓冲区*/
FILE *fp; /*文件指针*/
FILE *fp; /*文件指针*/
if ((fp = fopen(SYSTEM_CPU_INFO_PATH, "r")) == NULL) {
perror("fail to read /proc/meminfo");
return;
}
fgets(buf, BUFFER_SIZE_MEMINFO, fp);
sscanf(buf, "cpu: %u kB", cpuInfo->user, cpuInfo->nice, cpuInfo->system, cpuInfo->idle);
*useage = 1 - (float) *fre / *all;
return;
}
void updateSystemMem(Sys_Mem *memInfo) {
char buf[BUFFER_SIZE_MEMINFO]; /*缓冲区*/
FILE *fp; /*文件指针*/
if ((fp = fopen(SYSTEM_MEM_INFO_PATH, "r")) == NULL) {
perror("fail to read /proc/meminfo");
return;
}
fgets(buf, BUFFER_SIZE_MEMINFO, fp);
sscanf(buf, "MemTotal: %u kB", all);
sscanf(buf, "MemTotal: %u kB", memInfo->All);
fgets(buf, BUFFER_SIZE_MEMINFO, fp);
sscanf(buf, "MemFree %u kB", fre);
*useage = 1 - (float) *fre / *all;
sscanf(buf, "MemFree %u kB", memInfo->Free);
memInfo->Usage = 1 - (float) memInfo->Free / memInfo->All;
return;
}
+6 -13
View File
@@ -5,25 +5,18 @@
#ifndef ATOP_SYSTEMINFO_H
#define ATOP_SYSTEMINFO_H
typedef struct {
typedef struct Sys_CPU_Time_ {
float Usage;
unsigned long user;
unsigned long nice;
unsigned long system;
unsigned long idle;
} Total_CPU_Time;
} Sys_CPU_Time;
struct memGlobal {
typedef struct Sys_Mem_ {
float Usage;
unsigned int All;
float Usage;
unsigned int Free;
} memG;
struct cpuGlobal {
unsigned long user;
unsigned long nice;
unsigned long system;
unsigned long idle;
float Usage;
} cpuG;
} Sys_Mem;
#endif //ATOP_SYSTEMINFO_H