-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmctl_test.c
56 lines (48 loc) · 1.34 KB
/
pmctl_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// gen by gpt4-turbo
unsigned long convertHexString(const char *input) {
const char *separator = "=";
char *token;
char *inputCopy = strdup(input);
if (!inputCopy) return 0;
token = strtok(inputCopy, separator);
if (token != NULL) {
token = strtok(NULL, separator);
if (token != NULL) {
char *end;
for (end = token + strlen(token) - 1; end >= token && (*end == ' ' || *end == '\n'); --end)
*end = '\0';
unsigned long number = (unsigned long)strtol(token, NULL, 16);
free(inputCopy);
return number;
}
}
free(inputCopy);
return 0;
}
unsigned long * get_media_writes() {
unsigned long * ret = (unsigned long *) malloc(12*sizeof(unsigned long));
FILE *fp;
char content[2000];
fp = popen("ipmctl show -performance | grep TotalMediaWrites", "r");
if (fp == NULL) {
printf("Failed to run ipmctl\n");
exit(1);
}
int index = 0;
while (fgets(content, sizeof(content), fp) != NULL) {
printf("%s", content);
unsigned long number = convertHexString(content);
ret[index] = number;
printf("%lu\n", number);
index++;
}
pclose(fp);
return ret;
}
int main()
{
return 0;
}