-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.c
More file actions
44 lines (38 loc) · 1 KB
/
Copy pathoutput.c
File metadata and controls
44 lines (38 loc) · 1 KB
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
#include <stdio.h>
#include "psmem.h"
void printHeader(void) {
printf(" Private + Shared = RAM used\tProgram\n\n");
}
void printTotal(double total) {
printf("---------------------------------\n");
printf("%24s"," ");
printFormatSize(total);
printf("\n=================================\n");
}
void printFormatSize(double rawSize) {
const char* const sizes[] = {"KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"};
int maxOrder = sizeof(sizes) / sizeof(sizes[0]);
int order = 0;
while (rawSize >= 1000 && order < maxOrder) {
rawSize /= 1024.0;
order++;
}
/* our memory is higher than YiB */
if (order == maxOrder) {
printf("%9s","MEMOUT");
} else {
printf("%5.1f %3s", rawSize, sizes[order]);
}
}
void printSizes(struct program p) {
printFormatSize(p.private_mem);
printf(" + ");
printFormatSize(p.shared_mem);
printf(" = ");
printFormatSize(p.private_mem + p.shared_mem);
printf("\t%.*s",NAME_SIZE - 1, p.name);
if (p.count > 0) {
printf(" (%d)", p.count + 1);
}
printf("\n");
}