Compare commits
17 Commits
main
...
dev_offlin
| Author | SHA1 | Date |
|---|---|---|
|
|
937a5ac1d0 | 6 days ago |
|
|
4c36c7534c | 1 week ago |
|
|
aaac47868f | 2 weeks ago |
|
|
e47a221978 | 2 weeks ago |
|
|
c321a118d5 | 2 weeks ago |
|
|
61731e1d38 | 2 weeks ago |
|
|
eba708f32a | 2 weeks ago |
|
|
b535bc481e | 2 weeks ago |
|
|
8728bbdb68 | 2 weeks ago |
|
|
29086815bc | 2 weeks ago |
|
|
036d19bbe6 | 3 weeks ago |
|
|
0857847444 | 3 weeks ago |
|
|
c1f4a2b451 | 3 weeks ago |
|
|
0afe6c80a6 | 3 weeks ago |
|
|
18a1394759 | 3 weeks ago |
|
|
44ce8cc61c | 3 weeks ago |
|
|
546ce62fe6 | 3 weeks ago |
@ -0,0 +1,50 @@
|
||||
#ifndef _MEM_MONITOR_H_
|
||||
#define _MEM_MONITOR_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
// 获取当前进程 RSS (物理内存) 使用量,单位 MB
|
||||
static inline long getRSS_KB()
|
||||
{
|
||||
long rss = 0;
|
||||
FILE *fp = fopen("/proc/self/status", "r");
|
||||
if (!fp) return -1;
|
||||
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "VmRSS:", 6) == 0)
|
||||
{
|
||||
// 格式: "VmRSS: 12345 kB"
|
||||
const char *p = line + 6;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
rss = atol(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return rss;
|
||||
}
|
||||
|
||||
// 获取当前进程内存使用,打印格式化日志
|
||||
static inline void printMemUsage(const char *tag, const char *extra)
|
||||
{
|
||||
long rss = getRSS_KB();
|
||||
struct rusage usage;
|
||||
getrusage(RUSAGE_SELF, &usage);
|
||||
printf("[MEM] %-30s | VmRSS: %6ld MB | maxRSS: %6ld MB | %s\n",
|
||||
tag, rss / 1024, usage.ru_maxrss / 1024, extra ? extra : "");
|
||||
}
|
||||
|
||||
// 获取产品检测 pipeline 队列深度信息快照
|
||||
#define MEM_LOG(tag, fmt, ...) \
|
||||
do { \
|
||||
long _rss = getRSS_KB(); \
|
||||
printf("[MEM] %-30s | VmRSS: %6ld MB | " fmt "\n", tag, _rss / 1024, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#endif // _MEM_MONITOR_H_
|
||||
Loading…
Reference in new issue