changing branches
[pstop.git] / i_s / pl_by_user.go
index 9ad2c8d..0098417 100644 (file)
@@ -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|%5s %4s|%4s %3s|%6s %6s %6s %6s %6s|",
-               "username", "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,32 +57,35 @@ func (r *pl_by_user_row) row_content(totals pl_by_user_row) string {
        } else {
                u = r.username
        }
-       return fmt.Sprintf("%-14s|%10s %6s|%5s %4s|%4s %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
 func (t pl_by_user_rows) totals() pl_by_user_row {
        var totals pl_by_user_row
-       totals.username = "TOTALS"
+       totals.username = "Totals"
 
        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
-               //              totals.dbs += t[i].dbs                  This needs to be done differently to get the total number of distinct dbs
+               //      totals.hosts += t[i].hosts      This needs to be done differently to get the total number of distinct hosts
+               //      totals.dbs += t[i].dbs          This needs to be done differently to get the total number of distinct dbs
                totals.selects += t[i].selects
                totals.inserts += t[i].inserts
                totals.updates += t[i].updates
@@ -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,18 +126,15 @@ 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))
+       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() {
        sort.Sort(ByRunTime(t))
 }
 
-func (r pl_by_user_row) Description() string {
-       return "no description"
-}
-
 func (t pl_by_user_rows) emptyRowContent() string {
        var r pl_by_user_row
        return r.row_content(r)