Skip to content

Commit

Permalink
[fix]: try to reduce escapes to heap (#1886)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Yuan <[email protected]>
  • Loading branch information
SamYuan1990 authored Dec 10, 2024
1 parent 33c5c73 commit c9524a8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/collector/stats/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type UInt64Stat struct {
}

func NewUInt64Stat(aggr, delta uint64) *UInt64Stat {
stat := &UInt64Stat{}
stat := UInt64Stat{}
stat.aggr.Store(aggr)
stat.delta.Store(delta)
return stat
return &stat
}

func (s *UInt64Stat) String() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func getBoolConfig(configKey string, defaultBool bool) bool {
}

func getIntConfig(configKey string, defaultInt int) int {
defaultValue := fmt.Sprintf("%d", defaultInt)
defaultValue := strconv.Itoa(defaultInt)
value, err := strconv.Atoi(getConfig(configKey, defaultValue))
if err == nil {
return value
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubelet/kubelet_pod_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (

var (
podURL string
client http.Client
)

func init() {
Expand All @@ -50,6 +51,8 @@ func init() {
port = "10250"
}
podURL = "https://" + nodeName + ":" + port + "/pods"
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client = http.Client{}
}

func httpGet(url string) (*http.Response, error) {
Expand All @@ -65,8 +68,6 @@ func httpGet(url string) (*http.Response, error) {
return nil, err
}
req.Header.Add("Authorization", bearer)
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to get response from %q: %v", url, err)
Expand Down
10 changes: 4 additions & 6 deletions pkg/model/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ var (
LogisticTrainer,
ExponentialTrainer,
}
ModelOutputTypeConverter = []string{"AbsPower", "DynPower"}
ModelTypeConverter = []string{"Ratio", "Regressor", "EstimatorSidecar"}
)

func getModelOutputTypeConverter() []string {
return []string{
"AbsPower", "DynPower",
}
return ModelOutputTypeConverter
}

func getModelTypeConverter() []string {
return []string{
"Ratio", "Regressor", "EstimatorSidecar",
}
return ModelTypeConverter
}

func (s ModelOutputType) String() string {
Expand Down
1 change: 0 additions & 1 deletion pkg/sensors/components/source/rapl_msr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func ReadMSR(packageID int, msr int64) (uint64, error) {
}

msrVal := byteOrder.Uint64(buf)

return msrVal, nil
}

Expand Down
16 changes: 12 additions & 4 deletions pkg/sensors/components/source/rapl_sysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"strconv"
"strings"
"sync"

"k8s.io/klog/v2"
)
Expand All @@ -43,7 +44,9 @@ const (
)

var (
eventPaths map[string]map[string]string
eventPaths map[string]map[string]string
once sync.Once
systemCollectionSupported bool
)

func init() {
Expand Down Expand Up @@ -125,9 +128,14 @@ func (PowerSysfs) GetName() string {
}

func (r *PowerSysfs) IsSystemCollectionSupported() bool {
path := fmt.Sprintf(packageNamePathTemplate, 0)
_, err := os.ReadFile(path + energyFile)
return err == nil
// use a hard code to reduce escapes to heap
// there are parts of code invokes this function
// use once to reduce IO
once.Do(func() {
_, err := os.ReadFile("/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj")
systemCollectionSupported = (err == nil)
})
return systemCollectionSupported
}

func (r *PowerSysfs) GetAbsEnergyFromDram() (uint64, error) {
Expand Down

0 comments on commit c9524a8

Please sign in to comment.