Skip to content

Commit

Permalink
Parse filetotals lines
Browse files Browse the repository at this point in the history
  • Loading branch information
rcowham committed Aug 23, 2024
1 parent 7dce8d2 commit 245263d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
42 changes: 41 additions & 1 deletion p4dlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ type Command struct {
RPCHimarkRev int64 `json:"rpcHimarkRev"`
RPCSnd float32 `json:"rpcSnd"`
RPCRcv float32 `json:"rpcRcv"`
FileTotalsSnd int64 `json:"fileTotalsSnd`
FileTotalsRcv int64 `json:"fileTotalsRcv`
FileTotalsSndMBytes int64 `json:"fileTotalsSndMBytes`
FileTotalsRcvMBytes int64 `json:"fileTotalsRcvMBytes`
NetFilesAdded int64 `json:"netFilesAdded"` // Valid for syncs and network estimates records
NetFilesUpdated int64 `json:"netFilesUpdated"`
NetFilesDeleted int64 `json:"netFilesDeleted"`
Expand Down Expand Up @@ -412,6 +416,13 @@ func (c *Command) setRPC(rpcMsgsIn, rpcMsgsOut, rpcSizeIn, rpcSizeOut, rpcHimark
}
}

func (c *Command) setFileTotals(fileTotalsSnd, fileTotalsSndMBytes, fileTotalsRcv, fileTotalsRcvMBytes string) {
c.FileTotalsSnd, _ = strconv.ParseInt(fileTotalsSnd, 10, 64)
c.FileTotalsSndMBytes, _ = strconv.ParseInt(fileTotalsSndMBytes, 10, 64)
c.FileTotalsRcv, _ = strconv.ParseInt(fileTotalsRcv, 10, 64)
c.FileTotalsRcvMBytes, _ = strconv.ParseInt(fileTotalsRcvMBytes, 10, 64)
}

func (c *Command) setLbrRcsOpensCloses(lbrOpens, lbrCloses, lbrCheckins, lbrExists string) {
if lbrOpens != "" {
c.LbrRcsOpens, _ = strconv.ParseInt(lbrOpens, 10, 64)
Expand Down Expand Up @@ -650,7 +661,11 @@ func (c *Command) MarshalJSON() ([]byte, error) {
RPCHimarkRev int64 `json:"rpcHimarkRev"`
RPCSnd float32 `json:"rpcSnd"`
RPCRcv float32 `json:"rpcRcv"`
NetFilesAdded int64 `json:"netFilesAdded"` // Valid for syncs and network estimates records
FileTotalsSnd int64 `json:"fileTotalsSnd"` // Valid for syncs
FileTotalsRcv int64 `json:"fileTotalsRcv"` // Valid for syncs
FileTotalsSndMBytes int64 `json:"fileTotalsSndMBytes"` // Valid for syncs
FileTotalsRcvMBytes int64 `json:"fileTotalsRcvMBytes"` // Valid for syncs
NetFilesAdded int64 `json:"netFilesAdded"` // Valid for syncs and network estimates records
NetFilesUpdated int64 `json:"netFilesUpdated"`
NetFilesDeleted int64 `json:"netFilesDeleted"`
NetBytesAdded int64 `json:"netBytesAdded"`
Expand Down Expand Up @@ -739,6 +754,10 @@ func (c *Command) MarshalJSON() ([]byte, error) {
RPCHimarkRev: c.RPCHimarkRev,
RPCSnd: c.RPCSnd,
RPCRcv: c.RPCRcv,
FileTotalsSnd: c.FileTotalsSnd,
FileTotalsRcv: c.FileTotalsRcv,
FileTotalsSndMBytes: c.FileTotalsSndMBytes,
FileTotalsRcvMBytes: c.FileTotalsRcvMBytes,
NetFilesAdded: c.NetFilesAdded,
NetFilesUpdated: c.NetFilesUpdated,
NetFilesDeleted: c.NetFilesDeleted,
Expand Down Expand Up @@ -899,6 +918,18 @@ func (c *Command) updateFrom(other *Command) {
if other.RPCRcv > 0 {
c.RPCRcv = other.RPCRcv
}
if other.FileTotalsSnd > 0 {
c.FileTotalsSnd = other.FileTotalsSnd
}
if other.FileTotalsRcv > 0 {
c.FileTotalsRcv = other.FileTotalsRcv
}
if other.FileTotalsSndMBytes > 0 {
c.FileTotalsSndMBytes = other.FileTotalsSndMBytes
}
if other.FileTotalsRcvMBytes > 0 {
c.FileTotalsRcvMBytes = other.FileTotalsRcvMBytes
}
if other.NetFilesAdded > 0 {
c.NetFilesAdded = other.NetFilesAdded
}
Expand Down Expand Up @@ -1302,6 +1333,7 @@ var reCmdTrigger = regexp.MustCompile(` trigger ([^ ]+)$`)
var reTriggerLapse = regexp.MustCompile(`^lapse (\d+\.\d+)s|^lapse (\.\d+)s|^lapse (\d+)s`)
var prefixTrackCmdMem = "--- memory cmd/proc "
var prefixTrackRPC = "--- rpc msgs/size in+out "
var prefixTrackFileTotals = "--- filetotals (svr) send/recv files+bytes "
var prefixTrackLbr = "--- opens+closes"
var prefixTrackLbr2 = "--- reads+readbytes"
var prefixTrackLbr3 = "--- digests+filesizes"
Expand All @@ -1311,6 +1343,7 @@ var reTrackLbrDigestFilesize = regexp.MustCompile(`^--- digests\+filesizes\+mo
var reTrackCmdMem = regexp.MustCompile(`^--- memory cmd/proc (\d+)mb\/(\d+)mb`)
var reTrackRPC = regexp.MustCompile(`^--- rpc msgs/size in\+out (\d+)\+(\d+)/(\d+)mb\+(\d+)mb himarks (\d+)/(\d+)`)
var reTrackRPC2 = regexp.MustCompile(`^--- rpc msgs/size in\+out (\d+)\+(\d+)/(\d+)mb\+(\d+)mb himarks (\d+)/(\d+) snd/rcv ([0-9]+|[0-9]+\.[0-9]+|\.[0-9]+)s/([0-9]+|[0-9]+\.[0-9]+|\.[0-9]+)s`)
var reTrackFileTotals = regexp.MustCompile(`^--- filetotals \(svr\) send/recv files\+bytes (\d+)\+(\d+)mb/(\d+)\+(\d+)mb`)
var prefixTrackUsage = "--- usage"
var reTrackUsage = regexp.MustCompile(`^--- usage (\d+)\+(\d+)us (\d+)\+(\d+)io (\d+)\+(\d+)net (\d+)k (\d+)pf`)
var reCmdUsage = regexp.MustCompile(` (\d+)\+(\d+)us (\d+)\+(\d+)io (\d+)\+(\d+)net (\d+)k (\d+)pf`)
Expand Down Expand Up @@ -1450,6 +1483,13 @@ func (fp *P4dFileParser) processTrackRecords(cmd *Command, lines []string) {
continue
}
}
if strings.HasPrefix(line, prefixTrackFileTotals) {
m = reTrackFileTotals.FindStringSubmatch(line)
if len(m) > 0 {
cmd.setFileTotals(m[1], m[2], m[3], m[4])
continue
}
}
if strings.HasPrefix(line, trackLbrRcs) {
lbrAction = "lbrRcs"
hasTrackInfo = true
Expand Down
17 changes: 17 additions & 0 deletions p4dlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,3 +1370,20 @@ Perforce server info:
assert.JSONEq(t, cleanJSON(`{"app":"p4/2024.1.TEST-TEST_ONLY/LINUX26X86_64/2611120", "args":"-Ob //...", "cmd":"user-fstat", "cmdError":true, "completedLapse":8.39, "diskIn":304, "endTime":"2024/06/19 12:25:39", "ip":"127.0.0.1", "lineNo":2, "maxRss":68864, "memMB":74, "memPeakMB":74, "pid":1.056864e+06, "processKey":"861c79f6f864bc6cfd2aa3d0ba35952e", "rpcHimarkFwd":795416, "rpcHimarkRev":795272, "rpcMsgsIn":2, "rpcMsgsOut":84225, "rpcRcv":0.002, "rpcSizeOut":45, "rpcSnd":5.64, "running":1, "sCpu":67, "startTime":"2024/06/19 12:25:31", "tables":[], "uCpu":598, "user":"perforce", "workspace":"ip-10-0-0-106"}`),
cleanJSON(output[0]))
}

func TestFileTotals(t *testing.T) {
// Note just for testing we set both snd/rcv values - normally you get either one or the other
testInput := `Perforce server info:
2024/07/11 11:16:51 pid 3433924 bruno@bruno_ws 127.0.0.1 [p4/2023.2/LINUX26X86_64/2605454] 'user-sync -f //depot/data/...'
--- lapse 70.9s
--- usage 16270+5907us 136024+176io 0+0net 15216k 0pf
--- memory cmd/proc 5mb/5mb
--- rpc msgs/size in+out 32+29907/0mb+1863mb himarks 97604/97604 snd/rcv 58.5s/.326s
--- filetotals (svr) send/recv files+bytes 25+1862mb/1+2mb
`
output := parseLogLines(testInput)
assert.Equal(t, 1, len(output))
// assert.Equal(t, "", output[0])
assert.JSONEq(t, cleanJSON(`{"app":"p4/2023.2/LINUX26X86_64/2605454", "args":"-f //depot/data/...", "cmd":"user-sync", "cmdError":false, "completedLapse":70.9, "diskIn":136024, "diskOut":176, "endTime":"2024/07/11 11:18:01", "fileTotalsRcv":1, "fileTotalsRcvMBytes":2, "fileTotalsSnd":25, "fileTotalsSndMBytes":1862, "ip":"127.0.0.1", "lineNo":1, "maxRss":15216, "memMB":5, "memPeakMB":5, "pid":3.433924e+06, "processKey":"06b672ec262cbfde8633bc759d498340", "rpcHimarkFwd":97604, "rpcHimarkRev":97604, "rpcMsgsIn":32, "rpcMsgsOut":29907, "rpcRcv":0.326, "rpcSizeOut":1863, "rpcSnd":58.5, "running":1, "sCpu":5907, "startTime":"2024/07/11 11:16:51", "tables":[], "uCpu":16270, "user":"bruno", "workspace":"bruno_ws"}`),
cleanJSON(output[0]))
}

0 comments on commit 245263d

Please sign in to comment.