aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/trace/trace.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/trace/trace.go')
-rw-r--r--src/cmd/trace/trace.go26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go
index 0139639dae..a0d742ac54 100644
--- a/src/cmd/trace/trace.go
+++ b/src/cmd/trace/trace.go
@@ -6,6 +6,7 @@ package main
import (
"cmd/internal/traceviewer"
+ "embed"
"encoding/json"
"fmt"
"internal/trace"
@@ -13,8 +14,6 @@ import (
"log"
"math"
"net/http"
- "path/filepath"
- "runtime"
"runtime/debug"
"sort"
"strconv"
@@ -22,13 +21,16 @@ import (
"time"
)
+//go:embed static/trace_viewer_full.html static/webcomponents.min.js
+var staticContent embed.FS
+
func init() {
http.HandleFunc("/trace", httpTrace)
http.HandleFunc("/jsontrace", httpJsonTrace)
- http.HandleFunc("/trace_viewer_html", httpTraceViewerHTML)
- http.HandleFunc("/webcomponents.min.js", webcomponentsJS)
+ http.Handle("/static/", http.FileServer(http.FS(staticContent)))
}
+
// httpTrace serves either whole trace (goid==0) or trace for goid goroutine.
func httpTrace(w http.ResponseWriter, r *http.Request) {
_, err := parseTrace()
@@ -50,19 +52,19 @@ func httpTrace(w http.ResponseWriter, r *http.Request) {
var templTrace = `
<html>
<head>
-<script src="/webcomponents.min.js"></script>
+<script src="/static/webcomponents.min.js"></script>
<script>
'use strict';
function onTraceViewerImportFail() {
document.addEventListener('DOMContentLoaded', function() {
document.body.textContent =
- '/trace_viewer_full.html is missing. File a bug in https://golang.org/issue';
+ '/static/trace_viewer_full.html is missing. File a bug in https://golang.org/issue';
});
}
</script>
-<link rel="import" href="/trace_viewer_html"
+<link rel="import" href="/static/trace_viewer_full.html"
onerror="onTraceViewerImportFail(event)">
<style type="text/css">
@@ -173,16 +175,6 @@ function onTraceViewerImportFail() {
</html>
`
-// httpTraceViewerHTML serves static part of trace-viewer.
-// This URL is queried from templTrace HTML.
-func httpTraceViewerHTML(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, filepath.Join(runtime.GOROOT(), "misc", "trace", "trace_viewer_full.html"))
-}
-
-func webcomponentsJS(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, filepath.Join(runtime.GOROOT(), "misc", "trace", "webcomponents.min.js"))
-}
-
// httpJsonTrace serves json trace, requested from within templTrace HTML.
func httpJsonTrace(w http.ResponseWriter, r *http.Request) {
defer debug.FreeOSMemory()