Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/pprof: Remove SIGPROF if the last event is stopped. #3

Open
wants to merge 1 commit into
base: release-branch.go1.16_pmu_pprof
Choose a base branch
from

Conversation

WangLeonard
Copy link

This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.

Please ensure you adhere to every item in this list.

More info can be found at https://github.com/golang/go/wiki/CommitMessage

  • The PR title is formatted as follows: net/http: frob the quux before blarfing
    • The package name goes before the colon
    • The part after the colon uses the verb tense + phrase that completes the blank in,
      "This change modifies Go to ___________"
    • Lowercase verb after the colon
    • No trailing period
    • Keep the title as short as possible. ideally under 76 characters or shorter
  • No Markdown
  • The first PR comment (this one) is wrapped at 76 characters, unless it's
    really needed (ASCII art, table, or long link)
  • If there is a corresponding issue, add either Fixes #1234 or Updates #1234
    (the latter if this is not a complete fix) to this comment
  • If referring to a repo other than golang/go you can use the
    owner/repo#issue_number syntax: Fixes golang/tools#1234
  • We do not use Signed-off-by lines in Go. Please don't add them.
    Our Gerrit server & GitHub bots enforce CLA compliance instead.
  • Delete these instructions once you have read and applied them

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Leonard Wang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@WangLeonard
Copy link
Author

Hi, I added the following print and did an experiment

diff --git a/src/net/http/pprof/pprof.go b/src/net/http/pprof/pprof.go
index 89d5151c1f..c5dfe375d3 100644
--- a/src/net/http/pprof/pprof.go
+++ b/src/net/http/pprof/pprof.go
@@ -151,6 +151,7 @@ func Profile(w http.ResponseWriter, r *http.Request) {
        case "timer":
                err = pprof.StartCPUProfile(w)
        case "cycles":
+               println("StartCPUProfileWithConfig")
                err = pprof.StartCPUProfileWithConfig(pprof.CPUCycles(w, period))
        case "instructions":
                err = pprof.StartCPUProfileWithConfig(pprof.CPUInstructions(w, period))
@@ -182,6 +183,7 @@ func Profile(w http.ResponseWriter, r *http.Request) {
        }
 
        sleep(r, time.Duration(sec)*time.Second)
+       println("StopCPUProfile")
        pprof.StopCPUProfile()
 }
 
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index f7a57d75cc..0f25566238 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -4644,10 +4644,12 @@ func setcpuprofileconfig(eventId cpuEvent, profConfig *cpuProfileConfig) {
                        for i := _CPUPROF_FIRST_EVENT; i < _CPUPROF_EVENTS_MAX; i++ {
                                if prof[i].config != nil {
                                        eventsRunning = true
+                                       println("eventsRunning = true")
                                        break
                                }
                        }
                        if eventsRunning == false {
+                               println("setProcessCPUProfiler(nil)")
                                setProcessCPUProfiler(nil)
                        }
                } else {

when I run net/http/pprof/examples/goroutine.go

and curl for a cycles event profile

It will print:

go run goroutine.go
StartCPUProfileWithConfig
StopCPUProfile
eventsRunning = true

Note, I only create one event, and when it is done, call pprof.StopCPUProfile().

It will set eventsRunning = true, and miss setProcessCPUProfiler(nil) , further miss Restore SIGPROF.

Is this as expected? Does it need to be fixed?

Thank you!

@WangLeonard
Copy link
Author

friendly ping...
Is this MR correct or maybe I am thinking wrong somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants