diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-08-22 12:38:06 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-08-22 14:08:54 +0000 |
| commit | 5e416b9760dc506494f60935ba8badf492728bff (patch) | |
| tree | 46e111c9d774b66e77828dbf986622cabfa503e1 /prog | |
| parent | 6e3696e1821a99ba709c464e5e4a2fc455730b2b (diff) | |
prog: extract program IDs from the logs
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/parse.go | 9 | ||||
| -rw-r--r-- | prog/parse_test.go | 12 |
2 files changed, 20 insertions, 1 deletions
diff --git a/prog/parse.go b/prog/parse.go index c9c1564dc..bad2dcecc 100644 --- a/prog/parse.go +++ b/prog/parse.go @@ -12,13 +12,16 @@ import ( type LogEntry struct { P *Prog Proc int // index of parallel proc + ID int // ID of the executed program (-1 if not present) Start int // start offset in log End int // end offset in log } func (target *Target) ParseLog(data []byte) []*LogEntry { var entries []*LogEntry - ent := &LogEntry{} + ent := &LogEntry{ + ID: -1, + } var cur []byte faultCall, faultNth := -1, -1 for pos := 0; pos < len(data); { @@ -41,6 +44,10 @@ func (target *Target) ParseLog(data []byte) []*LogEntry { ent = &LogEntry{ Proc: proc, Start: pos0, + ID: -1, + } + if id, ok := extractInt(line, "id="); ok { + ent.ID = id } // We no longer print it this way, but we still parse such fragments to preserve // the backward compatibility. diff --git a/prog/parse_test.go b/prog/parse_test.go index 1dcaa95d8..37bc7771e 100644 --- a/prog/parse_test.go +++ b/prog/parse_test.go @@ -5,6 +5,8 @@ package prog import ( "testing" + + "github.com/stretchr/testify/assert" ) func TestParseSingle(t *testing.T) { @@ -48,6 +50,13 @@ func TestParseMulti(t *testing.T) { } entries := target.ParseLog([]byte(execLogNew)) validateProgs(t, entries, len(execLogNew)) + if entries[0].ID != -1 || + entries[1].ID != 70 || + entries[2].ID != 75 || + entries[3].ID != 80 || + entries[4].ID != 85 { + t.Fatalf("bad IDs") + } } func TestParseMultiLegacy(t *testing.T) { @@ -58,6 +67,9 @@ func TestParseMultiLegacy(t *testing.T) { } entries := target.ParseLog([]byte(execLogOld)) validateProgs(t, entries, len(execLogOld)) + for _, ent := range entries { + assert.Equal(t, -1, ent.ID) + } } func validateProgs(t *testing.T, entries []*LogEntry, logLen int) { |
