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
f67bb046
Commit
f67bb046
authored
Jun 29, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c9762c3f
Changes
2
Show 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 {
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
{
bytes
.
Buffer
}
...
...
@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string {
}
// 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
// load anything except the package in question
// TODO -> use just AST parsing for loading?
...
...
@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write output to ztrace.go
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
{
log
.
Fatal
(
err
)
}
...
...
@@ -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
ztrace_s
:=
filepath
.
Join
(
pkgdir
,
"ztrace.s"
)
if
len
(
pkg
.
Importv
)
==
0
{
err
=
w
.
removeFile
(
ztrace_s
)
err
=
removeFile
(
ztrace_s
)
}
else
{
text
.
Reset
()
text
.
WriteString
(
magic
)
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
{
...
...
@@ -610,7 +591,7 @@ TODO ...
}
pkgpath
:=
argv
[
0
]
err
:=
tracegen
(
pkgpath
,
build
.
Default
)
err
:=
tracegen
(
pkgpath
,
&
build
.
Default
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
View file @
f67bb046
...
...
@@ -2,26 +2,15 @@ package main
import
(
"go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"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 {
mw.wrote[path] = string(data)
return nil
}
func (mw *memWriter) removeFile(path) error {
mw.removed.Add(path)
return nil
}
*/
"lab.nexedi.com/kirr/go123/exc"
)
func
xglob
(
t
*
testing
.
T
,
pattern
string
)
[]
string
{
t
.
Helper
()
...
...
@@ -41,20 +30,20 @@ const (
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// 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
)
if
err
!=
nil
{
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
)
if
info
.
IsDir
()
{
err
:=
os
.
Mkdir
(
dstpath
,
0777
)
if
err
!=
nil
{
return
err
}
return
cpR
(
srcpath
,
dstpath
)
return
prepareTestTree
(
srcpath
,
dstpath
,
mode
)
}
var
isOk
,
isRm
bool
...
...
@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
isOk
=
true
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".ok"
)
}
if
strings
.
h
asSuffix
(
srcpath
,
".rm"
)
{
if
strings
.
H
asSuffix
(
srcpath
,
".rm"
)
{
isRm
=
true
dstpath
=
strings
.
TrimSuffix
(
dstpath
,
".rm"
)
}
...
...
@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
}
switch
mode
{
case
p
repareGolden
:
case
TreeP
repareGolden
:
// no removed files in golden tree
if
isRm
{
return
nil
}
case
p
repareWork
:
case
TreeP
repareWork
:
// no ok files initially in work tree
if
isOk
{
return
nil
...
...
@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
})
}
xprepareTree
(
t
*
testing
.
T
,
src
,
dst
string
,
mode
p
repareMode
)
{
err
:=
prepareTestTree
(
src
,
dst
)
func
xprepareTree
(
src
,
dst
string
,
mode
TreeP
repareMode
)
{
err
:=
prepareTestTree
(
src
,
dst
,
mode
)
exc
.
Raiseif
(
err
)
}
...
...
@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) {
xprepareTree
(
"testdata"
,
work
,
TreePrepareWork
)
// test build context with GOPATH set to work tree
var
tBuildCtx
=
build
.
Context
{
var
tBuildCtx
=
&
build
.
Context
{
GOARCH
:
"amd64"
,
GOOS
:
"linux"
,
GOROOT
:
runtime
.
GOROOT
(),
GOPATH
:
work
,
Compiler
:
runtime
.
Compiler
()
,
Compiler
:
runtime
.
Compiler
,
}
// 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