Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions internal/log/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ func Infof(msg string, keysAndValues ...any) {
}

// Info logs informational messages about the general state of the profiler.
// This is a wrapper around Infof for convenience.
func Info(msg string) {
// The optional args are structured key-value pairs, and are the preferred
// alternative to the string-formatted Infof.
func Info(msg string, args ...any) {
if getLogger().Enabled(context.Background(), slog.LevelInfo) {
getLogger().Info(msg)
getLogger().Info(msg, args...)
}
}

Expand Down Expand Up @@ -88,10 +89,11 @@ func Debugf(msg string, keysAndValues ...any) {
}

// Debug logs detailed debugging information about internal profiler behavior.
// This is a wrapper around Debugf for convenience.
func Debug(msg string) {
// The optional args are structured key-value pairs, and are the preferred
// alternative to the string-formatted Debugf.
func Debug(msg string, args ...any) {
if getLogger().Enabled(context.Background(), slog.LevelDebug) {
getLogger().Debug(msg)
getLogger().Debug(msg, args...)
}
}

Expand All @@ -105,9 +107,10 @@ func Warnf(msg string, keysAndValues ...any) {
}

// Warn logs warnings in the profiler — not errors, but likely more important
// than informational messages. This is a wrapper around Warnf for convenience.
func Warn(msg string) {
// than informational messages. The optional args are structured key-value
// pairs, and are the preferred alternative to the string-formatted Warnf.
func Warn(msg string, args ...any) {
if getLogger().Enabled(context.Background(), slog.LevelWarn) {
getLogger().Warn(msg)
getLogger().Warn(msg, args...)
}
}
10 changes: 6 additions & 4 deletions interpreter/php/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func (i *phpInstance) getFunction(addr libpf.Address, typeInfo uint32) (*phpFunc
vms.zend_string.val)

if fname != "" && !util.IsValidString(fname) {
log.Debugf("Extracted invalid PHP function name at 0x%x '%v'", addr, []byte(fname))
log.Debug("Extracted invalid PHP function name",
"address", fmt.Sprintf("0x%x", addr), "name", []byte(fname))
fname = ""
}

Expand All @@ -133,7 +134,8 @@ func (i *phpInstance) getFunction(addr libpf.Address, typeInfo uint32) (*phpFunc
if classNameStrPtr != 0 {
className := i.rm.String(classNameStrPtr + vms.zend_string.val)
if className != "" && !util.IsValidString(className) {
log.Debugf("Extracted invalid PHP class name at 0x%x", addr)
log.Debug("Extracted invalid PHP class name",
"address", fmt.Sprintf("0x%x", addr))
className = ""
}
// Combine class name and function name using PHP's ClassName::methodName convention.
Expand All @@ -160,8 +162,8 @@ func (i *phpInstance) getFunction(addr libpf.Address, typeInfo uint32) (*phpFunc
sourceAddr := npsr.Ptr(fobj, vms.zend_function.op_array_filename)
sourceFileName = i.rm.String(sourceAddr + vms.zend_string.val)
if !util.IsValidString(sourceFileName) {
log.Debugf("Extracted invalid PHP source file name at 0x%x '%v'",
addr, []byte(sourceFileName))
log.Debug("Extracted invalid PHP source file name",
"address", fmt.Sprintf("0x%x", addr), "name", []byte(sourceFileName))
sourceFileName = ""
}

Expand Down
2 changes: 1 addition & 1 deletion interpreter/php/opcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (i *opcacheInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,

prefixes, err := lpm.CalculatePrefixList(dasmBuf, dasmBuf+dasmSize)
if err != nil {
log.Debugf("Producing prefixes failed: %v", err)
log.Debug("Producing prefixes failed", "error", err)
return err
}

Expand Down
18 changes: 11 additions & 7 deletions interpreter/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ type phpData struct {
}
}

// versionString returns the dotted representation of an encoded PHP version.
func versionString(ver uint32) string {
return fmt.Sprintf("%d.%d.%d", (ver>>16)&0xff, (ver>>8)&0xff, ver&0xff)
}

func (d *phpData) String() string {
ver := d.version
return fmt.Sprintf("PHP %d.%d.%d", (ver>>16)&0xff, (ver>>8)&0xff, ver&0xff)
return "PHP " + versionString(d.version)
}

func (d *phpData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libpf.Address,
Expand Down Expand Up @@ -307,14 +311,14 @@ func loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpr
var vmKind uint
vmKind, err = determineVMKind(ef)
if err != nil {
log.Debugf("PHP version %x: an error occurred while determining "+
"the VM kind (%v)",
version, err)
log.Debug("An error occurred while determining the PHP VM kind",
"version", versionString(version), "error", err)
} else if vmKind == ZEND_VM_KIND_HYBRID {
rtAddr, err = recoverExecuteExJumpLabelAddress(ef)
if err != nil {
log.Debugf("PHP version %x: an error occurred while determining "+
"the return address for execute_ex: (%v)", version, err)
log.Debug("An error occurred while determining the return address "+
"for PHP execute_ex",
"version", versionString(version), "error", err)
}
}
}
Expand Down