-
Notifications
You must be signed in to change notification settings - Fork 6
/
lab_usage.awk
executable file
·119 lines (103 loc) · 3.69 KB
/
lab_usage.awk
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/awk -f
@include "mycolors.awk"
function print_row_separator()
{
printf("| %14s |","--------------");
# printf(" %3s + %3s + %3s |", "---", "---", "---");
printf(" %9s + %3s + %3s |", "---------", "---", "---");
printf("\n");
}
BEGIN {
FS="[ :|=,]";
print_row_separator()
printf("| %14s |","Username");
green_G = colour_str_custom("G", colour("Green"), 1);
blue_C = colour_str_custom("C", colour("Blue"), 1);
printf(" %27s | %3s | %3s |", sprintf("R (%s/%s)", blue_C, green_G), "PD", "CG");
printf("\n");
print_row_separator()
}
{
if ($1 == "G>") {
# for overcap jobs, assign lab arbitrarily
if ($14 == "overcap"){
lab=user_to_lab[$2]
}
else{
lab=$13
}
gpu_counts[lab][$2][$3]+=$12;
gpu_counts[lab][$2][$3,$4]+=$12;
gpu_counts[lab][$2]["R"]+=0;
gpu_counts[lab][$2]["PD"]+=0;
gpu_counts[lab][$2]["CG"]+=0;
cpu_counts[lab][$2][$3]+=$7;
cpu_counts[lab][$2][$3,$4]+=$7;
cpu_counts[lab][$2]["R"]+=0;
cpu_counts[lab][$2]["PD"]+=0;
cpu_counts[lab][$2]["CG"]+=0;
labs_to_gpus_used[lab][$3]+=$12;
labs_to_cpus_used[lab][$3]+=$7;
} else {
if ($5 == "gres/gpu") {
labs_to_gpus[$1] += $12;
labs_to_cpus[$1] += $4;
} else {
if ($1 != "overcap") {
user_to_lab[$2]=$1;
}
}
}
}
END {
for (lab in labs_to_gpus) {
if (lab == "guest-lab") {
continue;
}
print_str = sprintf(\
"[ %d/%d/%d ]",
labs_to_gpus_used[lab]["R"],
labs_to_gpus_used[lab]["PD"],
labs_to_gpus[lab])
printf("| %14s | %-21s |\n", lab, print_str);
print_row_separator()
if (lab in gpu_counts) {
for (name in gpu_counts[lab]){
cpu_per_gpu_use_str = "-"
if (gpu_counts[lab][name]["R"] > 0){
cpu_per_gpu_use = (1.0*cpu_counts[lab][name]["R"]) / gpu_counts[lab][name]["R"]
# cpu_per_gpu_use_str = sprintf("%.1f", cpu_per_gpu_use)
if (cpu_per_gpu_use >= 10.0) {
cpu_per_gpu_use_str = sprintf("%d", cpu_per_gpu_use)
} else {
cpu_per_gpu_use_str = sprintf("%.1f", cpu_per_gpu_use)
}
run_str = sprintf(\
" %s (%s) |",\
colour_int(gpu_counts[lab][name]["R"]),\
colour_str_custom(cpu_per_gpu_use_str, colour("Blue"), 3)\
)
} else {
run_str = sprintf(" %9s |", colour_int(gpu_counts[lab][name]["R"]))
}
printf("| %14s |",name);
# printf(" %3d |",gpu_counts[lab][name]["R"]);
# printf(" %3d |",gpu_counts[lab][name]["PD"]);
# printf(" %3d |",gpu_counts[lab][name]["CG"]);
# Colorized
# printf(\
# " %s (%s) |",\
# colour_int(gpu_counts[lab][name]["R"]),\
# colour_str_custom(cpu_per_gpu_use_str, colour("Blue"), 3)\
# );
printf(run_str);
printf(" %s |", colour_int(gpu_counts[lab][name]["PD"]));
printf(" %s |", colour_int(gpu_counts[lab][name]["CG"]));
# printf(" %s |", colour_int_blue(cpu_counts[lab][name]["R"]));
# printf(" %s |", colour_str_custom(cpu_per_gpu_use_str, colour("Blue"), 3));
printf("\n");
}
}
print_row_separator()
}
}