diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-04-07 15:48:15 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-04-24 09:11:37 +0000 |
| commit | 75b844f0d228bda5dea2aabae096909f81355bac (patch) | |
| tree | f3751910ecac44a0ff89309efc03a8c520ce269e /src/internal/trace/parser.go | |
| parent | 687fe991e42f15fe1f491680c615ef96568f780a (diff) | |
| download | go-75b844f0d228bda5dea2aabae096909f81355bac.tar.xz | |
runtime/trace: test detection of broken timestamps
On some processors cputicks (used to generate trace timestamps)
produce non-monotonic timestamps. It is important that the parser
distinguishes logically inconsistent traces (e.g. missing, excessive
or misordered events) from broken timestamps. The former is a bug
in tracer, the latter is a machine issue.
Test that (1) parser does not return a logical error in case of
broken timestamps and (2) broken timestamps are eventually detected
and reported.
Change-Id: Ib4b1eb43ce128b268e754400ed8b5e8def04bd78
Reviewed-on: https://go-review.googlesource.com/21608
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/internal/trace/parser.go')
| -rw-r--r-- | src/internal/trace/parser.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/internal/trace/parser.go b/src/internal/trace/parser.go index e6f29445c1..843d0eaf63 100644 --- a/src/internal/trace/parser.go +++ b/src/internal/trace/parser.go @@ -9,10 +9,12 @@ import ( "bytes" "fmt" "io" + "math/rand" "os" "os/exec" "strconv" "strings" + _ "unsafe" ) // Event describes one event in the trace. @@ -371,6 +373,16 @@ func parseEvents(ver int, rawEvents []rawEvent, strings map[uint64]string) (even err = fmt.Errorf("no EvFrequency event") return } + if BreakTimestampsForTesting { + var batchArr [][]*Event + for _, batch := range batches { + batchArr = append(batchArr, batch) + } + for i := 0; i < 5; i++ { + batch := batchArr[rand.Intn(len(batchArr))] + batch[rand.Intn(len(batch))].Ts += int64(rand.Intn(2000) - 1000) + } + } if ver < 1007 { events, err = order1005(batches) } else { @@ -813,6 +825,9 @@ func argNum(raw rawEvent, ver int) int { return narg } +// BreakTimestampsForTesting causes the parser to randomly alter timestamps (for testing of broken cputicks). +var BreakTimestampsForTesting bool + // Event types in the trace. // Verbatim copy from src/runtime/trace.go. const ( |
