Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Levin Zimmermann
go-fuse
Commits
97b89072
Commit
97b89072
authored
Jul 12, 2016
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example/loopback: use signals to capture memory profiles at specific times.
Change-Id: Idddaef2216c2fd216476da8744efcda679f12dd6
parent
a27cac55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
example/loopback/main.go
example/loopback/main.go
+25
-11
No files found.
example/loopback/main.go
View file @
97b89072
...
@@ -8,9 +8,11 @@ import (
...
@@ -8,9 +8,11 @@ import (
"fmt"
"fmt"
"log"
"log"
"os"
"os"
"os/signal"
"path"
"path"
"path/filepath"
"path/filepath"
"runtime/pprof"
"runtime/pprof"
"syscall"
"time"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse"
...
@@ -18,6 +20,25 @@ import (
...
@@ -18,6 +20,25 @@ import (
"github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/fuse/pathfs"
)
)
func
writeMemProfile
(
fn
string
,
sigs
<-
chan
os
.
Signal
)
{
i
:=
0
for
range
sigs
{
fn
:=
fmt
.
Sprintf
(
"%s-%d.memprof"
,
fn
,
i
)
i
++
log
.
Printf
(
"Writing mem profile to %s
\n
"
,
fn
)
f
,
err
:=
os
.
Create
(
fn
)
if
err
!=
nil
{
log
.
Printf
(
"Create: %v"
,
err
)
continue
}
pprof
.
WriteHeapProfile
(
f
)
if
err
:=
f
.
Close
();
err
!=
nil
{
log
.
Printf
(
"close %v"
,
err
)
}
}
}
func
main
()
{
func
main
()
{
log
.
SetFlags
(
log
.
Lmicroseconds
)
log
.
SetFlags
(
log
.
Lmicroseconds
)
// Scans the arg list and sets up flags
// Scans the arg list and sets up flags
...
@@ -44,17 +65,10 @@ func main() {
...
@@ -44,17 +65,10 @@ func main() {
defer
pprof
.
StopCPUProfile
()
defer
pprof
.
StopCPUProfile
()
}
}
if
*
memprofile
!=
""
{
if
*
memprofile
!=
""
{
fmt
.
Printf
(
"Writing mem profile to %s
\n
"
,
*
memprofile
)
log
.
Printf
(
"send SIGUSR1 to %d to dump memory profile"
,
os
.
Getpid
())
f
,
err
:=
os
.
Create
(
*
memprofile
)
profSig
:=
make
(
chan
os
.
Signal
,
1
)
if
err
!=
nil
{
signal
.
Notify
(
profSig
,
syscall
.
SIGUSR1
)
fmt
.
Println
(
err
)
go
writeMemProfile
(
*
memprofile
,
profSig
)
os
.
Exit
(
4
)
}
defer
func
()
{
pprof
.
WriteHeapProfile
(
f
)
f
.
Close
()
return
}()
}
}
if
*
cpuprofile
!=
""
||
*
memprofile
!=
""
{
if
*
cpuprofile
!=
""
||
*
memprofile
!=
""
{
fmt
.
Printf
(
"Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!
\n
"
)
fmt
.
Printf
(
"Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!
\n
"
)
...
...
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