Commit 0fcbdc95 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 92e8e1e0
...@@ -737,6 +737,9 @@ func (c *Conn) err(op string, e error) error { ...@@ -737,6 +737,9 @@ func (c *Conn) err(op string, e error) error {
//trace:event traceConnRecv(c *Conn /*aaa*/, msg Msg) //trace:event traceConnRecv(c *Conn /*aaa*/, msg Msg)
//trace:event traceConnSend(c *Conn, msg Msg) // XXX -> traceConnSendPre ? //trace:event traceConnSend(c *Conn, msg Msg) // XXX -> traceConnSendPre ?
//XXX temp
//trace:import lab.nexedi.com/kirr/neo/go/xcommon/xnet/pipenet
// Recv receives message // Recv receives message
// it receives packet and decodes message from it // it receives packet and decodes message from it
func (c *Conn) Recv() (Msg, error) { func (c *Conn) Recv() (Msg, error) {
......
...@@ -59,6 +59,7 @@ type traceEvent struct { ...@@ -59,6 +59,7 @@ type traceEvent struct {
//Name string //Name string
//Argv string //Argv string
PkgPath string // XXX -> pkg ?
*ast.FuncDecl *ast.FuncDecl
} }
...@@ -101,50 +102,57 @@ func (v byEventName) Less(i, j int) bool { return v[i].Name.Name < v[j].Name.Nam ...@@ -101,50 +102,57 @@ func (v byEventName) Less(i, j int) bool { return v[i].Name.Name < v[j].Name.Nam
func (v byEventName) Swap(i, j int) { v[i], v[j] = v[j], v[i] } func (v byEventName) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func (v byEventName) Len() int { return len(v) } func (v byEventName) Len() int { return len(v) }
// traceEventCode is code template generated for one trace event // traceEventCodeTmpl is code template generated for one trace event
const traceEventCode = ` var traceEventCodeTmpl = template.Must(template.New("traceevent").Parse(`
// traceevent: {{.Name}}({{.TypedArgv}}) XXX better raw .Text (e.g. comments) // traceevent: {{.Name}}({{.TypedArgv}}) XXX better raw .Text (e.g. comments)
{{/* probe type for this trace event */}} {{/* probe type for this trace event */ -}}
type _t_{{.Name}} struct { type _t_{{.Name}} struct {
tracing.Probe tracing.Probe
probefunc func({{.TypedArgv}}) probefunc func({{.TypedArgv}})
} }
{{/* list of probes attached (nil if nothing) */}} {{/* list of probes attached (nil if nothing) */ -}}
var _{{.Name}} *_t_{{.Name}} var _{{.Name}} *_t_{{.Name}}
{{/* function which event producer calls to notify about the event {{/* function which event producer calls to notify about the event
* *
* after https://github.com/golang/go/issues/19348 is done this separate * after https://github.com/golang/go/issues/19348 is done this separate
* checking function will be inlined and tracepoint won't cost a function * checking function will be inlined and tracepoint won't cost a function
* call when it is disabled */}} * call when it is disabled */ -}}
func {{.Name}}({{.TypedArgv}}) { func {{.Name}}({{.TypedArgv}}) {
if _{{.Name}} != nil { if _{{.Name}} != nil {
_{{.Name}}_run({{.Argv}}) _{{.Name}}_run({{.Argv}})
} }
} }
{{/* function to notify attached probes */}} {{/* function to notify attached probes */ -}}
func _{{.Name}}{{.Argv}}_run({{.Argv}}) { func _{{.Name}}_run({{.Argv}}) {
for p := _{{.Name}}; p != nil; p = (*_t_{{.Name}})(unsafe.Pointer(p.Next())) { for p := _{{.Name}}; p != nil; p = (*_t_{{.Name}})(unsafe.Pointer(p.Next())) {
p.probefunc({{.Argv}}) p.probefunc({{.Argv}})
} }
} }
{{/* function to attach a probe to tracepoint */}} {{/* function to attach a probe to tracepoint */ -}}
func {{.Name}}_Attach(pg *tracing.ProbeGroup, probe func({{.TypedArgv}})) *tracing.Probe { func {{.Name}}_Attach(pg *tracing.ProbeGroup, probe func({{.TypedArgv}})) *tracing.Probe {
p := _t_{{.Name}}{probefunc: probe} p := _t_{{.Name}}{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_{{.Name}}), &p.Probe) tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_{{.Name}}), &p.Probe)
return &p.Probe return &p.Probe
} }
` `))
var traceEventCodeTmpl = template.Must(template.New("traceevent").Parse(traceEventCode)) // traceEventImportTmpl is code template generated for importing one trace event
var traceEventImportTmpl = template.Must(template.New("traceimport").Parse(`
// traceimport: {{.Pkgi.Pkg.Path}} {{.Name}}
// FIXME func args typs must be qualified
//go:linkname {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach {{.Pkgi.Pkg.Path}}.{{.Name}}_Attach
func {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func(.TypedArgv)) *tracing.Probe
`))
// parseTraceEvent parses trace event definition into traceEvent // parseTraceEvent parses trace event definition into traceEvent
// text is text argument after "//trace:event " // text is text argument after "//trace:event "
func parseTraceEvent(text string) (*traceEvent, error) { func parseTraceEvent(pkgi *loader.PackageInfo, text string) (*traceEvent, error) {
if !strings.HasPrefix(text, "trace") { if !strings.HasPrefix(text, "trace") {
return nil, fmt.Errorf("trace event must start with \"trace\"") // XXX pos return nil, fmt.Errorf("trace event must start with \"trace\"") // XXX pos
} }
...@@ -171,7 +179,7 @@ func parseTraceEvent(text string) (*traceEvent, error) { ...@@ -171,7 +179,7 @@ func parseTraceEvent(text string) (*traceEvent, error) {
return nil, fmt.Errorf("trace event must not return results") return nil, fmt.Errorf("trace event must not return results")
} }
return &traceEvent{declf}, nil return &traceEvent{pkgi.Pkg.Path(), declf}, nil
} }
// tracegen generates code according to tracing directives in a package @ pkgpath // tracegen generates code according to tracing directives in a package @ pkgpath
...@@ -194,8 +202,8 @@ func tracegen(pkgpath string) error { ...@@ -194,8 +202,8 @@ func tracegen(pkgpath string) error {
pkg := lprog.InitialPackages()[0] pkg := lprog.InitialPackages()[0]
//fmt.Println(pkg) //fmt.Println(pkg)
eventv := []*traceEvent{} // events this package defines eventv := []*traceEvent{} // events this package defines
importv := map[/*pkgpath*/string][]traceEvent{} // events this package imports importv := []string{} // packages (pkgpath) this package trace imports
// go through files of the package and process //trace: directives // go through files of the package and process //trace: directives
for _, file := range pkg.Files { // ast.File for _, file := range pkg.Files { // ast.File
...@@ -221,7 +229,7 @@ func tracegen(pkgpath string) error { ...@@ -221,7 +229,7 @@ func tracegen(pkgpath string) error {
directive, arg := textv[0], textv[1] directive, arg := textv[0], textv[1]
switch directive { switch directive {
case "//trace:event": case "//trace:event":
event, err := parseTraceEvent(arg) event, err := parseTraceEvent(pkg, arg)
if err != nil { if err != nil {
log.Fatalf("%v: %v", pos, err) log.Fatalf("%v: %v", pos, err)
} }
...@@ -229,8 +237,8 @@ func tracegen(pkgpath string) error { ...@@ -229,8 +237,8 @@ func tracegen(pkgpath string) error {
eventv = append(eventv, event) eventv = append(eventv, event)
case "//trace:import": case "//trace:import":
panic("TODO") // XXX reject duplicate imports
// TODO arg is pkgpath - get trace events from tha importv = append(importv, arg)
default: default:
log.Fatalf("%v: unknown tracing directive %q", pos, directive) log.Fatalf("%v: unknown tracing directive %q", pos, directive)
...@@ -248,8 +256,15 @@ func tracegen(pkgpath string) error { ...@@ -248,8 +256,15 @@ func tracegen(pkgpath string) error {
} }
} }
// TODO export hash
// generate code for trace:import imports // generate code for trace:import imports
_ = importv fmt.Println()
for _, pkgpath := range importv {
fmt.Printf("// traceimport TODO %v\n", pkgpath)
}
// TODO check export hash
return nil // XXX return nil // XXX
} }
......
// traceevent: traceConnRecv(c *Conn, msg Msg) XXX better raw .Text (e.g. comments) // traceevent: traceConnRecv(c *Conn, msg Msg) XXX better raw .Text (e.g. comments)
type _t_traceConnRecv struct { type _t_traceConnRecv struct {
tracing.Probe tracing.Probe
probefunc func(c *Conn, msg Msg) probefunc func(c *Conn, msg Msg)
} }
var _traceConnRecv *_t_traceConnRecv var _traceConnRecv *_t_traceConnRecv
func traceConnRecv(c *Conn, msg Msg) { func traceConnRecv(c *Conn, msg Msg) {
if _traceConnRecv != nil { if _traceConnRecv != nil {
_traceConnRecv_run(c, msg) _traceConnRecv_run(c, msg)
} }
} }
func _traceConnRecv_run(c, msg) {
func _traceConnRecvc, msg_run(c, msg) {
for p := _traceConnRecv; p != nil; p = (*_t_traceConnRecv)(unsafe.Pointer(p.Next())) { for p := _traceConnRecv; p != nil; p = (*_t_traceConnRecv)(unsafe.Pointer(p.Next())) {
p.probefunc(c, msg) p.probefunc(c, msg)
} }
} }
func traceConnRecv_Attach(pg *tracing.ProbeGroup, probe func(c *Conn, msg Msg)) *tracing.Probe {
func traceConnRecv_Attach(pg *tracing.ProbeGroup, probe func({31 [0xc42358be80 0xc42358bec0] 56})) *tracing.Probe {
p := _t_traceConnRecv{probefunc: probe} p := _t_traceConnRecv{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceConnRecv), &p.Probe) tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceConnRecv), &p.Probe)
return &p.Probe return &p.Probe
...@@ -33,32 +28,29 @@ func traceConnRecv_Attach(pg *tracing.ProbeGroup, probe func({31 [0xc42358be80 0 ...@@ -33,32 +28,29 @@ func traceConnRecv_Attach(pg *tracing.ProbeGroup, probe func({31 [0xc42358be80 0
// traceevent: traceConnSend(c *Conn, msg Msg) XXX better raw .Text (e.g. comments) // traceevent: traceConnSend(c *Conn, msg Msg) XXX better raw .Text (e.g. comments)
type _t_traceConnSend struct { type _t_traceConnSend struct {
tracing.Probe tracing.Probe
probefunc func(c *Conn, msg Msg) probefunc func(c *Conn, msg Msg)
} }
var _traceConnSend *_t_traceConnSend var _traceConnSend *_t_traceConnSend
func traceConnSend(c *Conn, msg Msg) { func traceConnSend(c *Conn, msg Msg) {
if _traceConnSend != nil { if _traceConnSend != nil {
_traceConnSend_run(c, msg) _traceConnSend_run(c, msg)
} }
} }
func _traceConnSend_run(c, msg) {
func _traceConnSendc, msg_run(c, msg) {
for p := _traceConnSend; p != nil; p = (*_t_traceConnSend)(unsafe.Pointer(p.Next())) { for p := _traceConnSend; p != nil; p = (*_t_traceConnSend)(unsafe.Pointer(p.Next())) {
p.probefunc(c, msg) p.probefunc(c, msg)
} }
} }
func traceConnSend_Attach(pg *tracing.ProbeGroup, probe func(c *Conn, msg Msg)) *tracing.Probe {
func traceConnSend_Attach(pg *tracing.ProbeGroup, probe func({31 [0xc42358bf40 0xc42358bf80] 48})) *tracing.Probe {
p := _t_traceConnSend{probefunc: probe} p := _t_traceConnSend{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceConnSend), &p.Probe) tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceConnSend), &p.Probe)
return &p.Probe return &p.Probe
} }
// traceimport TODO lab.nexedi.com/kirr/neo/go/xcommon/xnet/pipenet
...@@ -125,11 +125,15 @@ type dialReq struct { ...@@ -125,11 +125,15 @@ type dialReq struct {
// ---------------------------------------- // ----------------------------------------
// FIXME temp for testing
//trace:event traceNew(name string)
// New creates new pipenet Network // New creates new pipenet Network
// name is name of this network under "pipe" namespace, e.g. "α" will give full network name "pipeα". // name is name of this network under "pipe" namespace, e.g. "α" will give full network name "pipeα".
// //
// New does not check whether network name provided is unique. // New does not check whether network name provided is unique.
func New(name string) *Network { func New(name string) *Network {
traceNew(name)
return &Network{name: name, hostMap: make(map[string]*Host)} return &Network{name: name, hostMap: make(map[string]*Host)}
} }
......
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