77#
88# Boolean options:
99# -h,--help Print this text.
10+ # --no-procs Don't print the number of sccache processes
11+ # --no-stats Don't print the sccache stats
12+ # --no-temps Don't print the number of sccache tempfiles
1013#
1114# Options that require values:
1215# -c|--col-width <num> Max column width in number of characters.
1316# String columns wider than this will be truncated with "...".
1417# (default: $COLUMNS)
1518# -f|--format (csv|tsv|json) The `sccache --dist-status` output format.
16- # (default: "json")
19+ # (default: "tsv")
20+ # -w,--watch <num> Watch status every <num> seconds (or 1s if <num> is unspecified).
1721#
1822
1923_sccache_dist_status () {
@@ -26,18 +30,41 @@ _sccache_dist_status() {
2630 # shellcheck disable=SC1091
2731 . devcontainer-utils-debug-output ' devcontainer_utils_debug' ' sccache sccache-dist-status' ;
2832
29- f=" ${f:- ${format:- json} } " ;
30- c=" ${c:- ${col_width:- ${COLUMNS:- 1000000000} } } " ;
33+ if test ${# w[@]} -gt 0 && ! test -n " ${w: +x} " ; then
34+ w=" 1" ;
35+ fi
3136
32- # Print current dist status to verify we're connected
33- sccache 2> /dev/null --dist-status \
34- | {
35- # Passthrough if the format is json
36- if test " $f " = json; then
37- cat - <( echo)
38- else
37+ if ! test -n " ${__SKIP_WATCH: +x} " && test -n " ${w: +x} " ; then
38+ __SKIP_WATCH=1 watch -n " $w " devcontainer-utils-sccache-dist-status " ${@ } " ;
39+ else
3940
40- cat - | jq -r -f <( cat << EOF
41+ f=" ${f:- ${format:- tsv} } " ;
42+ c=" ${c:- ${col_width:- ${COLUMNS:- 1000000000} } } " ;
43+
44+ if [[ " $f " != json ]] && ! test -n " ${no_procs: +x} " ; then
45+ echo " sccache procs: $( pgrep sccache | wc -l) "
46+ fi
47+
48+ if [[ " $f " != json ]] && ! test -n " ${no_temps: +x} " ; then
49+ echo -n " preprocessed tempfiles: "
50+ echo -n " $( ls -All /tmp/.sccache_temp/.tmp* 2> /dev/null | wc -l) "
51+ echo " ($( du -ch /tmp/.sccache_temp/.tmp* 2> /dev/null | tail -n1 | cut -f1) )"
52+
53+ echo -n " nvcc internal tempfiles: "
54+ echo -n " $( ls -All /tmp/.sccache_temp/nvcc/* /* 2> /dev/null | wc -l) "
55+ echo " ($( du -ch /tmp/.sccache_temp/nvcc/* 2> /dev/null | tail -n1 | cut -f1) )"
56+ echo
57+ fi
58+
59+ # Print current dist status to verify we're connected
60+ sccache 2> /dev/null --dist-status \
61+ | {
62+ # Passthrough if the format is json
63+ if test " $f " = json; then
64+ cat - <( echo)
65+ else
66+
67+ cat - | jq -r -f <( cat << EOF
4168 def truncate_val: (
4269 . as \$ x
4370 | \$ x | length as \$ l
@@ -47,7 +74,7 @@ _sccache_dist_status() {
4774 end
4875 );
4976 def info_to_row: {
50- time: now | floor ,
77+ time: now | strflocaltime("%X") ,
5178 type: (.type // "server"),
5279 id: .id,
5380 servers: (if .servers == null then "-" else (.servers | length) end),
@@ -57,36 +84,47 @@ _sccache_dist_status() {
5784 loading: .jobs.loading,
5885 pending: .jobs.pending,
5986 running: .jobs.running,
87+ max: ((.max_job_age // 0) | tostring | . + "s"),
6088 accepted: .jobs.accepted,
6189 finished: .jobs.finished,
62- u_time : ((.u_time // 0) | tostring | . + "s")
90+ seen : ((.u_time // 0) | tostring | . + "s"),
6391 };
6492
6593 .SchedulerStatus as [\$ x, \$ y] | [
66- (\$ y + { id: \$ x, type: "scheduler", u_time: (\$ y.servers // {} | map(.u_time) | min | . // "-" | tostring) }),
94+ (\$ y + { id: \$ x, type: "scheduler", u_time: (\$ y.servers // {} | map(.u_time) | min | . // "-" | tostring), max_job_age: ( \$ y.servers // {} | map(.u_time + .max_job_age) | max | . // "-" | tostring) }),
6795 (\$ y.servers // [] | sort_by(.id)[])
6896 ]
6997 | map(info_to_row) as \$ rows
7098 | (\$ rows[0] | keys_unsorted) as \$ cols
7199 | (\$ rows | map(. as \$ row | \$ cols | map(\$ row[.] | truncate_val))) as \$ rows
72100 | (\$ cols | map(truncate_val)), \$ rows[] | @csv
73101EOF
74- )
75- fi
76- } \
77- | {
78- # Passthrough if the format is csv or json
79- # Otherwise, transform the csv into a tsv.
80- if test " $f " = tsv; then
81- if [[ " $( grep DISTRIB_RELEASE= /etc/lsb-release | cut -d= -f2) " > " 20.04" ]]; then
82- cat - | sed ' s/\"//g' | column -t -s, -R $( seq -s, 1 13)
102+ )
103+ fi
104+ } \
105+ | {
106+ # Passthrough if the format is csv or json
107+ # Otherwise, transform the csv into a tsv.
108+ if test " $f " = tsv; then
109+ if [[ " $( grep DISTRIB_RELEASE= /etc/lsb-release | cut -d= -f2) " > " 20.04" ]]; then
110+ cat - | sed ' s/\"//g' | column -t -s, -R $( seq -s, 1 14)
111+ else
112+ cat - | sed ' s/\"//g' | column -t -s,
113+ fi
114+ else
115+ cat -
116+ fi
117+ }
118+
119+ if ! test -n " ${no_stats: +x} " ; then
120+ echo
121+ if test " $f " = json; then
122+ sccache --show-stats --stats-format json
83123 else
84- cat - | sed ' s/\"//g ' | column -t -s,
124+ sccache --show-stats
85125 fi
86- else
87- cat -
88126 fi
89- }
127+ fi
90128}
91129
92130_sccache_dist_status " $@ " < & 0;
0 commit comments