Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-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
Kirill Smelkov
jacobsa-fuse
Commits
572491fe
Commit
572491fe
authored
May 01, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commonOp.maybeTraceByPID
parent
2783a716
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
fuseops/common_op.go
fuseops/common_op.go
+35
-5
No files found.
fuseops/common_op.go
View file @
572491fe
...
...
@@ -16,6 +16,7 @@ package fuseops
import
(
"flag"
"fmt"
"reflect"
"strings"
"sync"
...
...
@@ -60,15 +61,44 @@ func describeOpType(t reflect.Type) (desc string) {
return
}
func
(
o
*
commonOp
)
maybeTraceByPID
(
in
context
.
Context
)
(
out
context
.
Context
)
{
var
gPIDMapMu
sync
.
Mutex
// A map from PID to a traced context for that PID.
//
// GUARDED_BY(gPIDMapMu)
var
gPIDMap
=
make
(
map
[
int
]
context
.
Context
)
func
reportWhenPIDGone
(
pid
int
,
ctx
context
.
Context
,
report
reqtrace
.
ReportFunc
)
func
(
o
*
commonOp
)
maybeTraceByPID
(
in
context
.
Context
,
pid
int
)
(
out
context
.
Context
)
{
// Is there anything to do?
if
!*
fTraceByPID
{
if
!
reqtrace
.
Enabled
()
||
!
*
fTraceByPID
{
out
=
in
return
}
// TODO(jacobsa): Do something interesting.
out
=
in
gPIDMapMu
.
Lock
()
defer
gPIDMapMu
.
Unlock
()
// Do we already have a traced context for this PID?
if
existing
,
ok
:=
gPIDMap
[
pid
];
ok
{
out
=
existing
return
}
// Set up a new one and stick it in the map.
var
report
reqtrace
.
ReportFunc
out
,
report
=
reqtrace
.
Trace
(
in
,
fmt
.
Sprintf
(
"PID %v"
,
pid
))
gPIDMap
[
pid
]
=
out
// Ensure we close the trace and remove it from the map eventually.
go
reportWhenPIDGone
(
pid
,
out
,
report
)
return
}
...
...
@@ -79,7 +109,7 @@ func (o *commonOp) init(
log
func
(
int
,
string
,
...
interface
{}),
opsInFlight
*
sync
.
WaitGroup
)
{
// Set up a context that reflects per-PID tracing if appropriate.
ctx
=
o
.
maybeTraceByPID
(
ctx
)
ctx
=
o
.
maybeTraceByPID
(
ctx
,
int
(
r
.
Hdr
()
.
Pid
)
)
// Initialize basic fields.
o
.
opType
=
describeOpType
(
opType
)
...
...
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