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>
This commit is contained in:
Dmitry Vyukov 2016-04-07 15:48:15 +02:00
parent 687fe991e4
commit 75b844f0d2
3 changed files with 50 additions and 18 deletions

View file

@ -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 (