Skip to content

Commit 5ca30df

Browse files
authored
enable post-processing of pre-collected metric events (#192)
1 parent 2fa5446 commit 5ca30df

File tree

5 files changed

+357
-124
lines changed

5 files changed

+357
-124
lines changed

cmd/metrics/metadata.go

Lines changed: 28 additions & 5 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/cpudb"
2021
"perfspect/internal/script"
@@ -30,10 +31,12 @@ type Metadata struct {
3031
Architecture string
3132
Vendor string
3233
Microarchitecture string
34+
Hostname string
3335
ModelName string
3436
PerfSupportedEvents string
3537
PMUDriverVersion string
3638
SocketCount int
39+
CollectionStartTime time.Time
3740
SupportsInstructions bool
3841
SupportsFixedCycles bool
3942
SupportsFixedInstructions bool
@@ -80,6 +83,8 @@ func LoadMetadata(myTarget target.Target, noRoot bool, perfPath string, localTem
8083
metadata.CPUSocketMap = createCPUSocketMap(metadata.CoresPerSocket, metadata.SocketCount, metadata.ThreadsPerCore == 2)
8184
// Model Name
8285
metadata.ModelName = cpuInfo[0]["model name"]
86+
// Hostname
87+
metadata.Hostname = myTarget.GetName()
8388
// Architecture
8489
metadata.Architecture, err = myTarget.GetArchitecture()
8590
if err != nil {
@@ -256,6 +261,7 @@ func LoadMetadata(myTarget target.Target, noRoot bool, perfPath string, localTem
256261
// String - provides a string representation of the Metadata structure
257262
func (md Metadata) String() string {
258263
out := fmt.Sprintf(""+
264+
"Host Name: %s, "+
259265
"Model Name: %s, "+
260266
"Architecture: %s, "+
261267
"Vendor: %s, "+
@@ -274,7 +280,9 @@ func (md Metadata) String() string {
274280
"PEBS supported: %t, "+
275281
"OCR supported: %t, "+
276282
"PMU Driver version: %s, "+
277-
"Kernel version: %s, ",
283+
"Kernel version: %s, "+
284+
"Collection Start Time: %s, ",
285+
md.Hostname,
278286
md.ModelName,
279287
md.Architecture,
280288
md.Vendor,
@@ -293,7 +301,9 @@ func (md Metadata) String() string {
293301
md.SupportsPEBS,
294302
md.SupportsOCR,
295303
md.PMUDriverVersion,
296-
md.KernelVersion)
304+
md.KernelVersion,
305+
md.CollectionStartTime.Format(time.RFC3339),
306+
)
297307
for deviceName, deviceIds := range md.UncoreDeviceIDs {
298308
var ids []string
299309
for _, id := range deviceIds {
@@ -316,9 +326,6 @@ func (md Metadata) JSON() (out []byte, err error) {
316326
slog.Error("failed to marshal metadata structure", slog.String("error", err.Error()))
317327
return
318328
}
319-
// remove PerfSupportedEvents from json
320-
re := regexp.MustCompile(`"PerfSupportedEvents":".*?",`)
321-
out = re.ReplaceAll(out, []byte(""))
322329
return
323330
}
324331

@@ -343,6 +350,22 @@ func (md Metadata) WriteJSONToFile(path string) (err error) {
343350
return
344351
}
345352

353+
// ReadJSONFromFile reads the metadata structure from the filename provided
354+
func ReadJSONFromFile(path string) (md Metadata, err error) {
355+
// read the file
356+
var rawBytes []byte
357+
rawBytes, err = os.ReadFile(path)
358+
if err != nil {
359+
slog.Error("failed to read metadata file", slog.String("error", err.Error()))
360+
return
361+
}
362+
if err = json.Unmarshal(rawBytes, &md); err != nil {
363+
slog.Error("failed to unmarshal metadata json", slog.String("error", err.Error()))
364+
return
365+
}
366+
return
367+
}
368+
346369
// getUncoreDeviceIDs - returns a map of device type to list of device indices
347370
// e.g., "upi" -> [0,1,2,3],
348371
func getUncoreDeviceIDs(myTarget target.Target, localTempDir string) (IDs map[string][]int, err error) {

cmd/metrics/metric.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ type Metric struct {
2525

2626
// MetricFrame represents the metrics values and associated metadata
2727
type MetricFrame struct {
28-
Metrics []Metric
29-
Timestamp float64
30-
FrameCount int
31-
Socket string
32-
CPU string
33-
Cgroup string
34-
PID string
35-
Cmd string
28+
Metrics []Metric
29+
Timestamp float64
30+
Socket string
31+
CPU string
32+
Cgroup string
33+
PID string
34+
Cmd string
3635
}
3736

3837
// ProcessEvents is responsible for producing metrics from raw perf events

0 commit comments

Comments
 (0)