Skip to content

Commit

Permalink
Merge pull request #1702 from maryamtahhan/cleanup-node-globals
Browse files Browse the repository at this point in the history
Cleanup stats pkg globals
  • Loading branch information
maryamtahhan authored Sep 10, 2024
2 parents daa0a63 + 349f00c commit 49f1f6f
Show file tree
Hide file tree
Showing 23 changed files with 532 additions and 530 deletions.
3 changes: 0 additions & 3 deletions cmd/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/sustainable-computing-io/kepler/pkg/bpf"
"github.com/sustainable-computing-io/kepler/pkg/build"
"github.com/sustainable-computing-io/kepler/pkg/collector/stats"
"github.com/sustainable-computing-io/kepler/pkg/config"
"github.com/sustainable-computing-io/kepler/pkg/manager"
"github.com/sustainable-computing-io/kepler/pkg/metrics"
Expand Down Expand Up @@ -147,8 +146,6 @@ func main() {
platform.InitPowerImpl()
defer platform.StopPower()

stats.InitAvailableParamAndMetrics()

if config.EnabledGPU() {
r := accelerator.GetRegistry()
if a, err := accelerator.New(accelerator.GPU, true); err == nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/collector/metric_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func (c *Collector) Initialize() error {
// model component decide whether/how to init
model.CreatePowerEstimatorModels(
stats.GetProcessFeatureNames(c.bpfSupportedMetrics),
stats.NodeMetadataFeatureNames(),
stats.NodeMetadataFeatureValues(),
c.bpfSupportedMetrics,
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/metric_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Test Collector Unit", func() {
metricCollector := newMockCollector(bpfExporter)
// The default estimator model is the ratio
bpfSupportedMetrics := bpfExporter.SupportedMetrics()
model.CreatePowerEstimatorModels(stats.GetProcessFeatureNames(bpfSupportedMetrics), stats.NodeMetadataFeatureNames(), stats.NodeMetadataFeatureValues(), bpfSupportedMetrics)
model.CreatePowerEstimatorModels(stats.GetProcessFeatureNames(bpfSupportedMetrics), bpfSupportedMetrics)
// update container and node metrics
metricCollector.UpdateProcessEnergyUtilizationMetrics()
metricCollector.AggregateProcessEnergyUtilizationMetrics()
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/stats/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func benchmarkNtesting(b *testing.B, processNumber int) {

// The default estimator model is the ratio
bpfSupportedMetrics := bpf.DefaultSupportedMetrics()
model.CreatePowerEstimatorModels(stats.GetProcessFeatureNames(bpfSupportedMetrics), stats.NodeMetadataFeatureNames(), stats.NodeMetadataFeatureValues(), bpfSupportedMetrics)
model.CreatePowerEstimatorModels(stats.GetProcessFeatureNames(bpfSupportedMetrics), bpfSupportedMetrics)

// update container and node metrics
b.ReportAllocs()
Expand Down
41 changes: 21 additions & 20 deletions pkg/collector/stats/node_stats.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021.
Copyright 2021-2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@ import (

"github.com/sustainable-computing-io/kepler/pkg/bpf"
"github.com/sustainable-computing-io/kepler/pkg/config"
"github.com/sustainable-computing-io/kepler/pkg/node"
acc "github.com/sustainable-computing-io/kepler/pkg/sensors/accelerator"
"github.com/sustainable-computing-io/kepler/pkg/utils"
)
Expand All @@ -30,32 +31,16 @@ type NodeStats struct {

// IdleResUtilization is used to determine idle pmap[string]eriods
IdleResUtilization map[string]uint64
}

// NodeCPUArchitecture returns the CPU architecture
func NodeCPUArchitecture() string {
return getCPUArch()
}

// NodeCPUPackageMap returns the CPU package map
func NodeCPUPackageMap() map[int32]string {
return getCPUPackageMap()
}

// NodeMetadataFeatureNames returns the feature names for metadata
func NodeMetadataFeatureNames() []string {
return []string{"cpu_architecture"}
}

// NodeMetadataFeatureValues returns the feature values for metadata
func NodeMetadataFeatureValues() []string {
return []string{NodeCPUArchitecture()}
// nodeInfo allows access to node information
nodeInfo node.Node
}

func NewNodeStats(bpfSupportedMetrics bpf.SupportedMetrics) *NodeStats {
return &NodeStats{
Stats: *NewStats(bpfSupportedMetrics),
IdleResUtilization: map[string]uint64{},
nodeInfo: node.NewNodeInfo(),
}
}

Expand Down Expand Up @@ -151,3 +136,19 @@ func (ne *NodeStats) String() string {
"%v\n", ne.Stats.String(),
)
}

func (ne *NodeStats) MetadataFeatureNames() []string {
return ne.nodeInfo.MetadataFeatureNames()
}

func (ne *NodeStats) MetadataFeatureValues() []string {
return ne.nodeInfo.MetadataFeatureValues()
}

func (ne *NodeStats) CPUArchitecture() string {
return ne.nodeInfo.CPUArchitecture()
}

func (ne *NodeStats) NodeName() string {
return ne.nodeInfo.Name()
}
Loading

0 comments on commit 49f1f6f

Please sign in to comment.