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
b6676718
Commit
b6676718
authored
Jul 04, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a503084a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
25 deletions
+24
-25
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+16
-16
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go.ok
...mmon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go.ok
+4
-4
go/xcommon/tracing/cmd/gotrace/testdata/src/b/pkg2/pkg2.go
go/xcommon/tracing/cmd/gotrace/testdata/src/b/pkg2/pkg2.go
+2
-3
go/xcommon/tracing/cmd/gotrace/testdata/src/b/pkg2/ztrace.go.ok
...mmon/tracing/cmd/gotrace/testdata/src/b/pkg2/ztrace.go.ok
+2
-2
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
b6676718
...
...
@@ -25,6 +25,8 @@ gotrace list package TODO
XXX tracepoints this package defines
XXX tracepoints this package imports
FIXME build tags not taken into account
*/
package
main
...
...
@@ -51,7 +53,7 @@ import (
// traceEvent represents 1 trace:event definition
type
traceEvent
struct
{
Pkg
*
Package
// package this trace event is part of
Pkg
t
*
Package
// package this trace event is part of
// declaration of function to signal the event
// the declaration is constructed on the fly via converting e.g.
...
...
@@ -97,7 +99,6 @@ type Package struct {
// progImporter is types.Importer that imports packages from loaded loader.Program
// TODO also import package not yet imported by prog
type
progImporter
struct
{
prog
*
loader
.
Program
}
...
...
@@ -182,21 +183,20 @@ func (p *Package) parseTraceEvent(srcfile *ast.File, pos token.Position, text st
return
nil
,
err
// should already have pos' as prefix
}
return
&
traceEvent
{
Pkg
:
p
,
FuncDecl
:
declf
},
nil
return
&
traceEvent
{
Pkg
t
:
p
,
FuncDecl
:
declf
},
nil
}
// packageTrace returns tracing information about a package
func
packageTrace
(
prog
*
loader
.
Program
,
pkgi
*
loader
.
PackageInfo
)
(
*
Package
,
error
)
{
fmt
.
Println
(
"package trace:"
,
pkgi
.
Pkg
.
Path
())
// prepare Package with typechecker ready to typecheck trace files
// (to get trace func argument types)
tconf
:=
&
types
.
Config
{
Importer
:
&
progImporter
{
prog
},
//
XXX
to ignore traceXXX() calls from original package code
// to ignore traceXXX() calls from original package code
IgnoreFuncBodies
:
true
,
// we t
ook
imports from original source file verbatim,
// we t
ake
imports from original source file verbatim,
// but most of them probably won't be used.
DisableUnusedImportCheck
:
true
,
}
...
...
@@ -221,7 +221,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
err
:=
p
.
traceChecker
.
Files
(
p
.
Pkgi
.
Files
)
if
err
!=
nil
{
// must not happen
panic
(
fmt
.
Errorf
(
"
error rechecking original package: %v"
,
err
))
panic
(
fmt
.
Errorf
(
"
%v: error rechecking original package: %v"
,
pkgi
.
Pkg
.
Path
()
,
err
))
}
// go through files of the original package and process //trace: directives
...
...
@@ -291,8 +291,6 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
return
p
,
nil
}
// ----------------------------------------
// 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
}
...
...
@@ -306,6 +304,8 @@ func (v byPkgPath) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func
(
v
byPkgPath
)
Len
()
int
{
return
len
(
v
)
}
// ----------------------------------------
// Argv returns comma-separated argument-list
func
(
te
*
traceEvent
)
Argv
()
string
{
argv
:=
[]
string
{}
...
...
@@ -322,7 +322,7 @@ func (te *traceEvent) Argv() string {
// ArgvTyped returns argument list with types
// types are qualified relative to original package
func
(
te
*
traceEvent
)
ArgvTyped
()
string
{
return
te
.
ArgvTypedRelativeTo
(
te
.
Pkg
.
tracePkg
)
return
te
.
ArgvTypedRelativeTo
(
te
.
Pkg
t
.
tracePkg
)
}
// ArgvTypedRelativeTo returns argument list with types qualified relative to specified package
...
...
@@ -347,7 +347,7 @@ func (te *traceEvent) ArgvTypedRelativeTo(pkg *types.Package) string {
}
arg
:=
strings
.
Join
(
namev
,
", "
)
typ
:=
te
.
Pkg
.
traceTypeInfo
.
Types
[
field
.
Type
]
.
Type
typ
:=
te
.
Pkg
t
.
traceTypeInfo
.
Types
[
field
.
Type
]
.
Type
arg
+=
" "
+
types
.
TypeString
(
typ
,
qf
)
argv
=
append
(
argv
,
arg
)
...
...
@@ -367,7 +367,7 @@ func (te *traceEvent) NeedPkgv() []string {
}
for
_
,
field
:=
range
te
.
FuncDecl
.
Type
.
Params
.
List
{
typ
:=
te
.
Pkg
.
traceTypeInfo
.
Types
[
field
.
Type
]
.
Type
typ
:=
te
.
Pkg
t
.
traceTypeInfo
.
Types
[
field
.
Type
]
.
Type
_
=
types
.
TypeString
(
typ
,
qf
)
}
...
...
@@ -376,7 +376,7 @@ func (te *traceEvent) NeedPkgv() []string {
// traceEventCodeTmpl is code template generated for one trace event
var
traceEventCodeTmpl
=
template
.
Must
(
template
.
New
(
"traceevent"
)
.
Parse
(
`
// traceevent: {{.Name}}({{.ArgvTyped}})
XXX better raw .Text (e.g. comments)
// traceevent: {{.Name}}({{.ArgvTyped}})
{{/* probe type for this trace event */ -}}
type _t_{{.Name}} struct {
...
...
@@ -415,8 +415,8 @@ func {{.Name}}_Attach(pg *tracing.ProbeGroup, probe func({{.ArgvTyped}})) *traci
// traceEventImportTmpl is code template generated for importing one trace event
var
traceEventImportTmpl
=
template
.
Must
(
template
.
New
(
"traceimport"
)
.
Parse
(
`
//go:linkname {{.Pkg
.Pkgi.Pkg.Name}}_{{.Name}}_Attach {{.Pkg
.Pkgi.Pkg.Path}}.{{.Name}}_Attach
func {{.Pkg.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedRelativeTo .ImporterPkg}})) *tracing.Probe
//go:linkname {{.Pkg
t.Pkgi.Pkg.Name}}_{{.Name}}_Attach {{.Pkgt
.Pkgi.Pkg.Path}}.{{.Name}}_Attach
func {{.Pkg
t
.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedRelativeTo .ImporterPkg}})) *tracing.Probe
`
))
// magic begins all files generated by gotrace
...
...
@@ -609,7 +609,7 @@ func tracegen(pkgpath string, ctxt *build.Context, cwd string) error {
// code for trace:import imports
for
_
,
timport
:=
range
tpkg
.
Importv
{
text
.
emit
(
"
\n
// traceimport: %
v
"
,
timport
.
PkgPath
)
text
.
emit
(
"
\n
// traceimport: %
q
"
,
timport
.
PkgPath
)
impProg
,
impPkgi
,
err
:=
P
.
Import
(
timport
.
PkgPath
)
if
err
!=
nil
{
...
...
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go.ok
View file @
b6676718
...
...
@@ -10,7 +10,7 @@ import (
"net/url"
)
//
traceevent
:
traceDoSomething
(
topic
string
)
XXX
better
raw
.
Text
(
e
.
g
.
comments
)
//
traceevent
:
traceDoSomething
(
topic
string
)
type
_t_traceDoSomething
struct
{
tracing
.
Probe
...
...
@@ -37,7 +37,7 @@ func traceDoSomething_Attach(pg *tracing.ProbeGroup, probe func(topic string)) *
return
&
p
.
Probe
}
//
traceevent
:
traceNewT
(
t
*
T
)
XXX
better
raw
.
Text
(
e
.
g
.
comments
)
//
traceevent
:
traceNewT
(
t
*
T
)
type
_t_traceNewT
struct
{
tracing
.
Probe
...
...
@@ -64,7 +64,7 @@ func traceNewT_Attach(pg *tracing.ProbeGroup, probe func(t *T)) *tracing.Probe {
return
&
p
.
Probe
}
//
traceevent
:
traceNewTPre
()
XXX
better
raw
.
Text
(
e
.
g
.
comments
)
//
traceevent
:
traceNewTPre
()
type
_t_traceNewTPre
struct
{
tracing
.
Probe
...
...
@@ -91,7 +91,7 @@ func traceNewTPre_Attach(pg *tracing.ProbeGroup, probe func()) *tracing.Probe {
return
&
p
.
Probe
}
//
traceevent
:
traceURLParsed
(
u
*
url
.
URL
)
XXX
better
raw
.
Text
(
e
.
g
.
comments
)
//
traceevent
:
traceURLParsed
(
u
*
url
.
URL
)
type
_t_traceURLParsed
struct
{
tracing
.
Probe
...
...
go/xcommon/tracing/cmd/gotrace/testdata/src/b/pkg2/pkg2.go
View file @
b6676718
package
pkg2
// XXX vvv kill
//import "a/pkg1" // TODO should not be needed eventually
// trace-import another package
// NOTE "a/pkg1" is not regularly imported
//trace:import "a/pkg1"
// additional tracepoint which pkg2 defines
...
...
go/xcommon/tracing/cmd/gotrace/testdata/src/b/pkg2/ztrace.go.ok
View file @
b6676718
...
...
@@ -11,7 +11,7 @@ import (
"net/url"
)
//
traceevent
:
traceDoSomething
(
i
,
j
int
,
q
string
)
XXX
better
raw
.
Text
(
e
.
g
.
comments
)
//
traceevent
:
traceDoSomething
(
i
,
j
int
,
q
string
)
type
_t_traceDoSomething
struct
{
tracing
.
Probe
...
...
@@ -38,7 +38,7 @@ func traceDoSomething_Attach(pg *tracing.ProbeGroup, probe func(i, j int, q stri
return
&
p
.
Probe
}
//
traceimport
:
a
/
pkg1
//
traceimport
:
"a/pkg1"
//
go
:
linkname
pkg1_traceDoSomething_Attach
a
/
pkg1
.
traceDoSomething_Attach
func
pkg1_traceDoSomething_Attach
(*
tracing
.
ProbeGroup
,
func
(
topic
string
))
*
tracing
.
Probe
...
...
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