Skip to content

Commit

Permalink
Merge pull request #55366 from knz/backport20.2-55364
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Oct 16, 2020
2 parents 227422b + 11d3e2b commit 973a6f3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/cpuprofile.go
Expand Up @@ -34,7 +34,7 @@ var maxCombinedCPUProfFileSize = settings.RegisterByteSizeSetting(
128<<20, // 128MiB
)

const cpuProfTimeFormat = "2006-01-02T15_04_05.999"
const cpuProfTimeFormat = "2006-01-02T15_04_05.000"
const cpuProfFileNamePrefix = "cpuprof."

type cpuProfiler struct{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/goroutinedumper/goroutinedumper.go
Expand Up @@ -29,7 +29,7 @@ import (

const (
goroutineDumpPrefix = "goroutine_dump"
timeFormat = "2006-01-02T15_04_05.999"
timeFormat = "2006-01-02T15_04_05.000"
)

var (
Expand Down
20 changes: 10 additions & 10 deletions pkg/server/goroutinedumper/goroutinedumper_test.go
Expand Up @@ -61,9 +61,9 @@ func TestHeuristic(t *testing.T) {
{220, 100, 500}, // trigger since N has doubled since last dump
},
expectedDumps: []string{
"goroutine_dump.2019-01-01T00_00_20.double_since_last_dump.000000120",
"goroutine_dump.2019-01-01T00_01_20.double_since_last_dump.000000250",
"goroutine_dump.2019-01-01T00_03_40.double_since_last_dump.000000500",
"goroutine_dump.2019-01-01T00_00_20.000.double_since_last_dump.000000120",
"goroutine_dump.2019-01-01T00_01_20.000.double_since_last_dump.000000250",
"goroutine_dump.2019-01-01T00_03_40.000.double_since_last_dump.000000500",
},
},
{
Expand All @@ -84,12 +84,12 @@ func TestHeuristic(t *testing.T) {
{220, 100, 500}, // not trigger since N has not doubled since last dump
},
expectedDumps: []string{
"goroutine_dump.2019-01-01T00_00_20.double_since_last_dump.000000110",
"goroutine_dump.2019-01-01T00_01_40.double_since_last_dump.000000220",
"goroutine_dump.2019-01-01T00_03_20.double_since_last_dump.000000450",
"goroutine_dump.2019-01-01T00_00_20.000.double_since_last_dump.000000110",
"goroutine_dump.2019-01-01T00_01_40.000.double_since_last_dump.000000220",
"goroutine_dump.2019-01-01T00_03_20.000.double_since_last_dump.000000450",
},
dumpsToFail: []string{
"goroutine_dump.2019-01-01T00_01_20.double_since_last_dump.000000230",
"goroutine_dump.2019-01-01T00_01_20.000.double_since_last_dump.000000230",
},
},
{
Expand All @@ -109,9 +109,9 @@ func TestHeuristic(t *testing.T) {
{220, 200, 500}, // trigger since N has doubled since last dump
},
expectedDumps: []string{
"goroutine_dump.2019-01-01T00_00_20.double_since_last_dump.000000120",
"goroutine_dump.2019-01-01T00_01_30.double_since_last_dump.000000210",
"goroutine_dump.2019-01-01T00_03_40.double_since_last_dump.000000500",
"goroutine_dump.2019-01-01T00_00_20.000.double_since_last_dump.000000120",
"goroutine_dump.2019-01-01T00_01_30.000.double_since_last_dump.000000210",
"goroutine_dump.2019-01-01T00_03_40.000.double_since_last_dump.000000500",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/heapprofiler/profiler_common.go
Expand Up @@ -34,7 +34,7 @@ var resetHighWaterMarkInterval = func() time.Duration {
// timestampFormat is chosen to mimix that used by the log
// package. This is not a hard requirement thought; the profiles are
// stored in a separate directory.
const timestampFormat = "2006-01-02T15_04_05.999"
const timestampFormat = "2006-01-02T15_04_05.000"

type testingKnobs struct {
dontWriteProfiles bool
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/heapprofiler/profilestore.go
Expand Up @@ -156,6 +156,15 @@ func (s *profileStore) parseFileName(
// Not for us. Silently ignore.
return
}
if len(parts[2]) < 3 {
// At some point in the v20.2 cycle the timestamps were generated
// with format .999, which caused the trailing zeroes to be
// omitted. During parsing, they must be present, so re-add them
// here.
//
// TODO(knz): Remove this code in v21.1.
parts[2] += "000"[:3-len(parts[2])]
}
maybeTimestamp := parts[1] + "." + parts[2]
var err error
timestamp, err = time.Parse(timestampFormat, maybeTimestamp)
Expand Down
16 changes: 14 additions & 2 deletions pkg/server/heapprofiler/profilestore_test.go
Expand Up @@ -24,13 +24,21 @@ import (
)

func TestMakeFileName(t *testing.T) {
ts := time.Date(2020, 6, 15, 13, 19, 19, 543000000, time.UTC)

store := dumpstore.NewStore("mydir", nil, nil)
joy := newProfileStore(store, HeapFileNamePrefix, ".test", nil)

ts := time.Date(2020, 6, 15, 13, 19, 19, 543000000, time.UTC)
assert.Equal(t,
filepath.Join("mydir", "memprof.2020-06-15T13_19_19.543.123456.test"),
joy.makeNewFileName(ts, 123456))

// Also check when the millisecond part is zero. This verifies that
// the .999 format is not used, which would cause the millisecond
// part to be (erronously) omitted.
ts = time.Date(2020, 6, 15, 13, 19, 19, 00000000, time.UTC)
assert.Equal(t,
filepath.Join("mydir", "memprof.2020-06-15T13_19_19.000.123456.test"),
joy.makeNewFileName(ts, 123456))
}

func TestParseFileName(t *testing.T) {
Expand All @@ -50,6 +58,10 @@ func TestParseFileName(t *testing.T) {

// New format.
{"memprof.2020-06-15T13_19_19.543.123456", time.Date(2020, 6, 15, 13, 19, 19, 543000000, time.UTC), 123456, false},
// v20.2 transition formats.
// TODO(knz): Remove in v21.1.
{"memprof.2020-06-15T13_19_19.54.123456", time.Date(2020, 6, 15, 13, 19, 19, 540000000, time.UTC), 123456, false},
{"memprof.2020-06-15T13_19_19.5.123456", time.Date(2020, 6, 15, 13, 19, 19, 500000000, time.UTC), 123456, false},
}

s := profileStore{prefix: HeapFileNamePrefix}
Expand Down

0 comments on commit 973a6f3

Please sign in to comment.