summaryrefslogtreecommitdiff
path: root/internal/file
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-14 23:41:54 +0200
committerPaul Buetow <paul@buetow.org>2025-03-14 23:41:54 +0200
commit5cac6a84181a6121e27c5c763a3e34254180fa4b (patch)
tree83bf76348990052452d38d3feacc20f757b27695 /internal/file
parent3edde70ef17d23a3f2fcb0fac11a50e8810ab943 (diff)
parallel rite collapsed flamegraphs
Diffstat (limited to 'internal/file')
-rw-r--r--internal/file/file.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/internal/file/file.go b/internal/file/file.go
index 4d9afab..a9de8d3 100644
--- a/internal/file/file.go
+++ b/internal/file/file.go
@@ -1,6 +1,7 @@
package file
import (
+ "bytes"
"fmt"
"os"
"strconv"
@@ -17,8 +18,8 @@ type FdFile struct {
name string
}
-func NewFd(fd int32, name string) FdFile {
- return FdFile{fd, name}
+func NewFd(fd int32, name []byte) FdFile {
+ return FdFile{fd, stringValue(name)}
}
func NewFdWithPid(fd int32, pid uint32) FdFile {
@@ -51,6 +52,10 @@ type OldnameNewnameFile struct {
Oldname, Newname string
}
+func NewOldnameNewname(oldname, newname []byte) OldnameNewnameFile {
+ return OldnameNewnameFile{stringValue(oldname), stringValue(newname)}
+}
+
func (f OldnameNewnameFile) Name() string {
return f.Newname
}
@@ -70,6 +75,10 @@ type PathnameFile struct {
Pathname string
}
+func NewPathname(pathname []byte) PathnameFile {
+ return PathnameFile{stringValue(pathname)}
+}
+
func (f PathnameFile) Name() string {
return f.Pathname
}
@@ -82,3 +91,8 @@ func (f PathnameFile) String() string {
return sb.String()
}
+
+func stringValue(byteStr []byte) string {
+ // TODO: Hopefully, this won't cause a panic when the filename is as long as the array itself
+ return string(byteStr[:bytes.IndexByte(byteStr, 0)])
+}