-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.c
102 lines (86 loc) · 2.96 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Copyright (C) 2023, Oracle and/or its affiliates. All rights reserved
*
* This file is part of libresource.
*
* libresource is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* libresource is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libresource. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <resource.h>
void print_meminfo()
{
struct memstat mem;
res_read(RES_MEM_INFOALL, &mem, sizeof(mem), NULL, 0, 0);
printf("MemTotal: %lu kB\n", mem.memtotal);
printf("\n");
}
void print_vmstat()
{
struct vmstat data;
unsigned long value;
res_read(RES_VMSTAT_INFO, &data, sizeof(data), NULL, 0, 0);
// Showing access of just the first element here:
printf("nr_free_pages %lu\n", data.nr_free_pages);
res_read(RES_VMSTAT_PGPGIN, &value, sizeof(value), NULL, 0, 0);
printf("RES_VMSTAT_PGPGIN: %lu\n",value);
res_read(RES_VMSTAT_PGPGOUT, &value, sizeof(value), NULL, 0, 0);
printf("RES_VMSTAT_PGPGOUT: %lu\n",value);
res_read(RES_VMSTAT_SWAPIN, &value, sizeof(value), NULL, 0, 0);
printf("RES_VMSTAT_SWAPIN: %lu\n",value);
res_read(RES_VMSTAT_SWAPOUT, &value, sizeof(value), NULL, 0, 0);
printf("RES_VMSTAT_SWAPOUT: %lu\n",value);
printf("\n");
}
void print_fs()
{
unsigned long long fs_value, val[3];
res_read(FS_AIONR, &fs_value, sizeof(fs_value), NULL, 0, 0);
printf("FS_AIONR : %Lu\n",fs_value);
res_read(FS_AIOMAXNR, &fs_value, sizeof(fs_value), NULL, 0, 0);
printf("FS_AIOMAXNR : %Lu\n",fs_value);
res_read(FS_FILENR, &val, sizeof(val), NULL, 0, 0);
printf("FS_FILENR : %Lu %Lu %Lu\n",val[0], val[1], val[2]);
res_read(FS_FILEMAXNR, &fs_value, sizeof(fs_value), NULL, 0, 0);
printf("FS_FILEMAXNR : %Lu\n",fs_value);
printf("\n");
}
void print_cpuinfo()
{
struct cpuinfo *cpu;
int cpu_num, i;
cpu_num = sysconf(_SC_NPROCESSORS_ONLN);
cpu = (struct cpuinfo *) malloc(cpu_num*sizeof(struct cpuinfo));
res_read(RES_CPU_INFO, cpu, (cpu_num*sizeof(struct cpuinfo)), NULL, 0, 0);
for (i = 0; i < cpu_num; i++) {
printf("processor\t: %u\n",cpu->processor);
printf("vendor_id\t: %s\n",cpu->vendor_id);
/* Keep accessing other fields in cpu-> */
cpu++;
printf("\n");
}
printf("\n");
}
int main(int argc, char **argv)
{
/* VMSTAT */
print_vmstat();
/* MEMINFO */
print_meminfo();
/* CPUINFO */
print_cpuinfo();
/* FS */
print_fs();
}