Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(172)

Delta Between Two Patch Sets: src/pkg/runtime/debug.go

Issue 132440043: code review 132440043: runtime: convert cpuprof from C to Go (Closed)
Left Patch Set: diff -r 25ae16c918f65ca0e0039d74109aaeefa716d987 https://code.google.com/p/go Created 10 years, 6 months ago
Right Patch Set: diff -r 17b5fc2aa130ef7c32cbbdf95620862610d7773e https://code.google.com/p/go Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/cpuprof.go ('k') | src/pkg/runtime/proc.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package runtime 5 package runtime
6 6
7 import "unsafe" 7 import "unsafe"
8 8
9 // Breakpoint executes a breakpoint trap. 9 // Breakpoint executes a breakpoint trap.
10 func Breakpoint() 10 func Breakpoint()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 return n 43 return n
44 } 44 }
45 45
46 // NumGoroutine returns the number of goroutines that currently exist. 46 // NumGoroutine returns the number of goroutines that currently exist.
47 func NumGoroutine() int { 47 func NumGoroutine() int {
48 return int(gcount()) 48 return int(gcount())
49 } 49 }
50 50
51 func gcount() int32 51 func gcount() int32
52
53 // MemProfileRate controls the fraction of memory allocations
54 // that are recorded and reported in the memory profile.
55 // The profiler aims to sample an average of
56 // one allocation per MemProfileRate bytes allocated.
57 //
58 // To include every allocated block in the profile, set MemProfileRate to 1.
59 // To turn off profiling entirely, set MemProfileRate to 0.
60 //
61 // The tools that process the memory profiles assume that the
62 // profile rate is constant across the lifetime of the program
63 // and equal to the current value. Programs that change the
64 // memory profiling rate should do so just once, as early as
65 // possible in the execution of the program (for example,
66 // at the beginning of main).
67 var MemProfileRate int = 512 * 1024
68
69 // A MemProfileRecord describes the live objects allocated
70 // by a particular call sequence (stack trace).
71 type MemProfileRecord struct {
72 AllocBytes, FreeBytes int64 // number of bytes allocated, free d
73 AllocObjects, FreeObjects int64 // number of objects allocated, fr eed
74 Stack0 [32]uintptr // stack trace for this record; en ds at first 0 entry
75 }
76
77 // InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
78 func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeByte s }
79
80 // InUseObjects returns the number of objects in use (AllocObjects - FreeObjects ).
81 func (r *MemProfileRecord) InUseObjects() int64 {
82 return r.AllocObjects - r.FreeObjects
83 }
84
85 // Stack returns the stack trace associated with the record,
86 // a prefix of r.Stack0.
87 func (r *MemProfileRecord) Stack() []uintptr {
88 for i, v := range r.Stack0 {
89 if v == 0 {
90 return r.Stack0[0:i]
91 }
92 }
93 return r.Stack0[0:]
94 }
95
96 // A StackRecord describes a single execution stack.
97 type StackRecord struct {
98 Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry
99 }
100
101 // Stack returns the stack trace associated with the record,
102 // a prefix of r.Stack0.
103 func (r *StackRecord) Stack() []uintptr {
104 for i, v := range r.Stack0 {
105 if v == 0 {
106 return r.Stack0[0:i]
107 }
108 }
109 return r.Stack0[0:]
110 }
111
112 // GoroutineProfile returns n, the number of records in the active goroutine sta ck profile.
113 // If len(p) >= n, GoroutineProfile copies the profile into p and returns n, tru e.
114 // If len(p) < n, GoroutineProfile does not change p and returns n, false.
115 //
116 // Most clients should use the runtime/pprof package instead
117 // of calling GoroutineProfile directly.
118 func GoroutineProfile(p []StackRecord) (n int, ok bool)
119
120 // SetBlockProfileRate controls the fraction of goroutine blocking events
121 // that are reported in the blocking profile. The profiler aims to sample
122 // an average of one blocking event per rate nanoseconds spent blocked.
123 //
124 // To include every blocking event in the profile, pass rate = 1.
125 // To turn off profiling entirely, pass rate <= 0.
126 func SetBlockProfileRate(rate int)
127
128 // BlockProfileRecord describes blocking events originated
129 // at a particular call sequence (stack trace).
130 type BlockProfileRecord struct {
131 Count int64
132 Cycles int64
133 StackRecord
134 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b