-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatus
executable file
·109 lines (98 loc) · 3.95 KB
/
status
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
#! /bin/sh
#
# Show the currently running KONECT-Analysis processes.
# This calls ps(1) and presents the results in a useful way.
#
# All shown runtimes are CPU times, not wall clock times.
#
# MECHANISM
#
# To show the time left for a task, a program outputs, at regular
# intervals, strings of the form
#
# [TIMESPEC left]
#
# where TIMESPEC is the time left in free form. The string does not
# need to be alone on a line.
#
# Additionally, each program that should be inspected in this way should
# be started with a logfile name as (any) positional argument, which
# must start with the value of $TMPDIR. This is done automatically by
# the wrappers {octave,matlab,julia}, but must be implemented by hand
# with other languages. This is the reason why certain C or Perl
# programs are passed a logfile name, even if they do not (yet) make use
# of it. In principle however, every program that has a long runtime
# should log such [... left] message to its logfile.
#
# Logfiles names have the general format
#
# $TMPDIR/$LETTER.$PROGRAM[.$PARAMETERS].log
#
# where $LETTER is a single letter denoting the programming language
# (usually the programming language's name first letter), $PROGRAM is
# the general name of the program being run, and [.$PARAMETERS] are
# optional parameters (such as the network name, etc.)
#
# BUGS
#
# * We don't manage the situation when the list is longer than the screen.
# Currently, we just make the window higher in that case.
# * The shown CPU percentage is as returned by ps(1), which gives the
# average CPU usage since the process was started. This is
# different (and less useful) to what top(1) is doing, which shows
# the CPU usage since the last screen update.
#
# Show all running Stu instances
# Note: ps -C is not POSIX
ps -C stu -o user,pid,pcpu,etime,cputime,command
printf '%s\n' -
# Format for the printf(1) command
format='%4s %13s %12s %13s %s\n'
# Header line
printf "$format" "%CPU" "MEM [KiB]" "TIME" "LEFT" "LOG"
TMPDIR=${TMPDIR-/tmp}
TMPDIR_esc=$(echo "$TMPDIR" | sed -E -e 's,/,\\/,g')
ps -A k-cputime -o pcpu,cputime,vsize,user,command |
sed -E -e '1d;/'"$TMPDIR_esc"'/!d' |
while IFS= read -r line
do
cpu=$(echo "$line" | sed -E -e 's,^\s*(\S+)\s.*$,\1,;s,\.[0-9]$,,')
vsize=$(echo "$line" | sed -E -e 's,^\s*\S+\s+\S+\s+(\S+)\s.*$,\1,' | sed -E -e '
s/^([^.]*[0-9])([0-9]{21}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{18}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{15}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{12}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{9}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{6}(\.|$))/\1,\2/
s/^([^.]*[0-9])([0-9]{3}(\.|$))/\1,\2/
')
time=$(echo "$line" | sed -E -e 's,^\s*,,' | cut -f 2 -d ' ' | sed -E -e 's,^[0:]*(.*....)$,\1,')
logfile=$(echo "$line" | sed -E -e 's,^.*\s('"$TMPDIR_esc"'\S+).*$,\1,')
command=$(echo "$line" | sed -E -e 's,^\s*\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s.*$,\1,')
command=$(basename "$command")
# Don't show clearly non-computational processes. For instance,
# 'less' is often used to look at logfiles, and would thus show
# up here because it has a logfile name as a positional argument
if [ "$command" = less ] || [ "$command" = more ] || [ "$command" = tail ] || [ "$command" = sed ] ; then
continue
fi
if printf "%s\n" "$command" | grep -E -q ^main.stu ; then
continue
fi
# This refers to stu-utils/output-finally
if printf "%s\n" "$line" | grep -E -q 'output-finally' ;
then
continue
fi
# 'tac' reports an error if the logfile was not (yet)
# created. Ignore this error.
left=$(tac "$logfile" 2>/dev/null | sed -E -e '/left]/!d;s,^.*\[(.*) left\].*$,\1,;q')
if [ -z "$left" ] ; then
# If there is a "time left" information available
# for a sub-task, show that prefixed with '+'.
left=$(tac "$logfile" 2>/dev/null | sed -E -e '/left}/!d;s,^.*\{(.*) left\}.*$,+\1,;q')
fi
logfile_color=$(echo "$logfile" | sed -E -e 's,^(.*)/([^.]+)\.(.+).log$,\1/\2.[1m\3[m.log,')
printf "$format" "$cpu" "$vsize" "$time" "$left" "$logfile_color"
done
printf '%s\n' -