Commit 219e1ced authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8d3aec5b
......@@ -80,4 +80,4 @@ func pipenet_traceListen_Attach(*tracing.ProbeGroup, func(laddr string)) *tracin
func pipenet_traceNew_Attach(*tracing.ProbeGroup, func(name string)) *tracing.Probe
//go:linkname pipenet_traceNewHost_Attach lab.nexedi.com/kirr/neo/go/xcommon/xnet/pipenet.traceNewHost_Attach
func pipenet_traceNewHost_Attach(*tracing.ProbeGroup, func(host *Host)) *tracing.Probe
func pipenet_traceNewHost_Attach(*tracing.ProbeGroup, func(host *pipenet.Host)) *tracing.Probe
......@@ -257,24 +257,37 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
// ----------------------------------------
// TypedArgv returns argument list with types qualified relative to original package
func (te *traceEvent) TypedArgv() string {
return TypedArgvRelativeTo(te.Pkgi.Pkg)
// Argv returns comma-separated argument-list
func (te *traceEvent) Argv() string {
argv := []string{}
for _, field := range te.FuncDecl.Type.Params.List {
for _, name := range field.Names {
argv = append(argv, name.Name)
}
}
return strings.Join(argv, ", ")
}
// ArgvTyped returns argument list with types qualified relative to original package
func (te *traceEvent) ArgvTyped() string {
return te.ArgvTypedRelativeTo(te.Pkgi.Pkg)
}
func (te *traceEvent) TypedArgvRelativeTo(pkg *types.Package) string {
func (te *traceEvent) ArgvTypedRelativeTo(pkg *types.Package) string {
//format.Node(&buf, fset, te.FuncDecl.Type.Params)
argv := []string{}
// default qualifier - relative to original package
qf = func(pkg *types.Package) string {
// original package - unqualified
if pkg == te.Pkgi.Pkg {
qf := func(p *types.Package) string {
// specified package - unqualified
if p == pkg {
return ""
}
// default qualification
return pkg.Name()
return p.Name()
}
for _, field := range te.FuncDecl.Type.Params.List {
......@@ -293,18 +306,6 @@ func (te *traceEvent) TypedArgvRelativeTo(pkg *types.Package) string {
return strings.Join(argv, ", ")
}
// Argv returns comma-separated argument-list
func (te *traceEvent) Argv() string {
argv := []string{}
for _, field := range te.FuncDecl.Type.Params.List {
for _, name := range field.Names {
argv = append(argv, name.Name)
}
}
return strings.Join(argv, ", ")
}
// NeedPkgv returns packages that are needed for argument types
func (te *traceEvent) NeedPkgv() []string {
......@@ -325,12 +326,12 @@ func (te *traceEvent) NeedPkgv() []string {
// traceEventCodeTmpl is code template generated for one trace event
var traceEventCodeTmpl = template.Must(template.New("traceevent").Parse(`
// traceevent: {{.Name}}({{.TypedArgv}}) XXX better raw .Text (e.g. comments)
// traceevent: {{.Name}}({{.ArgvTyped}}) XXX better raw .Text (e.g. comments)
{{/* probe type for this trace event */ -}}
type _t_{{.Name}} struct {
tracing.Probe
probefunc func({{.TypedArgv}})
probefunc func({{.ArgvTyped}})
}
{{/* list of probes attached (nil if nothing) */ -}}
......@@ -341,21 +342,21 @@ var _{{.Name}} *_t_{{.Name}}
* after https://github.com/golang/go/issues/19348 is done this separate
* checking function will be inlined and tracepoint won't cost a function
* call when it is disabled */ -}}
func {{.Name}}({{.TypedArgv}}) {
func {{.Name}}({{.ArgvTyped}}) {
if _{{.Name}} != nil {
_{{.Name}}_run({{.Argv}})
}
}
{{/* function to notify attached probes */ -}}
func _{{.Name}}_run({{.TypedArgv}}) {
func _{{.Name}}_run({{.ArgvTyped}}) {
for p := _{{.Name}}; p != nil; p = (*_t_{{.Name}})(unsafe.Pointer(p.Next())) {
p.probefunc({{.Argv}})
}
}
{{/* 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({{.ArgvTyped}})) *tracing.Probe {
p := _t_{{.Name}}{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_{{.Name}})), &p.Probe)
return &p.Probe
......@@ -363,10 +364,9 @@ func {{.Name}}_Attach(pg *tracing.ProbeGroup, probe func({{.TypedArgv}})) *traci
`))
// traceEventImportTmpl is code template generated for importing one trace event
// FIXME func args types must be qualified
var traceEventImportTmpl = template.Must(template.New("traceimport").Parse(`
//go:linkname {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach {{.Pkgi.Pkg.Path}}.{{.Name}}_Attach
func {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.TypedArgv}})) *tracing.Probe
func {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedRelativeTo .ImporterPkg}})) *tracing.Probe
`))
// magic begins all files generated by gotrace
......@@ -507,7 +507,11 @@ func tracegen(pkgpath string) error {
for _, event := range impPkg.Eventv {
needPkg.Add(event.NeedPkgv()...)
err = traceEventImportTmpl.Execute(text, event)
importedEvent := struct{
*traceEvent
ImporterPkg *types.Package
} {event, pkgi.Pkg }
err = traceEventImportTmpl.Execute(text, importedEvent)
if err != nil {
panic(err) // XXX
}
......
// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.
package pipenet
// code generated for tracepoints
import (
"lab.nexedi.com/kirr/neo/go/xcommon/tracing"
"unsafe"
"net"
)
// traceevent: traceAccept(conn net.Conn) XXX better raw .Text (e.g. comments)
type _t_traceAccept struct {
tracing.Probe
probefunc func(conn net.Conn)
}
var _traceAccept *_t_traceAccept
func traceAccept(conn net.Conn) {
if _traceAccept != nil {
_traceAccept_run(conn)
}
}
func _traceAccept_run(conn net.Conn) {
for p := _traceAccept; p != nil; p = (*_t_traceAccept)(unsafe.Pointer(p.Next())) {
p.probefunc(conn)
}
}
func traceAccept_Attach(pg *tracing.ProbeGroup, probe func(conn net.Conn)) *tracing.Probe {
p := _t_traceAccept{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceAccept)), &p.Probe)
return &p.Probe
}
// traceevent: traceDial(addr string) XXX better raw .Text (e.g. comments)
type _t_traceDial struct {
tracing.Probe
probefunc func(addr string)
}
var _traceDial *_t_traceDial
func traceDial(addr string) {
if _traceDial != nil {
_traceDial_run(addr)
}
}
func _traceDial_run(addr string) {
for p := _traceDial; p != nil; p = (*_t_traceDial)(unsafe.Pointer(p.Next())) {
p.probefunc(addr)
}
}
func traceDial_Attach(pg *tracing.ProbeGroup, probe func(addr string)) *tracing.Probe {
p := _t_traceDial{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceDial)), &p.Probe)
return &p.Probe
}
// traceevent: traceListen(laddr string) XXX better raw .Text (e.g. comments)
type _t_traceListen struct {
tracing.Probe
probefunc func(laddr string)
}
var _traceListen *_t_traceListen
func traceListen(laddr string) {
if _traceListen != nil {
_traceListen_run(laddr)
}
}
func _traceListen_run(laddr string) {
for p := _traceListen; p != nil; p = (*_t_traceListen)(unsafe.Pointer(p.Next())) {
p.probefunc(laddr)
}
}
func traceListen_Attach(pg *tracing.ProbeGroup, probe func(laddr string)) *tracing.Probe {
p := _t_traceListen{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceListen)), &p.Probe)
return &p.Probe
}
// traceevent: traceNew(name string) XXX better raw .Text (e.g. comments)
type _t_traceNew struct {
tracing.Probe
probefunc func(name string)
}
var _traceNew *_t_traceNew
func traceNew(name string) {
if _traceNew != nil {
_traceNew_run(name)
}
}
func _traceNew_run(name string) {
for p := _traceNew; p != nil; p = (*_t_traceNew)(unsafe.Pointer(p.Next())) {
p.probefunc(name)
}
}
func traceNew_Attach(pg *tracing.ProbeGroup, probe func(name string)) *tracing.Probe {
p := _t_traceNew{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceNew)), &p.Probe)
return &p.Probe
}
// traceevent: traceNewHost(host *Host) XXX better raw .Text (e.g. comments)
type _t_traceNewHost struct {
tracing.Probe
probefunc func(host *Host)
}
var _traceNewHost *_t_traceNewHost
func traceNewHost(host *Host) {
if _traceNewHost != nil {
_traceNewHost_run(host)
}
}
func _traceNewHost_run(host *Host) {
for p := _traceNewHost; p != nil; p = (*_t_traceNewHost)(unsafe.Pointer(p.Next())) {
p.probefunc(host)
}
}
func traceNewHost_Attach(pg *tracing.ProbeGroup, probe func(host *Host)) *tracing.Probe {
p := _t_traceNewHost{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceNewHost)), &p.Probe)
return &p.Probe
}
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