Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
07fc6c8
error on escape to heap
Jun 4, 2019
cb3f988
minor
Jun 4, 2019
87a6fec
disable escaping to heap and deliver SIGPROF to the correspoind signa…
Jun 5, 2019
59beecd
minor
Jun 5, 2019
ad7bef9
disable/enable PMU counters in the signal handler
Jun 6, 2019
014d49c
note
Jun 6, 2019
0b450d5
test cases for PMU
Jun 8, 2019
508ab84
test
Jun 10, 2019
e70dce4
separete PMU from the execution path of itimer()
Jun 10, 2019
51c4d15
minor
Jun 10, 2019
cbddb3b
disable ioctl and close file descriptor when go rountine
Jun 12, 2019
1e4ffc3
export env variabls instead of cmd arguments
Jun 12, 2019
dd72834
minor
Jun 12, 2019
c802faf
minor
Jun 13, 2019
456f93c
sth to todo
Jun 13, 2019
825961c
merge Joshua's patch
Jun 17, 2019
d2fcc3b
minor
Jun 18, 2019
66654bf
minor
Jun 18, 2019
e4c59d1
minor
Jun 18, 2019
31956bf
separate PMU's output from itimer's
Jun 19, 2019
4966a3a
precise ip
Jun 20, 2019
22805e4
enable multiple PMU events
Jun 24, 2019
60231cc
minor
Jun 24, 2019
da609e8
minor
Jun 24, 2019
03afced
minor
Jun 25, 2019
37ea021
close file descriptors when finished
Jul 2, 2019
2b986ed
removal
Jul 3, 2019
14b1027
test cases
Jul 3, 2019
3721604
redefine the interface
Jul 3, 2019
7362ce0
test cases
Jul 3, 2019
84264fe
removal
Jul 3, 2019
28ccd61
minor
Jul 3, 2019
020bcba
minor
Jul 3, 2019
697954f
refactoring
Jul 8, 2019
3ca840d
test
Jul 8, 2019
797cb5a
minor
Jul 8, 2019
d46b988
refactoring
Jul 8, 2019
1625927
remove
Jul 8, 2019
953985d
refactoring
Jul 8, 2019
5dd0981
remove
Jul 8, 2019
a1c64d0
refactoring
Jul 8, 2019
8464003
refactoring
Jul 8, 2019
2f7b4b1
http
Jul 9, 2019
1ce06b9
test
Jul 9, 2019
a6860bf
indentation
Jul 10, 2019
449a5b1
indentation
Jul 10, 2019
23a00c2
separate OS-specific functions and data stuctures
Jul 10, 2019
7585bd9
API checks
Jul 10, 2019
6c5a609
API checks
Jul 10, 2019
4416dcf
minor
Jul 10, 2019
9edf689
API checks
Jul 10, 2019
baa1694
test cases for http
Jul 11, 2019
d490da6
indention
Jul 11, 2019
0e744a8
minor
Jul 11, 2019
0758f56
minor
Jul 11, 2019
ce755fd
test cases
Jul 11, 2019
f498eaf
test cases
Jul 14, 2019
621479e
remove
Jul 14, 2019
7b64868
remove
Jul 14, 2019
ecca1b3
refactoring
Jul 14, 2019
58fa80d
data race detection
Jul 15, 2019
617f3f5
assembly code of perf_event_open, ioctl, fcntl on different linux ven…
Jul 15, 2019
63bab35
minor
Jul 15, 2019
82040ab
removal
Jul 15, 2019
87dbdac
delete redundant code
Jul 15, 2019
d6a1b0d
tests
Jul 15, 2019
83ffbb8
indention
Jul 15, 2019
9b86a34
refactoring
Jul 16, 2019
5130c9b
refactoring
Jul 16, 2019
938c5f2
refactoring
Jul 16, 2019
11f0876
fix a bug on the file desriptor leaks
Jul 17, 2019
5cd77ae
output
Jul 17, 2019
5efcfcb
minor
Jul 17, 2019
9d0af5b
minor
Jul 17, 2019
9bbe0fc
minor
Jul 17, 2019
d330857
comments
Jul 18, 2019
f024a8f
comments
Jul 18, 2019
a775e8c
minor
Jul 18, 2019
4d064c1
Added support for raw events
chabbimilind Jul 18, 2019
f0c7da3
Replaced MaxPMUEvent with GO_COUNT_PMU_EVENTS_MAX
chabbimilind Jul 18, 2019
960c833
benchmark profiling with pmu
Jul 18, 2019
57f075b
benchmark profiling with pmu
Jul 18, 2019
67d3536
test cases
Jul 18, 2019
496e0ff
fix a if-else bug caused by me
Jul 18, 2019
689c122
minor
Jul 18, 2019
3e2a5bc
test cases
Jul 18, 2019
d4ae34e
more test cases
Jul 18, 2019
1d9c12c
remove
Jul 18, 2019
18a9d26
minor
Jul 18, 2019
a42f3ce
minor
Jul 18, 2019
7c0fd97
minor
Jul 18, 2019
f431074
fix a configuration error by regenerating alldocs.go
Jul 19, 2019
ca0f3fc
test cases
Jul 19, 2019
16feaf6
minor
Jul 19, 2019
151680a
replace slice with array
Jul 19, 2019
eb4565f
minor
Jul 19, 2019
9e5ca00
minor
Jul 23, 2019
c7454d5
minor
Jul 23, 2019
0294127
minor
Jul 26, 2019
e8e5462
tests
Jul 28, 2019
d3dacce
support raw events for benchmarks
Jul 28, 2019
dc539da
add two new events: LLC_load_accesses and LLC_load_misses
Jul 30, 2019
c56ebe1
minor
Aug 1, 2019
39f49ce
tests
Aug 1, 2019
37f5a20
Simplified the logic to check whether PMU is enabled and dropped repl…
chabbimilind Aug 1, 2019
9b77ff3
Merge branch 'Go-psu' of github.com:chabbimilind/Go into Go-psu
chabbimilind Aug 1, 2019
0440673
Fix Go formatting on all modified files
Aug 2, 2019
428f949
Enable PEBS
Sep 22, 2019
61f6d7a
Remove the extra blank line
Sep 22, 2019
6950c9d
Read PMU counters
Sep 23, 2019
9b22f72
change the order where values are accessed in the ring buffer
Sep 23, 2019
602c0e3
fixed error about data type
Sep 23, 2019
a55e11d
Guarantee per-sample overflow notifications
Sep 23, 2019
89fdba2
Check whether the obtained sample ip is precise
Sep 24, 2019
e7dde74
Update test cases
Sep 24, 2019
42e0204
implement mb(), rmb() and wmb() in Go-style ASM
Sep 24, 2019
2cce77b
comments
Sep 24, 2019
2a1b558
Format code using gofmt
Sep 24, 2019
98957d8
Format code using gofmt
Sep 24, 2019
30d740e
Format test cases using gofmt
Sep 24, 2019
01e39fc
Update test cases
Sep 25, 2019
2cbc9ab
Fix cross-platform compilation errors
Sep 25, 2019
99c2b0e
Change the comments
Sep 25, 2019
9e43ce5
delete excess space
Oct 15, 2019
ed87648
delete excess space
Oct 15, 2019
ab79a0a
delete excess space
Oct 15, 2019
9d3c811
Merge branch 'Go-psu' of github.com:chabbimilind/Go into Go-psu
Oct 22, 2019
b67770a
Pprof+PMU: Set the file descriptor to 0 after closing
chabbimilind Oct 22, 2019
7e90d76
Merge branch 'Go-psu' of https://github.com/chabbimilind/Go into Go-psu
chabbimilind Oct 22, 2019
9465bad
Two patches: 1) disable the PMU counter before closing the associated…
Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/except.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,4 @@ pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntfromname [88]int8
pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntonname [88]int8
pkg text/scanner, const GoTokens = 1012
pkg unicode, const Version = "10.0.0"
pkg runtime/pprof, func StartCPUProfile(io.Writer) error
24 changes: 24 additions & 0 deletions src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,30 @@ profile the tests during execution:
Write a CPU profile to the specified file before exiting.
Writes test binary as -c would.

-pmuprofile pmu.out
Write a PMU profile to the specified file before exiting.
Writes test binary as -c would.

-pmuevent event
Specify which pmu event to sample.
To sample PMU cycles, use -test.pmuevent=cycles.
To sample PMU instructions, use -test.pmuevent=instructions.
To sample PMU cache misses, use -test.pmuevent=cacheMisses.
To sample PMU last-level cache read accesses, use -test.pmuevent=cacheLLReadAccesses.
To sample PMU last-level cache read misses, use -test.pmuevent=cacheLLReadMisses.

-pmuperiod n
Set the sampling period for the pmu event specified by -pmuevent.

-pmupreciseip n
Set the precise ip level for the pmu event specified by -pmuevent.

-pmukernelincl
Count the kernel or not.

-pmuhvincl
Count the hypervisor or not.

-memprofile mem.out
Write an allocation profile to the file after all tests have passed.
Writes test binary as -c would.
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/go/internal/test/testflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ var testFlagDefn = []*cmdflag.Defn{
{Name: "coverprofile", PassToTest: true},
{Name: "cpu", PassToTest: true},
{Name: "cpuprofile", PassToTest: true},
{Name: "pmuprofile", PassToTest: true},
{Name: "pmuevent", PassToTest: true},
{Name: "pmuperiod", PassToTest: true},
{Name: "pmupreciseip", PassToTest: true},
{Name: "pmukernelincl", BoolVar: new(bool), PassToTest: true},
{Name: "pmuhvincl", BoolVar: new(bool), PassToTest: true},
{Name: "failfast", BoolVar: new(bool), PassToTest: true},
{Name: "list", PassToTest: true},
{Name: "memprofile", PassToTest: true},
Expand Down Expand Up @@ -157,7 +163,7 @@ func testFlags(usage func(), args []string) (packageNames, passToTest []string)
testList = true
case "timeout":
testTimeout = value
case "blockprofile", "cpuprofile", "memprofile", "mutexprofile":
case "blockprofile", "cpuprofile", "pmuprofile", "memprofile", "mutexprofile":
testProfile = "-" + f.Name
testNeedBinary = true
case "trace":
Expand Down
75 changes: 69 additions & 6 deletions src/net/http/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,52 @@ func serveError(w http.ResponseWriter, status int, txt string) {
fmt.Fprintln(w, txt)
}

func pmuProfile(w http.ResponseWriter, r *http.Request) error {
var eventConfig pprof.PMUEventConfig
eventConfig.Period = 1e7 // default value

if period, err := strconv.ParseInt(r.FormValue("pmuperiod"), 10, 64); err == nil {
eventConfig.Period = period
}
if preciseIP, err := strconv.ParseInt(r.FormValue("pmupreciseip"), 10, 8); err == nil {
eventConfig.PreciseIP = int8(preciseIP)
}
if isKernelIncluded, err := strconv.ParseBool(r.FormValue("pmukernelincl")); err == nil {
eventConfig.IsKernelIncluded = isKernelIncluded
}
if isHvIncluded, err := strconv.ParseBool(r.FormValue("pmuhvincl")); err == nil {
eventConfig.IsHvIncluded = isHvIncluded
}

switch eventName := r.FormValue("pmuevent"); eventName {
case "":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCycles(w, &eventConfig))
case "cycles":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCycles(w, &eventConfig))
case "instructions":
return pprof.StartPMUProfile(pprof.WithProfilingPMUInstructions(w, &eventConfig))
case "cacheReferences":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCacheReferences(w, &eventConfig))
case "cacheMisses":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCacheMisses(w, &eventConfig))
case "cacheLLReadAccesses":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCacheLLReadAccesses(w, &eventConfig))
case "cacheLLReadMisses":
return pprof.StartPMUProfile(pprof.WithProfilingPMUCacheLLReadMisses(w, &eventConfig))
default:
// Is this a raw event?
if strings.HasPrefix(eventName, "r") {
if rawHexEvent, err := strconv.ParseInt(eventName[1:], 16, 64); err == nil {
eventConfig.RawEvent = rawHexEvent
return pprof.StartPMUProfile(pprof.WithProfilingPMURaw(w, &eventConfig))
}
return fmt.Errorf("Incorrect hex format for raw event")
} else {
return fmt.Errorf("Unknown or not yet implemented event")
}
}
}

// Profile responds with the pprof-formatted cpu profile.
// Profiling lasts for duration specified in seconds GET parameter, or for 30 seconds if not specified.
// The package initialization registers it as /debug/pprof/profile.
Expand All @@ -129,14 +175,31 @@ func Profile(w http.ResponseWriter, r *http.Request) {
// because if it does it starts writing.
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", `attachment; filename="profile"`)
if err := pprof.StartCPUProfile(w); err != nil {
// StartCPUProfile failed, so no writes yet.
serveError(w, http.StatusInternalServerError,
fmt.Sprintf("Could not enable CPU profiling: %s", err))
return

isPMUEnabled, err := strconv.ParseBool(r.FormValue("pmu"))

if (err != nil) || (!isPMUEnabled) {
if err = pprof.StartCPUProfile(w); err != nil {
serveError(w, http.StatusInternalServerError,
fmt.Sprintf("Could not enable CPU profiling: %s", err))
return
}
} else {
// err == nil and isPMUEnabled == true
if err = pmuProfile(w, r); err != nil {
serveError(w, http.StatusInternalServerError,
fmt.Sprintf("Could not enable PMU profiling: %s", err))
return
}
}

sleep(w, time.Duration(sec)*time.Second)
pprof.StopCPUProfile()

if isPMUEnabled {
pprof.StopPMUProfile()
} else {
pprof.StopCPUProfile()
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading till here, I have started feeling we could simply create another HTTP endpoint that caters to only PMU profiles. For example, GC profile has its own endpoint, mutex profile has one of its own and so on.

}

// Trace responds with the execution trace in binary form.
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/asm_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,18 @@ TEXT runtime·panicExtendSlice3CU(SB),NOSPLIT,$0-12
MOVL CX, y+8(FP)
JMP runtime·goPanicExtendSlice3CU(SB)

TEXT runtime·mb(SB),NOSPLIT,$0-0
MFENCE
RET

TEXT runtime·rmb(SB),NOSPLIT,$0-0
LFENCE
RET

TEXT runtime·wmb(SB),NOSPLIT,$0-0
SFENCE
RET

#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,18 @@ TEXT runtime·panicSlice3CU(SB),NOSPLIT,$0-16
MOVQ CX, y+8(FP)
JMP runtime·goPanicSlice3CU(SB)

TEXT runtime·mb(SB),NOSPLIT,$0-0
MFENCE
RET

TEXT runtime·rmb(SB),NOSPLIT,$0-0
LFENCE
RET

TEXT runtime·wmb(SB),NOSPLIT,$0-0
SFENCE
RET

#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
Expand Down
Loading