Commit f3f9949f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0fcbdc95
......@@ -121,6 +121,7 @@ func (tc *TraceChecker) ExpectNetTx(src, dst string, pkt string) {
}
*/
//trace:import lab.nexedi.com/kirr/neo/go/neo
// M drives cluster with 1 S through recovery -> verification -> service -> shutdown
func TestMasterStorage(t *testing.T) {
......
......@@ -182,31 +182,20 @@ func parseTraceEvent(pkgi *loader.PackageInfo, text string) (*traceEvent, error)
return &traceEvent{pkgi.Pkg.Path(), declf}, nil
}
// tracegen generates code according to tracing directives in a package @ pkgpath
func tracegen(pkgpath string) 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
conf := loader.Config{
ParserMode: parser.ParseComments,
TypeCheckFuncBodies: func(path string) bool { return false },
}
conf.Import(pkgpath)
// load package + all its imports
lprog, err := conf.Load()
if err != nil {
log.Fatal(err)
}
pkg := lprog.InitialPackages()[0]
//fmt.Println(pkg)
// Package represents tracing-related information about a package
type Package struct {
PkgPath string
Eventv []*traceEvent // trace events this package defines
Importv []string // packages (pkgpath) this package trace imports
}
eventv := []*traceEvent{} // events this package defines
importv := []string{} // packages (pkgpath) this package trace imports
// packageTrace returns tracing information about a package
func packageTrace(lprog *loader.Program, pkgi *loader.PackageInfo) *Package {
eventv := []*traceEvent{}
importv := []string{}
// go through files of the package and process //trace: directives
for _, file := range pkg.Files { // ast.File
for _, file := range pkgi.Files { // ast.File
for _, commgroup := range file.Comments { // ast.CommentGroup
for _, comment := range commgroup.List { // ast.Comment
pos := lprog.Fset.Position(comment.Slash)
......@@ -229,7 +218,7 @@ func tracegen(pkgpath string) error {
directive, arg := textv[0], textv[1]
switch directive {
case "//trace:event":
event, err := parseTraceEvent(pkg, arg)
event, err := parseTraceEvent(pkgi, arg)
if err != nil {
log.Fatalf("%v: %v", pos, err)
}
......@@ -247,9 +236,36 @@ func tracegen(pkgpath string) error {
}
}
// generate code for trace:event definitions
sort.Sort(byEventName(eventv))
for _, event := range eventv {
sort.Strings(importv)
return &Package{PkgPath: pkgi.Pkg.Path(), Eventv: eventv, Importv: importv}
}
// tracegen generates code according to tracing directives in a package @ pkgpath
func tracegen(pkgpath string) 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
conf := loader.Config{
ParserMode: parser.ParseComments,
TypeCheckFuncBodies: func(path string) bool { return false },
}
conf.Import(pkgpath)
// load package + all its imports
lprog, err := conf.Load()
if err != nil {
log.Fatal(err)
}
pkgi := lprog.InitialPackages()[0]
//fmt.Println(pkgi)
pkg := packageTrace(lprog, pkgi)
// generate code for trace:event definitions
for _, event := range pkg.Eventv {
err = traceEventCodeTmpl.Execute(os.Stdout, event)
if err != nil {
panic(err)
......@@ -260,12 +276,14 @@ func tracegen(pkgpath string) error {
// generate code for trace:import imports
fmt.Println()
for _, pkgpath := range importv {
for _, pkgpath := range pkg.Importv {
fmt.Printf("// traceimport TODO %v\n", pkgpath)
}
// TODO check export hash
// TODO trace.s with "// empty .s so `go build` does not use -complete for go:linkname to work"
return nil // XXX
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment