MCPcopy Create free account
hub / github.com/subtrace/subtrace / getEventTemplate

Method getEventTemplate

cmd/run/engine/process/process.go:63–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63func (p *Process) getEventTemplate() *event.Event {
64 if tmpl := p.tmpl.Load(); tmpl != nil {
65 return tmpl
66 }
67
68 tmpl := p.global.Config.GetEventTemplate()
69 tmpl.Set("process_id", fmt.Sprintf("%d", p.PID))
70
71 if path, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", p.PID)); err == nil {
72 tmpl.Set("process_executable_name", filepath.Base(path))
73 }
74
75 if info, err := os.Stat(fmt.Sprintf("/proc/%d/exe", p.PID)); err == nil {
76 tmpl.Set("process_executable_size", fmt.Sprintf("%d", info.Size()))
77 }
78
79 if cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", p.PID)); err == nil {
80 var parts []string
81 args := bytes.Split(cmdline, []byte{0})
82 for i := 0; i < len(args)-1; i++ {
83 parts = append(parts, string(args[i]))
84 }
85 tmpl.Set("process_command_line", strings.Join(parts, " "))
86 }
87
88 if info, err := os.Stat(fmt.Sprintf("/proc/%d", p.PID)); err == nil {
89 if sys, ok := info.Sys().(*syscall.Stat_t); ok {
90 if name, err := findUsername(sys.Uid); err == nil && name != "" {
91 tmpl.Set("process_user", name)
92 } else {
93 tmpl.Set("process_user", fmt.Sprintf("%d", sys.Uid))
94 }
95 }
96 }
97
98 p.tmpl.Store(tmpl)
99 return tmpl
100}
101
102func (p *Process) LogValue() slog.Value {
103 select {

Callers 3

handleFcntlMethod · 0.95
handleSocketMethod · 0.95
ImportInodeMethod · 0.95

Calls 4

findUsernameFunction · 0.85
LoadMethod · 0.80
GetEventTemplateMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected