github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/daemon/api_debug_pprof.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2015-2019 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package daemon
    21  
    22  import (
    23  	"net/http"
    24  	"net/http/pprof"
    25  
    26  	"github.com/gorilla/mux"
    27  
    28  	"github.com/snapcore/snapd/overlord/auth"
    29  )
    30  
    31  var debugPprofCmd = &Command{
    32  	PathPrefix: "/v2/debug/pprof/",
    33  	GET:        getPprof,
    34  	RootOnly:   true,
    35  }
    36  
    37  func getPprof(c *Command, r *http.Request, user *auth.UserState) Response {
    38  	router := mux.NewRouter()
    39  	router.HandleFunc("/v2/debug/pprof/cmdline", pprof.Cmdline)
    40  	router.HandleFunc("/v2/debug/pprof/profile", pprof.Profile)
    41  	router.HandleFunc("/v2/debug/pprof/symbol", pprof.Symbol)
    42  	router.HandleFunc("/v2/debug/pprof/trace", pprof.Trace)
    43  	for _, profile := range []string{"heap", "allocs", "block", "threadcreate", "goroutine", "mutex"} {
    44  		router.Handle("/v2/debug/pprof/"+profile, pprof.Handler(profile))
    45  	}
    46  	return router
    47  }