Skip to content

Commit 9554aaa

Browse files
committed
show timestamps in metrics summary charts
1 parent b6e7f99 commit 9554aaa

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

cmd/metrics/resources/base.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,15 @@
263263

264264
const base_line = {
265265
xAxis: {
266+
type: "category",
267+
data: TIMESTAMPS,
266268
name: "time (s)",
267269
min: "dataMin",
268270
max: "dataMax",
271+
boundaryGap: false, // ensure the chart starts at the first data point
272+
axisLabel: {
273+
rotate: 45,
274+
}
269275
},
270276
yAxis: {},
271277
tooltip: {

cmd/metrics/summary.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"regexp"
1616
"strconv"
1717
"strings"
18+
"time"
1819

1920
"perfspect/internal/util"
2021
)
@@ -320,23 +321,30 @@ func (m *metricsFromCSV) getHTML(metadata Metadata) (html string, err error) {
320321
{"PKGPOWER", []string{"package power (watts)", "package power (watts)"}},
321322
{"DRAMPOWER", []string{"DRAM power (watts)", ""}},
322323
}
323-
for _, tmpl := range templateReplace {
324+
for tIdx, tmpl := range templateReplace {
325+
var timeStamps []string
324326
var series [][]float64
325-
var firstTimestamp float64
326327
for rIdx, row := range m.rows {
327-
if rIdx == 0 {
328-
firstTimestamp = row.timestamp
329-
}
330328
if math.IsNaN(row.metrics[tmpl.metricNames[archIndex]]) || math.IsInf(row.metrics[tmpl.metricNames[archIndex]], 0) {
331329
continue
332330
}
333-
series = append(series, []float64{row.timestamp - firstTimestamp, row.metrics[tmpl.metricNames[archIndex]]})
331+
series = append(series, []float64{float64(rIdx), row.metrics[tmpl.metricNames[archIndex]]})
332+
// format the UNIX timestamp as a local tz string
333+
ts := time.Unix(int64(row.timestamp), 0).Format("15:04:05")
334+
timeStamps = append(timeStamps, ts)
334335
}
335336
var seriesBytes []byte
336337
if seriesBytes, err = json.Marshal(series); err != nil {
337338
return
338339
}
339340
html = strings.Replace(html, tmpl.tmplVar, string(seriesBytes), -1)
341+
if tIdx == 0 {
342+
var timeStampsBytes []byte
343+
if timeStampsBytes, err = json.Marshal(timeStamps); err != nil {
344+
return
345+
}
346+
html = strings.Replace(html, "TIMESTAMPS", string(timeStampsBytes), -1)
347+
}
340348
}
341349
// All Metrics Tab
342350
var metricHTMLStats [][]string

0 commit comments

Comments
 (0)