Skip to content

Commit

Permalink
enable post-processing of pre-collected metric events (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
harp-intel authored Feb 10, 2025
1 parent 2fa5446 commit 5ca30df
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 124 deletions.
33 changes: 28 additions & 5 deletions cmd/metrics/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

"perfspect/internal/cpudb"
"perfspect/internal/script"
Expand All @@ -30,10 +31,12 @@ type Metadata struct {
Architecture string
Vendor string
Microarchitecture string
Hostname string
ModelName string
PerfSupportedEvents string
PMUDriverVersion string
SocketCount int
CollectionStartTime time.Time
SupportsInstructions bool
SupportsFixedCycles bool
SupportsFixedInstructions bool
Expand Down Expand Up @@ -80,6 +83,8 @@ func LoadMetadata(myTarget target.Target, noRoot bool, perfPath string, localTem
metadata.CPUSocketMap = createCPUSocketMap(metadata.CoresPerSocket, metadata.SocketCount, metadata.ThreadsPerCore == 2)
// Model Name
metadata.ModelName = cpuInfo[0]["model name"]
// Hostname
metadata.Hostname = myTarget.GetName()
// Architecture
metadata.Architecture, err = myTarget.GetArchitecture()
if err != nil {
Expand Down Expand Up @@ -256,6 +261,7 @@ func LoadMetadata(myTarget target.Target, noRoot bool, perfPath string, localTem
// String - provides a string representation of the Metadata structure
func (md Metadata) String() string {
out := fmt.Sprintf(""+
"Host Name: %s, "+
"Model Name: %s, "+
"Architecture: %s, "+
"Vendor: %s, "+
Expand All @@ -274,7 +280,9 @@ func (md Metadata) String() string {
"PEBS supported: %t, "+
"OCR supported: %t, "+
"PMU Driver version: %s, "+
"Kernel version: %s, ",
"Kernel version: %s, "+
"Collection Start Time: %s, ",
md.Hostname,
md.ModelName,
md.Architecture,
md.Vendor,
Expand All @@ -293,7 +301,9 @@ func (md Metadata) String() string {
md.SupportsPEBS,
md.SupportsOCR,
md.PMUDriverVersion,
md.KernelVersion)
md.KernelVersion,
md.CollectionStartTime.Format(time.RFC3339),
)
for deviceName, deviceIds := range md.UncoreDeviceIDs {
var ids []string
for _, id := range deviceIds {
Expand All @@ -316,9 +326,6 @@ func (md Metadata) JSON() (out []byte, err error) {
slog.Error("failed to marshal metadata structure", slog.String("error", err.Error()))
return
}
// remove PerfSupportedEvents from json
re := regexp.MustCompile(`"PerfSupportedEvents":".*?",`)
out = re.ReplaceAll(out, []byte(""))
return
}

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

// ReadJSONFromFile reads the metadata structure from the filename provided
func ReadJSONFromFile(path string) (md Metadata, err error) {
// read the file
var rawBytes []byte
rawBytes, err = os.ReadFile(path)
if err != nil {
slog.Error("failed to read metadata file", slog.String("error", err.Error()))
return
}
if err = json.Unmarshal(rawBytes, &md); err != nil {
slog.Error("failed to unmarshal metadata json", slog.String("error", err.Error()))
return
}
return
}

// getUncoreDeviceIDs - returns a map of device type to list of device indices
// e.g., "upi" -> [0,1,2,3],
func getUncoreDeviceIDs(myTarget target.Target, localTempDir string) (IDs map[string][]int, err error) {
Expand Down
15 changes: 7 additions & 8 deletions cmd/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ type Metric struct {

// MetricFrame represents the metrics values and associated metadata
type MetricFrame struct {
Metrics []Metric
Timestamp float64
FrameCount int
Socket string
CPU string
Cgroup string
PID string
Cmd string
Metrics []Metric
Timestamp float64
Socket string
CPU string
Cgroup string
PID string
Cmd string
}

// ProcessEvents is responsible for producing metrics from raw perf events
Expand Down
Loading

0 comments on commit 5ca30df

Please sign in to comment.