@cryptotaxi247 / kubo / commits / 4753e6c29

sort options and add id to verbose output

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Feb 1, 2016 at 22:05 UTC 4753e6c292ae6befe1a8a65c1f19ad9641aca85d
2 files changed +23 -5
commands/reqlog.go
+8 -3
@@ -20,13 +20,18 @@ type ReqLogEntry struct {
20 }
21
22 func (r *ReqLogEntry) Finish() {
23 - r.log.lock.Lock()
24 - defer r.log.lock.Unlock()
23 + log := r.log
24 + log.lock.Lock()
25 + defer log.lock.Unlock()
26
27 r.Active = false
28 r.EndTime = time.Now()
28 -
29 r.log.maybeCleanup()
30 +
31 + // remove references to save memory
32 + r.req = nil
33 + r.log = nil
34 +
35 }
36
37 func (r *ReqLogEntry) Copy() *ReqLogEntry {
core/commands/active.go
+15 -2
@@ -4,6 +4,7 @@ import (
4 "bytes"
5 "fmt"
6 "io"
7 + "sort"
8 "text/tabwriter"
9 "time"
10
@@ -35,6 +36,9 @@ Lists running and recently run commands.
36 verbose, _, _ := res.Request().Option("v").Bool()
37
38 w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0)
39 + if verbose {
40 + fmt.Fprint(w, "ID\t")
41 + }
42 fmt.Fprint(w, "Command\t")
43 if verbose {
44 fmt.Fprint(w, "Arguments\tOptions\t")
@@ -42,11 +46,20 @@ Lists running and recently run commands.
46 fmt.Fprintln(w, "Active\tStartTime\tRunTime")
47
48 for _, req := range *out {
49 + if verbose {
50 + fmt.Fprintf(w, "%d\t", req.ID)
51 + }
52 fmt.Fprintf(w, "%s\t", req.Command)
53 if verbose {
54 fmt.Fprintf(w, "%v\t[", req.Args)
48 - for k, v := range req.Options {
49 - fmt.Fprintf(w, "%s=%v,", k, v)
55 + var keys []string
56 + for k, _ := range req.Options {
57 + keys = append(keys, k)
58 + }
59 + sort.Strings(keys)
60 +
61 + for _, k := range keys {
62 + fmt.Fprintf(w, "%s=%v,", k, req.Options[k])
63 }
64 fmt.Fprintf(w, "]\t")
65 }