-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremaining-times
executable file
·76 lines (63 loc) · 2.04 KB
/
remaining-times
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
#!/usr/bin/env Rscript
library(data.table)
library(BBmisc)
s = system3("squeue", stdout = TRUE, args = "-u $USER -o '%l %L %t'")$output
if (length(s) == 0) {
cat("No jobs on system!\n")
} else {
tab = read.table(textConnection(s), header = TRUE, stringsAsFactors = FALSE)
tab = as.data.table(tab)
# time conversion from character to seconds
factors = c(24 * 60 * 60, 60 * 60, 60, 1)
toSeconds = function(x) {
z = strsplit(x, "-")[[1]]
l = length(z)
z2 = strsplit(z[l], ":")[[1]]
l2 = length(z2)
z3 = numeric(4)
z3[(5 - l2):4] = as.numeric(z2)
if (l > 1) z3[1] = as.numeric(z[1])
res = sum(z3 * factors)
return(res)
}
left = sapply(tab$TIME_LEFT, toSeconds)
tab$TIME_LEFT = left
# queue names
limit = sapply(tab$TIME_LIMIT, toSeconds)
walltimes = c(2 * 3600, 8 * 3600, 48 * 3600, 672 * 3600)
names = c("short", "med", "long", "ultralong")
names.limit = sapply(limit, function(x) names[min(which(x <= walltimes))])
tab$TIME_LIMIT = names.limit
tab1 = tab[, list(
Running = sum(ST == "R"),
Pending = sum(ST == "PD")
), by = c("TIME_LIMIT")]
colnames(tab1)[1] = "Queue"
cat("Number of running and pending jobs:\n")
print(tab1, row.names = FALSE)
tab.r = tab[ST == "R", ]
if (nrow(tab.r) > 0) {
tab2 = tab.r[, list(
Min = min(TIME_LEFT),
Mean = round(mean(TIME_LEFT)),
Median = round(median(TIME_LEFT)),
Max = max(TIME_LEFT)
), by = c("TIME_LIMIT")]
# better units depending on times
time.units = choices = c("days", "hours", "minutes", "seconds")
tus = sapply(tab2$Median, function(m) {
if (m < 60) return(4)
else if (m < 60 * 60) return(3)
else if (m < 24 * 60 * 60) return(2)
else return(1)
})
for (i in seq_along(tus)) {
tab2[i, 2:5] = round(tab2[i, 2:5] / factors[tus[i]], 2)
}
tab3 = cbind(tab2, Unit = time.units[tus])
colnames(tab1)[1] = colnames(tab3)[1] = "Queue"
cat("\n")
cat("Remaining times of running jobs:\n")
print(tab3, row.names = FALSE)
}
}