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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
0da5fa01
Commit
0da5fa01
authored
Jul 03, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
79928d00
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
100 additions
and
67 deletions
+100
-67
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+95
-60
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
+2
-1
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
+0
-6
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/pkg4.go
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/pkg4.go
+3
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.go.rm
...mmon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.go.rm
+0
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.s.rm
...ommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.s.rm
+0
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.go.rm
...tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.go.rm
+0
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.s.rm
.../tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.s.rm
+0
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.go.rm
...acing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.go.rm
+0
-0
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.s.rm
...racing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.s.rm
+0
-0
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
0da5fa01
...
...
@@ -494,6 +494,7 @@ func (s StrSet) Itemv() []string {
return
itemv
}
/*
// findPackageNoZTrace is (*build.Context).Import but filters-out ztrace* files from found package
//
// we don't load what should be generated by us for 2 reasons:
...
...
@@ -528,6 +529,7 @@ func findPackageNoZTrace(ctxt *build.Context, importPath, fromDir string, mode b
return bp, err
}
*/
// tracegen generates code according to tracing directives in a package @ pkgpath
//
...
...
@@ -536,12 +538,36 @@ func findPackageNoZTrace(ctxt *build.Context, importPath, fromDir string, mode b
func
tracegen
(
pkgpath
string
,
ctxt
*
build
.
Context
,
cwd
string
)
error
{
// TODO test-only with .TestGoFiles .XTestGoFiles
// filter-out ztrace* files when disovering packages
//
// we don't load what should be generated by us for 2 reasons:
// - code generated could be wrong with older version of the
// tool - it should not prevent from regenerating.
// - generated code imports packages which might be not there
// yet in gopath (lab.nexedi.com/kirr/go123/tracing)
ctxtReadDir
:=
ctxt
.
ReadDir
if
ctxtReadDir
==
nil
{
ctxtReadDir
=
ioutil
.
ReadDir
}
ctxtNoZTrace
:=
*
ctxt
ctxtNoZTrace
.
ReadDir
=
func
(
dir
string
)
([]
os
.
FileInfo
,
error
)
{
fv
,
err
:=
ctxtReadDir
(
dir
)
okv
:=
fv
[
:
0
]
for
_
,
f
:=
range
fv
{
if
!
strings
.
HasPrefix
(
f
.
Name
(),
"ztrace"
)
{
okv
=
append
(
okv
,
f
)
}
}
return
okv
,
err
}
// XXX text
conf
:=
loader
.
Config
{
ParserMode
:
parser
.
ParseComments
,
TypeCheckFuncBodies
:
func
(
path
string
)
bool
{
return
false
},
Build
:
ctxt
,
Build
:
&
ctxtNoZTrace
,
Cwd
:
cwd
,
FindPackage
:
findPackageNoZTrace
,
//
FindPackage: findPackageNoZTrace,
}
conf
.
Import
(
pkgpath
)
...
...
@@ -570,76 +596,85 @@ func tracegen(pkgpath string, ctxt *build.Context, cwd string) error {
return
err
// XXX err ctx
}
// prologue
prologue
:=
&
Buffer
{}
prologue
.
WriteString
(
magic
)
prologue
.
emit
(
"
\n
package %v"
,
tpkg
.
Pkgi
.
Pkg
.
Name
())
prologue
.
emit
(
"// code generated for tracepoints"
)
prologue
.
emit
(
"
\n
import ("
)
prologue
.
emit
(
"
\t
%q"
,
"lab.nexedi.com/kirr/neo/go/xcommon/tracing"
)
prologue
.
emit
(
"
\t
%q"
,
"unsafe"
)
// import of all packages needed for used types will go here in the end
needPkg
:=
StrSet
{}
// code for trace:event definitions
text
:=
&
Buffer
{}
for
_
,
event
:=
range
tpkg
.
Eventv
{
needPkg
.
Add
(
event
.
NeedPkgv
()
...
)
err
=
traceEventCodeTmpl
.
Execute
(
text
,
event
)
// write ztrace.go with code generated for trace events and imports
ztrace_go
:=
filepath
.
Join
(
pkgdir
,
"ztrace.go"
)
if
len
(
tpkg
.
Eventv
)
==
0
&&
len
(
tpkg
.
Importv
)
==
0
{
err
=
removeFile
(
ztrace_go
)
if
err
!=
nil
{
panic
(
err
)
// XXX
return
err
}
}
else
{
// prologue
prologue
:=
&
Buffer
{}
prologue
.
WriteString
(
magic
)
prologue
.
emit
(
"
\n
package %v"
,
tpkg
.
Pkgi
.
Pkg
.
Name
())
prologue
.
emit
(
"// code generated for tracepoints"
)
prologue
.
emit
(
"
\n
import ("
)
prologue
.
emit
(
"
\t
%q"
,
"lab.nexedi.com/kirr/neo/go/xcommon/tracing"
)
prologue
.
emit
(
"
\t
%q"
,
"unsafe"
)
// import of all packages needed for used types will go here in the end
needPkg
:=
StrSet
{}
// code for trace:event definitions
text
:=
&
Buffer
{}
for
_
,
event
:=
range
tpkg
.
Eventv
{
needPkg
.
Add
(
event
.
NeedPkgv
()
...
)
err
=
traceEventCodeTmpl
.
Execute
(
text
,
event
)
if
err
!=
nil
{
panic
(
err
)
// XXX
}
}
}
// TODO export hash
// code for trace:import imports
for
_
,
timport
:=
range
tpkg
.
Importv
{
text
.
emit
(
"
\n
// traceimport: %v"
,
timport
.
PkgPath
)
// TODO export hash
impPkgi
:=
lprog
.
Package
(
timport
.
PkgPath
)
if
impPkgi
==
nil
{
// TODO do not require vvv
return
fmt
.
Errorf
(
"%v: package %s must be also regularly imported"
,
timport
.
Pos
,
timport
.
PkgPath
)
}
// code for trace:import imports
for
_
,
timport
:=
range
tpkg
.
Importv
{
text
.
emit
(
"
\n
// traceimport: %v"
,
timport
.
PkgPath
)
impPkg
,
err
:=
packageTrace
(
lprog
,
impPkgi
)
if
err
!=
nil
{
return
err
// XXX err ctx
}
impPkgi
:=
lprog
.
Package
(
timport
.
PkgPath
)
if
impPkgi
==
nil
{
// TODO do not require vvv
return
fmt
.
Errorf
(
"%v: package %s must be also regularly imported"
,
timport
.
Pos
,
timport
.
PkgPath
)
}
for
_
,
event
:=
range
impPkg
.
Eventv
{
needPkg
.
Add
(
event
.
NeedPkgv
()
...
)
importedEvent
:=
struct
{
*
traceEvent
ImporterPkg
*
types
.
Package
}
{
event
,
pkgi
.
Pkg
}
err
=
traceEventImportTmpl
.
Execute
(
text
,
importedEvent
)
impPkg
,
err
:=
packageTrace
(
lprog
,
impPkgi
)
if
err
!=
nil
{
panic
(
err
)
// XXX
return
err
// XXX err ctx
}
for
_
,
event
:=
range
impPkg
.
Eventv
{
needPkg
.
Add
(
event
.
NeedPkgv
()
...
)
importedEvent
:=
struct
{
*
traceEvent
ImporterPkg
*
types
.
Package
}
{
event
,
pkgi
.
Pkg
}
err
=
traceEventImportTmpl
.
Execute
(
text
,
importedEvent
)
if
err
!=
nil
{
panic
(
err
)
// XXX
}
}
}
}
// TODO check export hash
// TODO check export hash
// finish prologue with needed imports
needPkg
.
Delete
(
pkgpath
)
// our pkg - no need to import
needPkgv
:=
needPkg
.
Itemv
()
if
len
(
needPkgv
)
>
0
{
prologue
.
emit
(
""
)
}
// finish prologue with needed imports
needPkg
.
Delete
(
pkgpath
)
// our pkg - no need to import
needPkgv
:=
needPkg
.
Itemv
()
if
len
(
needPkgv
)
>
0
{
prologue
.
emit
(
""
)
}
for
_
,
needpkg
:=
range
needPkgv
{
prologue
.
emit
(
"
\t
%q"
,
needpkg
)
}
prologue
.
emit
(
")"
)
for
_
,
needpkg
:=
range
needPkgv
{
prologue
.
emit
(
"
\t
%q"
,
needpkg
)
}
prologue
.
emit
(
")"
)
// write output to ztrace.go
fulltext
:=
append
(
prologue
.
Bytes
(),
text
.
Bytes
()
...
)
err
=
writeFile
(
filepath
.
Join
(
pkgdir
,
"ztrace.go"
),
fulltext
)
if
err
!=
nil
{
return
err
// write output to ztrace.go
fulltext
:=
append
(
prologue
.
Bytes
(),
text
.
Bytes
()
...
)
err
=
writeFile
(
ztrace_go
,
fulltext
)
if
err
!=
nil
{
return
err
}
}
// write empty ztrace.s so go:linkname works, if there are trace imports
...
...
@@ -647,7 +682,7 @@ func tracegen(pkgpath string, ctxt *build.Context, cwd string) error {
if
len
(
tpkg
.
Importv
)
==
0
{
err
=
removeFile
(
ztrace_s
)
}
else
{
text
.
Reset
()
text
:=
&
Buffer
{}
text
.
WriteString
(
magic
)
text
.
emit
(
"// empty .s so `go build` does not use -complete for go:linkname to work"
)
...
...
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
View file @
0da5fa01
...
...
@@ -136,7 +136,8 @@ func TestGoTraceGen(t *testing.T) {
}
// XXX autodetect (go list ?)
testv
:=
[]
string
{
"a/pkg1"
,
"b/pkg2"
,
"c/pkg3"
}
//testv := []string{"a/pkg1", "b/pkg2", "c/pkg3", "d/pkg4"}
testv
:=
[]
string
{
"a/pkg1"
}
for
_
,
tpkg
:=
range
testv
{
err
=
tracegen
(
tpkg
,
tBuildCtx
,
""
/* = local imorts disabled */
)
...
...
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
View file @
0da5fa01
// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.
package
pkg1
import
(
"non-existent"
)
Bad
bad
bad
-
I
'
m
invalid
go
file
.
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/pkg4.go
0 → 100644
View file @
0da5fa01
package
pkg4
// this package does not use tracepoints at all
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.go.rm
0 → 100644
View file @
0da5fa01
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace.s.rm
0 → 100644
View file @
0da5fa01
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.go.rm
0 → 100644
View file @
0da5fa01
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_test.s.rm
0 → 100644
View file @
0da5fa01
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.go.rm
0 → 100644
View file @
0da5fa01
go/xcommon/tracing/cmd/gotrace/testdata/src/d/pkg4/ztrace_x_test.s.rm
0 → 100644
View file @
0da5fa01
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