]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: filter tasks by log text
authorHeschi Kreinick <heschi@google.com>
Wed, 7 Mar 2018 18:54:40 +0000 (13:54 -0500)
committerHeschi Kreinick <heschi@google.com>
Thu, 15 Mar 2018 19:59:22 +0000 (19:59 +0000)
Add a search box to the top of the user task views that only displays
tasks containing a particular log message.

Change-Id: I92f4aa113f930954e8811416901e37824f0eb884
Reviewed-on: https://go-review.googlesource.com/100843
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
src/cmd/trace/annotations.go

index aa72a50e7267090632577dac4b4f66170f029029..677ba0366ae7a2d348217c65cb1e048f069463b1 100644 (file)
@@ -662,10 +662,30 @@ func newTaskFilter(r *http.Request) (*taskFilter, error) {
                        return t.complete() && t.duration() <= lat
                })
        }
+       if text := r.FormValue("logtext"); text != "" {
+               name = append(name, fmt.Sprintf("log contains %q", text))
+               conditions = append(conditions, func(t *taskDesc) bool {
+                       return taskMatches(t, text)
+               })
+       }
 
        return &taskFilter{name: strings.Join(name, ","), cond: conditions}, nil
 }
 
+func taskMatches(t *taskDesc, text string) bool {
+       for _, ev := range t.events {
+               switch ev.Type {
+               case trace.EvUserTaskCreate, trace.EvUserSpan, trace.EvUserLog:
+                       for _, s := range ev.SArgs {
+                               if strings.Contains(s, text) {
+                                       return true
+                               }
+                       }
+               }
+       }
+       return false
+}
+
 type durationHistogram struct {
        Count                int
        Buckets              []int
@@ -804,6 +824,7 @@ var templUserTaskTypes = template.Must(template.New("").Parse(`
 
 </style>
 <body>
+Search log text: <form action="/usertask"><input name="logtext" type="text"><input type="submit"></form><br>
 <table border="1" sortable="1">
 <tr>
 <th>Task type</th>
@@ -870,6 +891,10 @@ var templUserTaskType = template.Must(template.New("userTask").Funcs(template.Fu
 
 <h2>User Task: {{.Name}}</h2>
 
+Search log text: <form onsubmit="window.location.search+='&logtext='+window.logtextinput.value; return false">
+<input name="logtext" id="logtextinput" type="text"><input type="submit">
+</form><br>
+
 <table id="reqs">
 <tr><th>When</th><th>Elapsed</th><th>Goroutine ID</th><th>Events</th></tr>
      {{range $el := $.Entry}}