aboutsummaryrefslogtreecommitdiff
path: root/src/internal/trace/traceviewer
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2023-11-12 23:27:31 +0000
committerMichael Knyszek <mknyszek@google.com>2023-11-21 21:27:53 +0000
commitff07b73faced25076548b8d916ff19de1844650a (patch)
tree36e8928ea4af5e95797b8194185cfb9d200e82c7 /src/internal/trace/traceviewer
parentc785be4c6ac8f042e91d7333862737078831ece4 (diff)
downloadgo-ff07b73faced25076548b8d916ff19de1844650a.tar.xz
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>
Diffstat (limited to 'src/internal/trace/traceviewer')
-rw-r--r--src/internal/trace/traceviewer/mmu.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/internal/trace/traceviewer/mmu.go b/src/internal/trace/traceviewer/mmu.go
index 42bf82774d..0cb2b42657 100644
--- a/src/internal/trace/traceviewer/mmu.go
+++ b/src/internal/trace/traceviewer/mmu.go
@@ -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');