1
0
mirror of https://github.com/golang/go synced 2024-11-23 19:50:06 -07:00

cmd/trace: filter tasks by log text

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>
This commit is contained in:
Heschi Kreinick 2018-03-07 13:54:40 -05:00
parent 61f92ee56a
commit 1814a0595c

View 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}}