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
f67bb046
Commit
f67bb046
authored
Jun 29, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c9762c3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
52 deletions
+22
-52
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+5
-24
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
+17
-28
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
f67bb046
...
@@ -416,25 +416,6 @@ func removeFile(path string) error {
...
@@ -416,25 +416,6 @@ func removeFile(path string) error {
return
os
.
Remove
(
path
)
return
os
.
Remove
(
path
)
}
}
/*
// writer is interface for gotrace output operations
// made for testing
type writer interface {
writeFile(path string, data []byte) error
removeFile(path string) error
}
type fsWriter struct{}
func (fsWriter) writeFile(path string, data []byte) error {
return writeFile(path, data)
}
func (fsWriter) removeFile(path string) error {
return removeFile(path)
}
*/
type
Buffer
struct
{
type
Buffer
struct
{
bytes
.
Buffer
bytes
.
Buffer
}
}
...
@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string {
...
@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string {
}
}
// tracegen generates code according to tracing directives in a package @ pkgpath
// tracegen generates code according to tracing directives in a package @ pkgpath
func
tracegen
(
pkgpath
string
,
buildCtx
*
build
.
Context
,
w
writer
)
error
{
func
tracegen
(
pkgpath
string
,
buildCtx
*
build
.
Context
)
error
{
// XXX typechecking is much slower than parsing + we don't need to
// XXX typechecking is much slower than parsing + we don't need to
// load anything except the package in question
// load anything except the package in question
// TODO -> use just AST parsing for loading?
// TODO -> use just AST parsing for loading?
...
@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
...
@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write output to ztrace.go
// write output to ztrace.go
fulltext
:=
append
(
prologue
.
Bytes
(),
text
.
Bytes
()
...
)
fulltext
:=
append
(
prologue
.
Bytes
(),
text
.
Bytes
()
...
)
err
=
w
.
w
riteFile
(
filepath
.
Join
(
pkgdir
,
"ztrace.go"
),
fulltext
)
err
=
writeFile
(
filepath
.
Join
(
pkgdir
,
"ztrace.go"
),
fulltext
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
...
@@ -574,13 +555,13 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
...
@@ -574,13 +555,13 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write empty ztrace.s so go:linkname works, if there are trace imports
// write empty ztrace.s so go:linkname works, if there are trace imports
ztrace_s
:=
filepath
.
Join
(
pkgdir
,
"ztrace.s"
)
ztrace_s
:=
filepath
.
Join
(
pkgdir
,
"ztrace.s"
)
if
len
(
pkg
.
Importv
)
==
0
{
if
len
(
pkg
.
Importv
)
==
0
{
err
=
w
.
removeFile
(
ztrace_s
)
err
=
removeFile
(
ztrace_s
)
}
else
{
}
else
{
text
.
Reset
()
text
.
Reset
()
text
.
WriteString
(
magic
)
text
.
WriteString
(
magic
)
text
.
emit
(
"// empty .s so `go build` does not use -complete for go:linkname to work"
)
text
.
emit
(
"// empty .s so `go build` does not use -complete for go:linkname to work"
)
err
=
w
.
w
riteFile
(
ztrace_s
,
text
.
Bytes
())
err
=
writeFile
(
ztrace_s
,
text
.
Bytes
())
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -610,7 +591,7 @@ TODO ...
...
@@ -610,7 +591,7 @@ TODO ...
}
}
pkgpath
:=
argv
[
0
]
pkgpath
:=
argv
[
0
]
err
:=
tracegen
(
pkgpath
,
build
.
Default
)
err
:=
tracegen
(
pkgpath
,
&
build
.
Default
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
...
...
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
View file @
f67bb046
...
@@ -2,26 +2,15 @@ package main
...
@@ -2,26 +2,15 @@ package main
import
(
import
(
"go/build"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"testing"
)
/*
// memWriter saves in memory filesystem modifications gotrace wanted to made
type memWriter struct {
wrote map[string]string // path -> data
removed StrSet
}
func (mw *memWriter) writeFile(path string, data []byte) error {
"lab.nexedi.com/kirr/go123/exc"
mw.wrote[path] = string(data)
)
return nil
}
func (mw *memWriter) removeFile(path) error {
mw.removed.Add(path)
return nil
}
*/
func
xglob
(
t
*
testing
.
T
,
pattern
string
)
[]
string
{
func
xglob
(
t
*
testing
.
T
,
pattern
string
)
[]
string
{
t
.
Helper
()
t
.
Helper
()
...
@@ -41,20 +30,20 @@ const (
...
@@ -41,20 +30,20 @@ const (
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// dst should not initially exist
// dst should not initially exist
func
prepareTestTree
(
src
,
dst
string
,
mode
p
repareMode
)
error
{
func
prepareTestTree
(
src
,
dst
string
,
mode
TreeP
repareMode
)
error
{
err
:=
os
.
MkdirAll
(
dst
,
0777
)
err
:=
os
.
MkdirAll
(
dst
,
0777
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
filepath
.
Walk
(
src
,
func
(
srcpath
string
,
info
os
.
FileInfo
,
err
error
)
error
{
return
filepath
.
Walk
(
src
,
func
(
srcpath
string
,
info
os
.
FileInfo
,
err
error
)
error
{
dstpath
:=
dst
+
"/"
+
strings
.
TrimPrefix
(
srcpath
,
src
)
dstpath
:=
dst
+
"/"
+
strings
.
TrimPrefix
(
srcpath
,
src
)
if
info
.
IsDir
()
{
if
info
.
IsDir
()
{
err
:=
os
.
Mkdir
(
dstpath
,
0777
)
err
:=
os
.
Mkdir
(
dstpath
,
0777
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
cpR
(
srcpath
,
dstpath
)
return
prepareTestTree
(
srcpath
,
dstpath
,
mode
)
}
}
var
isOk
,
isRm
bool
var
isOk
,
isRm
bool
...
@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
...
@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
isOk
=
true
isOk
=
true
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".ok"
)
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".ok"
)
}
}
if
strings
.
h
asSuffix
(
srcpath
,
".rm"
)
{
if
strings
.
H
asSuffix
(
srcpath
,
".rm"
)
{
isRm
=
true
isRm
=
true
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".rm"
)
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".rm"
)
}
}
...
@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
...
@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
}
}
switch
mode
{
switch
mode
{
case
p
repareGolden
:
case
TreeP
repareGolden
:
// no removed files in golden tree
// no removed files in golden tree
if
isRm
{
if
isRm
{
return
nil
return
nil
}
}
case
p
repareWork
:
case
TreeP
repareWork
:
// no ok files initially in work tree
// no ok files initially in work tree
if
isOk
{
if
isOk
{
return
nil
return
nil
...
@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
...
@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
})
})
}
}
xprepareTree
(
t
*
testing
.
T
,
src
,
dst
string
,
mode
p
repareMode
)
{
func
xprepareTree
(
src
,
dst
string
,
mode
TreeP
repareMode
)
{
err
:=
prepareTestTree
(
src
,
dst
)
err
:=
prepareTestTree
(
src
,
dst
,
mode
)
exc
.
Raiseif
(
err
)
exc
.
Raiseif
(
err
)
}
}
...
@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) {
...
@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) {
xprepareTree
(
"testdata"
,
work
,
TreePrepareWork
)
xprepareTree
(
"testdata"
,
work
,
TreePrepareWork
)
// test build context with GOPATH set to work tree
// test build context with GOPATH set to work tree
var
tBuildCtx
=
build
.
Context
{
var
tBuildCtx
=
&
build
.
Context
{
GOARCH
:
"amd64"
,
GOARCH
:
"amd64"
,
GOOS
:
"linux"
,
GOOS
:
"linux"
,
GOROOT
:
runtime
.
GOROOT
(),
GOROOT
:
runtime
.
GOROOT
(),
GOPATH
:
work
,
GOPATH
:
work
,
Compiler
:
runtime
.
Compiler
()
,
Compiler
:
runtime
.
Compiler
,
}
}
// XXX autodetect (go list ?)
// XXX autodetect (go list ?)
...
...
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