mirror of
https://github.com/golang/go
synced 2024-11-17 13:04:54 -07:00
internal/trace/traceviewer: make the mmu handler more self-contained
The last change made the MMU rendering code common and introduced a new API, but it was kind of messy. Part of the problem was that some of the Javascript in the template for the main page referred to specific endpoints on the server. Fix this by having the Javascript access the same endpoint but with a different query variable. Now the Javascript code doesn't depend on specific endpoints, just on query variables for the current endpoint. For #60773. For #63960. Change-Id: I1c559d9859c3a0d62e2094c9d4ab117890b63b31 Reviewed-on: https://go-review.googlesource.com/c/go/+/541259 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
c785be4c6a
commit
ff07b73fac
@ -139,8 +139,8 @@ func main() {
|
||||
log.Printf("Opening browser. Trace viewer is listening on %s", addr)
|
||||
browser.Open(addr)
|
||||
|
||||
// Install MMU handlers.
|
||||
traceviewer.InstallMMUHandlers(http.DefaultServeMux, ranges, mutatorUtil)
|
||||
// Install MMU handler.
|
||||
http.HandleFunc("/mmu", traceviewer.MMUHandlerFunc(ranges, mutatorUtil))
|
||||
|
||||
// Install main handler.
|
||||
http.Handle("/", traceviewer.MainHandler(ranges))
|
||||
|
@ -62,6 +62,10 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
|
||||
log.Printf("Opening browser. Trace viewer is listening on %s", addr)
|
||||
browser.Open(addr)
|
||||
|
||||
mutatorUtil := func(flags trace.UtilFlags) ([][]trace.MutatorUtil, error) {
|
||||
return trace.MutatorUtilizationV2(parsed.events, flags), nil
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", traceviewer.MainHandler(ranges))
|
||||
mux.Handle("/trace", traceviewer.TraceHandler())
|
||||
@ -69,12 +73,7 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
|
||||
mux.Handle("/static/", traceviewer.StaticHandler())
|
||||
mux.HandleFunc("/goroutines", GoroutinesHandlerFunc(gSummaries))
|
||||
mux.HandleFunc("/goroutine", GoroutineHandler(gSummaries))
|
||||
|
||||
// Install MMU handlers.
|
||||
mutatorUtil := func(flags trace.UtilFlags) ([][]trace.MutatorUtil, error) {
|
||||
return trace.MutatorUtilizationV2(parsed.events, flags), nil
|
||||
}
|
||||
traceviewer.InstallMMUHandlers(mux, ranges, mutatorUtil)
|
||||
mux.HandleFunc("/mmu", traceviewer.MMUHandlerFunc(ranges, mutatorUtil))
|
||||
|
||||
err = http.Serve(ln, mux)
|
||||
return fmt.Errorf("failed to start http server: %w", err)
|
||||
|
@ -40,19 +40,23 @@ import (
|
||||
|
||||
type MutatorUtilFunc func(trace.UtilFlags) ([][]trace.MutatorUtil, error)
|
||||
|
||||
func InstallMMUHandlers(mux *http.ServeMux, ranges []Range, f MutatorUtilFunc) {
|
||||
func MMUHandlerFunc(ranges []Range, f MutatorUtilFunc) http.HandlerFunc {
|
||||
mmu := &mmu{
|
||||
cache: make(map[trace.UtilFlags]*mmuCacheEntry),
|
||||
f: f,
|
||||
ranges: ranges,
|
||||
}
|
||||
mux.HandleFunc("/mmu", func(w http.ResponseWriter, r *http.Request) {
|
||||
// N.B. templMMU has Javascript that implicitly relies upon the existence
|
||||
// of /mmuPlot and /mmuDetails on the same server.
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.FormValue("mode") {
|
||||
case "plot":
|
||||
mmu.HandlePlot(w, r)
|
||||
return
|
||||
case "details":
|
||||
mmu.HandleDetails(w, r)
|
||||
return
|
||||
}
|
||||
http.ServeContent(w, r, "", time.Time{}, strings.NewReader(templMMU))
|
||||
})
|
||||
mux.HandleFunc("/mmuPlot", mmu.HandlePlot)
|
||||
mux.HandleFunc("/mmuDetails", mmu.HandleDetails)
|
||||
}
|
||||
}
|
||||
|
||||
var utilFlagNames = map[string]trace.UtilFlags{
|
||||
@ -209,7 +213,7 @@ var templMMU = `<!doctype html>
|
||||
container.css('opacity', '.5');
|
||||
refreshChart.count++;
|
||||
var seq = refreshChart.count;
|
||||
$.getJSON('/mmuPlot?flags=' + mmuFlags())
|
||||
$.getJSON('?mode=plot&flags=' + mmuFlags())
|
||||
.fail(function(xhr, status, error) {
|
||||
alert('failed to load plot: ' + status);
|
||||
})
|
||||
@ -282,7 +286,7 @@ var templMMU = `<!doctype html>
|
||||
var details = $('#details');
|
||||
details.empty();
|
||||
var windowNS = curve[items[0].row][0];
|
||||
var url = '/mmuDetails?window=' + windowNS + '&flags=' + mmuFlags();
|
||||
var url = '?mode=details&window=' + windowNS + '&flags=' + mmuFlags();
|
||||
$.getJSON(url)
|
||||
.fail(function(xhr, status, error) {
|
||||
details.text(status + ': ' + url + ' could not be loaded');
|
||||
|
Loading…
Reference in New Issue
Block a user