Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
63c2f263
Commit
63c2f263
authored
Jul 05, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a4cfd3bb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
65 deletions
+67
-65
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+55
-56
go/xcommon/tracing/tracing.go
go/xcommon/tracing/tracing.go
+12
-9
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
63c2f263
...
...
@@ -18,7 +18,10 @@
// See https://www.nexedi.com/licensing for rationale and options.
/*
gotrace gen generates code according to tracing annotations and imports
gotrace TODO
gen generates code according to tracing annotations and imports
list lists tracepoints defined in a package
gotrace gen package
gotrace list package TODO
...
...
@@ -106,7 +109,6 @@ type Package struct {
traceTypeInfo
*
types
.
Info
// typeinfo for ^^^
}
// parseTraceEvent parses trace event definition into traceEvent
// text is text argument after "//trace:event "
func
(
p
*
Package
)
parseTraceEvent
(
srcfile
*
ast
.
File
,
pos
token
.
Position
,
text
string
)
(
*
traceEvent
,
error
)
{
...
...
@@ -247,14 +249,14 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
DisableUnusedImportCheck
:
true
,
}
// tfset := token.NewFileSet() // XXX ok to separate or use original package fset?
// tfset := token.NewFileSet() // XXX ok to separate or use original package fset?
tpkg
:=
types
.
NewPackage
(
pkgi
.
Pkg
.
Path
(),
pkgi
.
Pkg
.
Name
())
tinfo
:=
&
types
.
Info
{
Types
:
make
(
map
[
ast
.
Expr
]
types
.
TypeAndValue
)}
p
:=
&
Package
{
Pkgi
:
pkgi
,
// traceFset: tfset,
// traceChecker: types.NewChecker(tconf, tfset, tpkg, tinfo),
// traceFset: tfset,
// traceChecker: types.NewChecker(tconf, tfset, tpkg, tinfo),
// XXX vvv do we need separate field for traceFset if it is = prog.Fset?
traceFset
:
prog
.
Fset
,
...
...
@@ -333,17 +335,18 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
// byEventName provides []*traceEvent ordering by event name
type
byEventName
[]
*
traceEvent
func
(
v
byEventName
)
Less
(
i
,
j
int
)
bool
{
return
v
[
i
]
.
Name
.
Name
<
v
[
j
]
.
Name
.
Name
}
func
(
v
byEventName
)
Swap
(
i
,
j
int
)
{
v
[
i
],
v
[
j
]
=
v
[
j
],
v
[
i
]
}
func
(
v
byEventName
)
Len
()
int
{
return
len
(
v
)
}
// byPkgPath provides []*traceImport ordering by package path
type
byPkgPath
[]
*
traceImport
func
(
v
byPkgPath
)
Less
(
i
,
j
int
)
bool
{
return
v
[
i
]
.
PkgPath
<
v
[
j
]
.
PkgPath
}
func
(
v
byPkgPath
)
Swap
(
i
,
j
int
)
{
v
[
i
],
v
[
j
]
=
v
[
j
],
v
[
i
]
}
func
(
v
byPkgPath
)
Len
()
int
{
return
len
(
v
)
}
// SplitTests splits package into main and test parts, each covering trace-related things accordingly
func
(
p
*
Package
)
SplitTests
()
(
testPkg
*
Package
)
{
__
:=
*
p
...
...
@@ -376,8 +379,6 @@ func (p *Package) SplitTests() (testPkg *Package) {
return
testPkg
}
// ----------------------------------------
// Argv returns comma-separated argument-list
...
...
@@ -401,7 +402,7 @@ func (te *traceEvent) ArgvTyped() string {
// ArgvTypedRelativeTo returns argument list with types qualified relative to specified package
// importedAs specifies under which name a package was imported, if name was explicitly set
func
(
te
*
traceEvent
)
ArgvTypedRelativeTo
(
pkg
*
types
.
Package
,
importedAs
map
[
string
/*pkgpath*/
]
string
/*
pkgname*/
)
string
{
func
(
te
*
traceEvent
)
ArgvTypedRelativeTo
(
pkg
*
types
.
Package
,
importedAs
map
[
string
]
string
/*pkgpath ->
pkgname*/
)
string
{
argv
:=
[]
string
{}
// default qualifier - relative to original package
...
...
@@ -437,10 +438,9 @@ func (te *traceEvent) ArgvTypedRelativeTo(pkg *types.Package, importedAs map[str
return
strings
.
Join
(
argv
,
", "
)
}
// NeedPkgv returns packages that are needed for argument types
func
(
te
*
traceEvent
)
NeedPkgv
()
[]
string
{
pkgset
:=
StrSet
{
/*pkgpath*/
}
pkgset
:=
StrSet
{
/*pkgpath*/
}
qf
:=
func
(
pkg
*
types
.
Package
)
string
{
// if we are called - pkg is used
pkgset
.
Add
(
pkg
.
Path
())
...
...
@@ -465,7 +465,6 @@ func (ti *traceImport) ImportSpec() string {
return
t
}
// traceEventCodeTmpl is code template generated for one trace event
var
traceEventCodeTmpl
=
template
.
Must
(
template
.
New
(
"traceevent"
)
.
Parse
(
`
// traceevent: {{.Name}}({{.ArgvTyped}})
...
...
@@ -671,7 +670,8 @@ func (p *Program) ImportWithTests(pkgpath string) (prog *loader.Program, pkgi *l
if
len
(
prog
.
Created
)
>
0
{
xtestPkgi
=
prog
.
Created
[
0
]
}
for
_
,
pkgi
=
range
prog
.
Imported
{}
for
_
,
pkgi
=
range
prog
.
Imported
{
}
return
prog
,
pkgi
,
xtestPkgi
,
nil
}
...
...
@@ -721,14 +721,13 @@ func tracegen(pkgpath string, ctxt *build.Context, cwd string) error {
return
xerr
.
Merge
(
err1
,
err2
,
err3
)
}
// tracegen1 generates code according to tracing directives for a (sub)package @pkgpath
// subpackage is either original package, testing code, or external test package
func
tracegen1
(
P
*
Program
,
tpkg
*
Package
,
pkgdir
string
,
kind
string
)
error
{
var
err
error
// write ztrace.go with code generated for trace events and imports
ztrace_go
:=
filepath
.
Join
(
pkgdir
,
"ztrace"
+
kind
+
".go"
)
ztrace_go
:=
filepath
.
Join
(
pkgdir
,
"ztrace"
+
kind
+
".go"
)
if
len
(
tpkg
.
Eventv
)
==
0
&&
len
(
tpkg
.
Importv
)
==
0
{
err
=
removeFile
(
ztrace_go
)
if
err
!=
nil
{
...
...
@@ -797,11 +796,12 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error {
}
// verify export hash so link fails if it gets out of sync with imported package
err
=
traceEventImportCheckTmpl
.
Execute
(
text
,
struct
{
err
=
traceEventImportCheckTmpl
.
Execute
(
text
,
struct
{
ImportSpec
*
traceImport
ExportHash
string
}{
ExportHash
string
}{
timport
,
traceExportHash
(
impPkg
,
""
/*regular package*/
)})
traceExportHash
(
impPkg
,
""
/*regular package*/
)})
text
.
emit
(
""
)
...
...
@@ -846,7 +846,7 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error {
}
// write empty ztrace.s so go:linkname works, if there are trace imports
ztrace_s
:=
filepath
.
Join
(
pkgdir
,
"ztrace"
+
kind
+
".s"
)
ztrace_s
:=
filepath
.
Join
(
pkgdir
,
"ztrace"
+
kind
+
".s"
)
if
len
(
tpkg
.
Importv
)
==
0
{
err
=
removeFile
(
ztrace_s
)
}
else
{
...
...
@@ -896,7 +896,6 @@ func traceExportHash(tpkg *Package, kind string) string {
return
fmt
.
Sprintf
(
"%x"
,
sha1
.
Sum
(
traceExport
(
tpkg
,
kind
)))
}
func
main
()
{
log
.
SetFlags
(
0
)
log
.
SetPrefix
(
"gotrace: "
)
...
...
go/xcommon/tracing/tracing.go
View file @
63c2f263
...
...
@@ -17,15 +17,18 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package tracing provides runtime and usage support for Go tracing facilities
// TODO describe how to define tracepoints
// TODO doc:
// - tracepoints
// - probes
// - probes can be attached/detached to/from tracepoints
//
// TODO document //trace:event & //trace:import
// TODO document `gotrace gen` + `gotrace list`
/*
Package tracing provides runtime and usage support for Go tracing facilities
TODO describe how to define tracepoints
TODO doc:
- tracepoints
- probes
- probes can be attached/detached to/from tracepoints
TODO document //trace:event & //trace:import
TODO document `gotrace gen` + `gotrace list`
*/
package
tracing
import
(
...
...
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