Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
d56917d8
Commit
d56917d8
authored
Jan 12, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(main): profile at top-level since work may be async
parent
4b13b05f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
cmd/ipfs/main.go
cmd/ipfs/main.go
+22
-10
No files found.
cmd/ipfs/main.go
View file @
d56917d8
...
...
@@ -67,6 +67,13 @@ func main() {
fmt
.
Fprintf
(
os
.
Stderr
,
"Error: %s
\n
"
,
err
.
Error
())
}
stopFunc
,
err
:=
profileIfEnabled
()
if
err
!=
nil
{
printErr
(
err
)
os
.
Exit
(
1
)
}
defer
stopFunc
()
// to be executed as late as possible
// this is a local helper to print out help text.
// there's some considerations that this makes easier.
printHelp
:=
func
(
long
bool
,
w
io
.
Writer
)
{
...
...
@@ -153,16 +160,6 @@ func (i *cmdInvocation) Run(ctx context.Context) (output io.Reader, err error) {
u
.
SetDebugLogging
()
}
// if debugging, let's profile.
// TODO maybe change this to its own option... profiling makes it slower.
if
u
.
Debug
{
stopProfilingFunc
,
err
:=
startProfiling
()
if
err
!=
nil
{
return
nil
,
err
}
defer
stopProfilingFunc
()
// to be executed as late as possible
}
res
,
err
:=
callCommand
(
ctx
,
i
.
req
,
Root
,
i
.
cmd
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -511,3 +508,18 @@ func allInterruptSignals() chan os.Signal {
syscall
.
SIGTERM
)
return
sigc
}
func
profileIfEnabled
()
(
func
(),
error
)
{
// FIXME this is a temporary hack so profiling of asynchronous operations
// works as intended.
if
u
.
GetenvBool
(
"DEBUG"
)
||
os
.
Getenv
(
"IPFS_LOGGING"
)
==
"debug"
{
u
.
Debug
=
true
u
.
SetDebugLogging
()
stopProfilingFunc
,
err
:=
startProfiling
()
// TODO maybe change this to its own option... profiling makes it slower.
if
err
!=
nil
{
return
nil
,
err
}
return
stopProfilingFunc
,
nil
}
return
func
()
{},
nil
}
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