forked from gary/ems
2
0
Fork 0
sun_ems/ems_c/kernel/kit_core.h

66 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************************
* @copyright 1997-2050, . POWER SUPPLY CO., LTD.
* @file kit_core.h
* @brief xx功能
* @author Gary
* @date 2024-09-21
* @remark
*****************************************************************************/
#ifndef KIT_CORE_H
#define KIT_CORE_H
#define RUNIN_MAC 0 // 实机运行
#define RUNIN_VM 1 // 虚拟机
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "kit_log.h"
// 定义一个结构体表示一个 CPU 时间
typedef struct cpu_time {
uint64_t user; // 用户态时间
uint64_t nice; // 低优先级用户态时间
uint64_t system; // 内核态时间
uint64_t idle; // 空闲时间
uint64_t iowait; // 等待 I/O 完成时间
uint64_t irq; // 硬中断时间
uint64_t softirq;// 软中断时间
uint64_t steal; // 被其他虚拟机偷走的时间
} cpu_time_t;
// 定义一个结构体表示内存信息
typedef struct memory_info {
uint64_t total; // 总内存大小
uint64_t free; // 空闲内存大小
uint64_t available; // 可用内存大小
uint64_t buffers; // 缓冲区内存大小
uint64_t cached; // 缓存内存大小
} memory_info_t;
/*****************************************************************************
* @brief 通过管道执行shell命令 (使用 system)
* @param[in] cmdshell命令
* @param[in] buffer读取执行结果
* @param[in] buffer_size读取执行结果长度
* @return 1-执行错误 0-执行成功
*****************************************************************************/
int kit_popen_exec(const char *cmd, char* buffer, size_t buffer_size);
/*****************************************************************************
* @brief 获取EMS的SN号
* @param[in] serial返回SN号
* @return 1-执行错误 0-执行成功
*****************************************************************************/
int kit_get_ems_sn(char serial[128]);
// 获取系统 CPU 时间
void getSysCpuTime(cpu_time_t *time);
// 获取指定进程的 CPU 时间
void getProCpuTime(cpu_time_t *time, pid_t pid);
// 获取内存信息的函数
void getMemInfo(memory_info_t *info);
// 计算当前进程内存占用
double calculateProcMemUsage(memory_info_t info, pid_t pid);
#endif // KIT_CORE_H