X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=i_s%2Fpl_by_user.go;h=009841706db73acc344bca58b5f1ebc27f86b7a9;hb=9c17baa1e5fb1582c5bbed49280a9ee672142332;hp=f5bd83ff042e63ef317011d91bc2a4175c2483a5;hpb=d38bc6ef7c4b5a914e5c3e492c1efdc84944fbd1;p=pstop.git diff --git a/i_s/pl_by_user.go b/i_s/pl_by_user.go index f5bd83f..0098417 100644 --- a/i_s/pl_by_user.go +++ b/i_s/pl_by_user.go @@ -24,6 +24,7 @@ CREATE TEMPORARY TABLE `PROCESSLIST` ( type pl_by_user_row struct { username string runtime uint64 + sleeptime uint64 connections uint64 active uint64 hosts uint64 @@ -37,13 +38,13 @@ type pl_by_user_row struct { type pl_by_user_rows []pl_by_user_row /* -username |Run Time %age|Conn Actv|Hosts DBs|Select Insert Update Delete Other| -xxxxxxxxxxxxxx|hh:mm:ss 100.0%|9999 9999|9999 999|100.0% 100.0% 100.0% 100.0% 100.0%| +username |Run Time %age|Sleeping %|Conn Actv|Hosts DBs|Sel Ins Upd Del Oth| +xxxxxxxxxxxxxx|hh:mm:ss 100.0%|hh:mm:ss 100.0%|9999 9999|9999 999|999 999 999 999 999| */ func (r *pl_by_user_row) headings() string { - return fmt.Sprintf("%-14s|%10s %6s|%4s %4s|%5s %3s|%6s %6s %6s %6s %6s|", - "User", "Run Time", "%", "Conn", "Actv", "Hosts", "DBs", "Select", "Insert", "Update", "Delete", "Other") + return fmt.Sprintf("%-14s|%-8s %6s|%-8s %6s|%4s %4s|%5s %3s|%3s %3s %3s %3s %3s|", + "User", "Run Time", "%", "Sleeping", "%", "Conn", "Actv", "Hosts", "DBs", "Sel", "Ins", "Upd", "Del", "Oth") } // generate a printable result @@ -56,19 +57,21 @@ func (r *pl_by_user_row) row_content(totals pl_by_user_row) string { } else { u = r.username } - return fmt.Sprintf("%-14s|%10s %6s|%4s %4s|%5s %3s|%6s %6s %6s %6s %6s|", + return fmt.Sprintf("%-14s|%8s %6s|%8s %6s|%4s %4s|%5s %3s|%3s %3s %3s %3s %3s|", u, - lib.FormatTime(r.runtime), + lib.FormatSeconds(r.runtime), lib.FormatPct(lib.MyDivide(r.runtime, totals.runtime)), - lib.FormatAmount(r.connections), - lib.FormatAmount(r.active), - lib.FormatAmount(r.hosts), - lib.FormatAmount(r.dbs), - lib.FormatAmount(r.selects), - lib.FormatAmount(r.inserts), - lib.FormatAmount(r.updates), - lib.FormatAmount(r.deletes), - lib.FormatAmount(r.other)) + lib.FormatSeconds(r.sleeptime), + lib.FormatPct(lib.MyDivide(r.sleeptime, totals.sleeptime)), + lib.FormatCounter(int(r.connections), 4), + lib.FormatCounter(int(r.active), 4), + lib.FormatCounter(int(r.hosts), 5), + lib.FormatCounter(int(r.dbs), 3), + lib.FormatCounter(int(r.selects), 3), + lib.FormatCounter(int(r.inserts), 3), + lib.FormatCounter(int(r.updates), 3), + lib.FormatCounter(int(r.deletes), 3), + lib.FormatCounter(int(r.other), 3)) } // generate a row of totals from a table @@ -78,6 +81,7 @@ func (t pl_by_user_rows) totals() pl_by_user_row { for i := range t { totals.runtime += t[i].runtime + totals.sleeptime += t[i].sleeptime totals.connections += t[i].connections totals.active += t[i].active // totals.hosts += t[i].hosts This needs to be done differently to get the total number of distinct hosts @@ -99,7 +103,12 @@ func (t pl_by_user_rows) Headings() string { // describe a whole row func (r pl_by_user_row) String() string { - return fmt.Sprintf("%v %v %v %v %v %v %v %v %v", r.username, r.runtime, r.connections, r.active, r.hosts, r.dbs, r.selects, r.inserts, r.updates, r.deletes, r.other) + return fmt.Sprintf("%v %v %v %v %v %v %v %v %v %v", r.username, r.runtime, r.connections, r.sleeptime, r.active, r.hosts, r.dbs, r.selects, r.inserts, r.updates, r.deletes, r.other) +} + +// total time is runtime + sleeptime +func (r pl_by_user_row) total_time() uint64 { + return r.runtime + r.sleeptime } // describe a whole table @@ -117,9 +126,9 @@ type ByRunTime pl_by_user_rows func (t ByRunTime) Len() int { return len(t) } func (t ByRunTime) Swap(i, j int) { t[i], t[j] = t[j], t[i] } func (t ByRunTime) Less(i, j int) bool { - return (t[i].runtime > t[j].runtime) || - ((t[i].runtime == t[j].runtime) && (t[i].connections > t[j].connections)) || - ((t[i].runtime == t[j].runtime) && (t[i].connections == t[j].connections) && (t[i].username < t[j].username)) + return (t[i].total_time() > t[j].total_time()) || + ((t[i].total_time() == t[j].total_time()) && (t[i].connections > t[j].connections)) || + ((t[i].total_time() == t[j].total_time()) && (t[i].connections == t[j].connections) && (t[i].username < t[j].username)) } func (t pl_by_user_rows) Sort() {