Esempio n. 1
0
// ProfIndex is a http.Handler for showing profile command.
// it's in url pattern "/prof" in admin module.
func profIndex(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	format := r.Form.Get("format")
	data := make(map[string]interface{})

	var result bytes.Buffer
	if command != "" {
		toolbox.ProcessInput(command, &result)
		data["Content"] = result.String()

		if format == "json" && command == "gc summary" {
			dataJson, err := json.Marshal(data)
			if err != nil {
				http.Error(rw, err.Error(), http.StatusInternalServerError)
				return
			}

			rw.Header().Set("Content-Type", "application/json")
			rw.Write(dataJson)
			return
		}

		data["Title"] = command
		tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
		tmpl = template.Must(tmpl.Parse(profillingTpl))
		if command == "gc summary" {
			tmpl = template.Must(tmpl.Parse(gcAjaxTpl))
		} else {

			tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
		}
		tmpl.Execute(rw, data)
	}
}
Esempio n. 2
0
// ProfIndex is a http.Handler for showing profile command.
// it's in url pattern "/prof" in admin module.
func profIndex(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command == "" {
		return
	}

	var (
		format = r.Form.Get("format")
		data   = make(map[interface{}]interface{})
		result bytes.Buffer
	)
	toolbox.ProcessInput(command, &result)
	data["Content"] = result.String()

	if format == "json" && command == "gc summary" {
		dataJSON, err := json.Marshal(data)
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}

		rw.Header().Set("Content-Type", "application/json")
		rw.Write(dataJSON)
		return
	}

	data["Title"] = command
	defaultTpl := defaultScriptsTpl
	if command == "gc summary" {
		defaultTpl = gcAjaxTpl
	}
	execTpl(rw, data, profillingTpl, defaultTpl)
}
Esempio n. 3
0
File: admin.go Progetto: Neeke/beego
func ProfIndex(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		toolbox.ProcessInput(command, rw)
	} else {
		rw.Write([]byte("request url like '/prof?command=lookup goroutine'"))
	}
}
Esempio n. 4
0
// ProfIndex is a http.Handler for showing profile command.
// it's in url pattern "/prof" in admin module.
func ProfIndex(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		toolbox.ProcessInput(command, rw)
	} else {
		rw.Write([]byte("request url like '/prof?command=lookup goroutine'\n"))
		rw.Write([]byte("the command have below types:\n"))
		rw.Write([]byte("1. lookup goroutine\n"))
		rw.Write([]byte("2. lookup heap\n"))
		rw.Write([]byte("3. lookup threadcreate\n"))
		rw.Write([]byte("4. lookup block\n"))
		rw.Write([]byte("5. start cpuprof\n"))
		rw.Write([]byte("6. stop cpuprof\n"))
		rw.Write([]byte("7. get memprof\n"))
		rw.Write([]byte("8. gc summary\n"))
	}
}
Esempio n. 5
0
// ProfIndex is a http.Handler for showing profile command.
// it's in url pattern "/prof" in admin module.
func profIndex(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		toolbox.ProcessInput(command, rw)
	} else {
		rw.Write([]byte("<html><head><title>beego admin dashboard</title></head><body>"))
		rw.Write([]byte("request url like '/prof?command=lookup goroutine'<br>\n"))
		rw.Write([]byte("the command have below types:<br>\n"))
		rw.Write([]byte("1. <a href='?command=lookup goroutine'>lookup goroutine</a><br>\n"))
		rw.Write([]byte("2. <a href='?command=lookup heap'>lookup heap</a><br>\n"))
		rw.Write([]byte("3. <a href='?command=lookup threadcreate'>lookup threadcreate</a><br>\n"))
		rw.Write([]byte("4. <a href='?command=lookup block'>lookup block</a><br>\n"))
		rw.Write([]byte("5. <a href='?command=start cpuprof'>start cpuprof</a><br>\n"))
		rw.Write([]byte("6. <a href='?command=stop cpuprof'>stop cpuprof</a><br>\n"))
		rw.Write([]byte("7. <a href='?command=get memprof'>get memprof</a><br>\n"))
		rw.Write([]byte("8. <a href='?command=gc summary'>gc summary</a><br>\n"))
		rw.Write([]byte("</body></html>"))
	}
}