Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
b2458ff7
Commit
b2458ff7
authored
Sep 04, 2012
by
Alan Donovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runtime/pprof: emit end-of-log marker at end of CPU profile.
R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/6489065
parent
d353d43d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
cpuprof.c
src/pkg/runtime/cpuprof.c
+14
-0
pprof_test.go
src/pkg/runtime/pprof/pprof_test.go
+11
-5
No files found.
src/pkg/runtime/cpuprof.c
View file @
b2458ff7
...
...
@@ -99,6 +99,7 @@ struct Profile {
uint32
wtoggle
;
bool
wholding
;
// holding & need to release a log half
bool
flushing
;
// flushing hash table - profile is over
bool
eod_sent
;
// special end-of-data record sent; => flushing
};
static
Lock
lk
;
...
...
@@ -109,6 +110,8 @@ static void add(Profile*, uintptr*, int32);
static
bool
evict
(
Profile
*
,
Entry
*
);
static
bool
flushlog
(
Profile
*
);
static
uintptr
eod
[
3
]
=
{
0
,
1
,
0
};
// LostProfileData is a no-op function used in profiles
// to mark the number of profiling stack traces that were
// discarded due to slow data writers.
...
...
@@ -163,6 +166,7 @@ runtime·SetCPUProfileRate(int32 hz)
prof
->
wholding
=
false
;
prof
->
wtoggle
=
0
;
prof
->
flushing
=
false
;
prof
->
eod_sent
=
false
;
runtime
·
noteclear
(
&
prof
->
wait
);
runtime
·
setcpuprofilerate
(
tick
,
hz
);
...
...
@@ -409,6 +413,16 @@ breakflush:
}
// Made it through the table without finding anything to log.
if
(
!
p
->
eod_sent
)
{
// We may not have space to append this to the partial log buf,
// so we always return a new slice for the end-of-data marker.
p
->
eod_sent
=
true
;
ret
.
array
=
(
byte
*
)
eod
;
ret
.
len
=
sizeof
eod
;
ret
.
cap
=
ret
.
len
;
return
ret
;
}
// Finally done. Clean up and return nil.
p
->
flushing
=
false
;
if
(
!
runtime
·
cas
(
&
p
->
handoff
,
p
->
handoff
,
0
))
...
...
src/pkg/runtime/pprof/pprof_test.go
View file @
b2458ff7
...
...
@@ -49,19 +49,25 @@ func TestCPUProfile(t *testing.T) {
// Convert []byte to []uintptr.
bytes
:=
prof
.
Bytes
()
l
:=
len
(
bytes
)
/
int
(
unsafe
.
Sizeof
(
uintptr
(
0
)))
val
:=
*
(
*
[]
uintptr
)(
unsafe
.
Pointer
(
&
bytes
))
val
=
val
[
:
l
en
(
bytes
)
/
int
(
unsafe
.
Sizeof
(
uintptr
(
0
)))
]
val
=
val
[
:
l
]
if
l
en
(
val
)
<
10
{
if
l
<
13
{
t
.
Fatalf
(
"profile too short: %#x"
,
val
)
}
if
val
[
0
]
!=
0
||
val
[
1
]
!=
3
||
val
[
2
]
!=
0
||
val
[
3
]
!=
1e6
/
100
||
val
[
4
]
!=
0
{
t
.
Fatalf
(
"unexpected header %#x"
,
val
[
:
5
])
hd
,
val
,
tl
:=
val
[
:
5
],
val
[
5
:
l
-
3
],
val
[
l
-
3
:
]
if
hd
[
0
]
!=
0
||
hd
[
1
]
!=
3
||
hd
[
2
]
!=
0
||
hd
[
3
]
!=
1e6
/
100
||
hd
[
4
]
!=
0
{
t
.
Fatalf
(
"unexpected header %#x"
,
hd
)
}
if
tl
[
0
]
!=
0
||
tl
[
1
]
!=
1
||
tl
[
2
]
!=
0
{
t
.
Fatalf
(
"malformed end-of-data marker %#x"
,
tl
)
}
// Check that profile is well formed and contains ChecksumIEEE.
found
:=
false
val
=
val
[
5
:
]
for
len
(
val
)
>
0
{
if
len
(
val
)
<
2
||
val
[
0
]
<
1
||
val
[
1
]
<
1
||
uintptr
(
len
(
val
))
<
2
+
val
[
1
]
{
t
.
Fatalf
(
"malformed profile. leftover: %#x"
,
val
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment