Documentation ¶
Index ¶
- func CheckIfCPUBaseFrequencySupported(cpuModel int) error
- func CheckIfCPUC1StateResidencySupported(cpuModel int) error
- func CheckIfCPUC3StateResidencySupported(cpuModel int) error
- func CheckIfCPUC6StateResidencySupported(cpuModel int) error
- func CheckIfCPUC7StateResidencySupported(cpuModel int) error
- func CheckIfCPUTemperatureSupported(cpuModel int) error
- type MaxTurboFreq
- type MetricNotSupportedError
- type ModuleNotInitializedError
- type MultiError
- type Option
- func WithCoreFrequency(basePath ...string) Option
- func WithExcludedCPUs(cpuIDs []int) Option
- func WithIncludedCPUs(cpuIDs []int) Option
- func WithLogger(l log.Logger) Option
- func WithMsr() Option
- func WithMsrTimeout(timeout time.Duration) Option
- func WithPerf(jsonFile string) Option
- func WithRapl(basePath ...string) Option
- func WithUncoreFrequency(basePath ...string) Option
- type PowerTelemetry
- func (pt *PowerTelemetry) DeactivatePerfEvents() error
- func (pt *PowerTelemetry) GetCPUBaseFrequency(packageID int) (uint64, error)
- func (pt *PowerTelemetry) GetCPUBusyFrequencyMhz(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC0StateResidency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC0SubstateC01Percent(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC0SubstateC02Percent(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC0SubstateC0WaitPercent(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC1StateResidency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC3StateResidency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC6StateResidency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUC7StateResidency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUCoreID(cpuID int) (int, error)
- func (pt *PowerTelemetry) GetCPUFrequency(cpuID int) (float64, error)
- func (pt *PowerTelemetry) GetCPUPackageID(cpuID int) (int, error)
- func (pt *PowerTelemetry) GetCPUTemperature(cpuID int) (uint64, error)
- func (pt *PowerTelemetry) GetCurrentDramPowerConsumptionWatts(packageID int) (float64, error)
- func (pt *PowerTelemetry) GetCurrentPackagePowerConsumptionWatts(packageID int) (float64, error)
- func (pt *PowerTelemetry) GetCurrentUncoreFrequency(packageID, dieID int) (float64, error)
- func (pt *PowerTelemetry) GetCustomizedUncoreFrequencyMax(packageID, dieID int) (float64, error)
- func (pt *PowerTelemetry) GetCustomizedUncoreFrequencyMin(packageID, dieID int) (float64, error)
- func (pt *PowerTelemetry) GetInitialUncoreFrequencyMax(packageID, dieID int) (float64, error)
- func (pt *PowerTelemetry) GetInitialUncoreFrequencyMin(packageID, dieID int) (float64, error)
- func (pt *PowerTelemetry) GetMaxTurboFreqList(packageID int) ([]MaxTurboFreq, error)
- func (pt *PowerTelemetry) GetMsrCPUIDs() []int
- func (pt *PowerTelemetry) GetPackageDieIDs(packageID int) ([]int, error)
- func (pt *PowerTelemetry) GetPackageIDs() []int
- func (pt *PowerTelemetry) GetPackageThermalDesignPowerWatts(packageID int) (float64, error)
- func (pt *PowerTelemetry) GetPerfCPUIDs() []int
- func (pt *PowerTelemetry) GetRaplPackageIDs() []int
- func (pt *PowerTelemetry) IsFlagSupported(flag string) (bool, error)
- func (pt *PowerTelemetry) ReadPerfEvents() error
- func (pt *PowerTelemetry) UpdatePerCPUMetrics(cpuID int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIfCPUBaseFrequencySupported ¶
CheckIfCPUBaseFrequencySupported checks if CPU base frequency metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
func CheckIfCPUC1StateResidencySupported ¶
CheckIfCPUC1StateResidencySupported checks if CPU C1 state residency metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
func CheckIfCPUC3StateResidencySupported ¶
CheckIfCPUC3StateResidencySupported checks if CPU C3 state residency metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
func CheckIfCPUC6StateResidencySupported ¶
CheckIfCPUC6StateResidencySupported checks if CPU C6 state residency metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
func CheckIfCPUC7StateResidencySupported ¶
CheckIfCPUC7StateResidencySupported checks if CPU C7 state residency metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
func CheckIfCPUTemperatureSupported ¶
CheckIfCPUTemperatureSupported checks if CPU temperature metric is supported by CPU model. Returns MetricNotSupportedError if metric is not supported by the CPU model; otherwise, returns nil.
Types ¶
type MaxTurboFreq ¶
type MaxTurboFreq struct { Value uint64 // Maximum reachable turbo frequency in MHz ActiveCores uint32 // Maximum number of active cores for the reachable turbo frequency Secondary bool // Attribute indicating if the list item is related to secondary cores of a hybrid architecture }
MaxTurboFreq is an item of a list of max turbo frequencies and related active cores.
type MetricNotSupportedError ¶
type MetricNotSupportedError struct {
// contains filtered or unexported fields
}
MetricNotSupportedError indicates that a metric is not supported.
func (*MetricNotSupportedError) Error ¶
func (e *MetricNotSupportedError) Error() string
Error returns a reason of this error.
type ModuleNotInitializedError ¶
type ModuleNotInitializedError struct {
Name string //holds name of not initialized module
}
ModuleNotInitializedError indicates that a module has not been initialized.
func (*ModuleNotInitializedError) Error ¶
func (e *ModuleNotInitializedError) Error() string
Error returns a reason of this error.
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError holds a slice of error descriptions. Implements Error interface. It is used to mark errors that happened during the initialization of PowerTelemetry dependencies.
func (*MultiError) Error ¶
func (e *MultiError) Error() string
Error returns a string with all error descriptions. Implements error.Error.
type Option ¶
type Option func(*powerBuilder)
func WithCoreFrequency ¶
WithCoreFrequency returns a function closure that initializes the coreFreqBuilder struct of a builder with the default configuration.
func WithExcludedCPUs ¶
WithExcludedCPUs returns a function closure that sets a slice with excluded CPU IDs of a builder.
func WithIncludedCPUs ¶
WithIncludedCPUs returns a function closure that sets a slice with included CPU IDs of a builder.
func WithLogger ¶
WithLogger returns a function closure that sets a user provided logger structure to be used to log messages. Note: this option is supposed to go first in the list of arguments passed to New() when creating a PowerTelemetry instance.
func WithMsr ¶
func WithMsr() Option
WithMsr returns a function closure that initializes the msrBuilder struct of a builder with the default configuration.
func WithMsrTimeout ¶
WithMsrTimeout returns a function closure that initializes the msrBuilder struct of a builder with the default configuration and given msr read timeout.
func WithPerf ¶
WithPerf takes a file path with perf event definition in JSON format. It returns a function closure that initializes a perfBuilder struct with the given JSON event definition file.
func WithRapl ¶
WithRapl returns a function closure that initializes the raplBuilder struct of a builder with the default configuration.
func WithUncoreFrequency ¶
WithUncoreFrequency returns a function closure that initializes the uncoreFreqBuilder struct of a builder with the default configuration.
type PowerTelemetry ¶
type PowerTelemetry struct {
// contains filtered or unexported fields
}
PowerTelemetry enables monitoring platform metrics.
func New ¶
func New(opts ...Option) (*PowerTelemetry, error)
New returns a PowerTelemetry instance that allows to gather power-related metrics from the host. An error is returned if either topology could not be initialized, or if the CPU model is not supported. Otherwise, a MultiError is returned if one or more user requested subsystems (pieces) fail to initialize.
func (*PowerTelemetry) DeactivatePerfEvents ¶
func (pt *PowerTelemetry) DeactivatePerfEvents() error
DeactivatePerfEvents deactivates all active events. If an event or events could not be successfully deactivated, an error is returned. This method should be explicitly called to avoid resource leakage.
func (*PowerTelemetry) GetCPUBaseFrequency ¶
func (pt *PowerTelemetry) GetCPUBaseFrequency(packageID int) (uint64, error)
GetCPUBaseFrequency returns the base frequency of the CPU in MHz. It takes a package ID as an argument and calculates the frequency using msr value. If an error occurs, it returns 0 and the error message.
func (*PowerTelemetry) GetCPUBusyFrequencyMhz ¶
func (pt *PowerTelemetry) GetCPUBusyFrequencyMhz(cpuID int) (float64, error)
GetCPUBusyFrequencyMhz takes a CPU ID and returns its busy frequency metric, in MHz.
func (*PowerTelemetry) GetCPUC0StateResidency ¶
func (pt *PowerTelemetry) GetCPUC0StateResidency(cpuID int) (float64, error)
GetCPUC0StateResidency takes a CPU ID and returns its C0 state residency metric, as a percentage.
func (*PowerTelemetry) GetCPUC0SubstateC01Percent ¶
func (pt *PowerTelemetry) GetCPUC0SubstateC01Percent(cpuID int) (float64, error)
GetCPUC0SubstateC01Percent takes a CPU ID and returns a value indicating the percentage of time the processor spent in its C0.1 substate out of the total time in the C0 state. C0.1 is characterized by a light-weight slower wakeup time but more power-saving optimized state.
func (*PowerTelemetry) GetCPUC0SubstateC02Percent ¶
func (pt *PowerTelemetry) GetCPUC0SubstateC02Percent(cpuID int) (float64, error)
GetCPUC0SubstateC02Percent takes a CPU ID and returns a value indicating the percentage of time the processor spent in its C0.2 substate out of the total time in the C0 state. C0.2 is characterized by a light-weight faster wakeup time but less power saving optimized state.
func (*PowerTelemetry) GetCPUC0SubstateC0WaitPercent ¶
func (pt *PowerTelemetry) GetCPUC0SubstateC0WaitPercent(cpuID int) (float64, error)
GetCPUC0SubstateC0WaitPercent takes a CPU ID and returns a value indicating the percentage of time the processor spent in its C0_Wait substate out of the total time in the C0 state. CPU is in C0_Wait substate when the thread is in the C0.1 or C0.2 or running a PAUSE in C0 ACPI state.
func (*PowerTelemetry) GetCPUC1StateResidency ¶
func (pt *PowerTelemetry) GetCPUC1StateResidency(cpuID int) (float64, error)
GetCPUC1StateResidency takes a CPU ID and returns its C1 state residency metric, as a percentage.
func (*PowerTelemetry) GetCPUC3StateResidency ¶
func (pt *PowerTelemetry) GetCPUC3StateResidency(cpuID int) (float64, error)
GetCPUC3StateResidency takes a CPU ID and returns its C3 state residency metric, as a percentage.
func (*PowerTelemetry) GetCPUC6StateResidency ¶
func (pt *PowerTelemetry) GetCPUC6StateResidency(cpuID int) (float64, error)
GetCPUC6StateResidency takes a CPU ID and returns its C6 state residency metric, as a percentage. C6 state residency is calculated within a time interval and the formula is as follows: c6[%] = 100 *(MSR_CORE_C6_RESIDENCY_2 - MSR_CORE_C6_RESIDENCY_1) / (IA32_TIME_STAMP_COUNTER_2 - IA32_TIME_STAMP_COUNTER_1).
func (*PowerTelemetry) GetCPUC7StateResidency ¶
func (pt *PowerTelemetry) GetCPUC7StateResidency(cpuID int) (float64, error)
GetCPUC7StateResidency takes a CPU ID and returns its C7 state residency metric, as a percentage.
func (*PowerTelemetry) GetCPUCoreID ¶
func (pt *PowerTelemetry) GetCPUCoreID(cpuID int) (int, error)
GetCPUCoreID gets cpu's core ID value. If no cpu is found for the corresponding cpuID an error is returned.
func (*PowerTelemetry) GetCPUFrequency ¶
func (pt *PowerTelemetry) GetCPUFrequency(cpuID int) (float64, error)
GetCPUFrequency returns current frequency value of specified cpu (in MHz).
func (*PowerTelemetry) GetCPUPackageID ¶
func (pt *PowerTelemetry) GetCPUPackageID(cpuID int) (int, error)
GetCPUPackageID gets cpu's package ID value. If no cpu is found for the corresponding cpuID an error is returned.
func (*PowerTelemetry) GetCPUTemperature ¶
func (pt *PowerTelemetry) GetCPUTemperature(cpuID int) (uint64, error)
GetCPUTemperature takes a cpu ID and returns its temperature, in degrees Celsius. CPU temperature is calculated based on cpu-specific msr offsets: temp[C] = MSR_TEMPERATURE_TARGET[23:16] - IA32_THERM_STATUS[22:16] If an error occurs while reading msr offsets, the function returns zero value for the temperature and the corresponding error.
func (*PowerTelemetry) GetCurrentDramPowerConsumptionWatts ¶
func (pt *PowerTelemetry) GetCurrentDramPowerConsumptionWatts(packageID int) (float64, error)
GetCurrentDramPowerConsumptionWatts takes a package ID and returns the current package domain power consumption package, in Watts.
func (*PowerTelemetry) GetCurrentPackagePowerConsumptionWatts ¶
func (pt *PowerTelemetry) GetCurrentPackagePowerConsumptionWatts(packageID int) (float64, error)
GetCurrentPackagePowerConsumptionWatts takes a package ID and returns the current package domain power consumption package, in Watts.
func (*PowerTelemetry) GetCurrentUncoreFrequency ¶
func (pt *PowerTelemetry) GetCurrentUncoreFrequency(packageID, dieID int) (float64, error)
GetCurrentUncoreFrequency takes a package ID and returns the current uncore frequency value (in MHz). First it tries to retrieve this value from sysfs. In case of error, it attempts to get this value from the CPU ID's MSR corresponding to the given package ID.
func (*PowerTelemetry) GetCustomizedUncoreFrequencyMax ¶
func (pt *PowerTelemetry) GetCustomizedUncoreFrequencyMax(packageID, dieID int) (float64, error)
GetCustomizedUncoreFrequencyMax retrieves the maximum customized uncore frequency limit (in MHz) for the specified package and die.
func (*PowerTelemetry) GetCustomizedUncoreFrequencyMin ¶
func (pt *PowerTelemetry) GetCustomizedUncoreFrequencyMin(packageID, dieID int) (float64, error)
GetCustomizedUncoreFrequencyMin retrieves the minimum customized uncore frequency limit (in MHz) for the specified package and die.
func (*PowerTelemetry) GetInitialUncoreFrequencyMax ¶
func (pt *PowerTelemetry) GetInitialUncoreFrequencyMax(packageID, dieID int) (float64, error)
GetInitialUncoreFrequencyMax retrieves the maximum initial uncore frequency limit (in MHz) for the specified package and die.
func (*PowerTelemetry) GetInitialUncoreFrequencyMin ¶
func (pt *PowerTelemetry) GetInitialUncoreFrequencyMin(packageID, dieID int) (float64, error)
GetInitialUncoreFrequencyMin retrieves the minimum initial uncore frequency limit (in MHz) for the specified package and die.
func (*PowerTelemetry) GetMaxTurboFreqList ¶
func (pt *PowerTelemetry) GetMaxTurboFreqList(packageID int) ([]MaxTurboFreq, error)
GetMaxTurboFreqList returns a list of max turbo frequencies and related active cores according to the package ID.
func (*PowerTelemetry) GetMsrCPUIDs ¶
func (pt *PowerTelemetry) GetMsrCPUIDs() []int
GetMsrCPUIDs returns a slice with available CPU IDs of the host, for which msr has access to.
func (*PowerTelemetry) GetPackageDieIDs ¶
func (pt *PowerTelemetry) GetPackageDieIDs(packageID int) ([]int, error)
GetPackageDieIDs gets package's die ID values. If no package is found for the corresponding packageID an error is returned.
func (*PowerTelemetry) GetPackageIDs ¶
func (pt *PowerTelemetry) GetPackageIDs() []int
GetPackageIDs returns a slice with ordered package IDs of the host.
func (*PowerTelemetry) GetPackageThermalDesignPowerWatts ¶
func (pt *PowerTelemetry) GetPackageThermalDesignPowerWatts(packageID int) (float64, error)
GetPackageThermalDesignPowerWatts takes a package ID and returns its maximum allowed power, in Watts.
func (*PowerTelemetry) GetPerfCPUIDs ¶
func (pt *PowerTelemetry) GetPerfCPUIDs() []int
GetPerfCPUIDs returns a slice with available CPU IDs of the host, for which perf has access to.
func (*PowerTelemetry) GetRaplPackageIDs ¶
func (pt *PowerTelemetry) GetRaplPackageIDs() []int
GetRaplPackageIDs returns a slice with package IDs of the host for which rapl has access to. If rapl is not initialized, it returns nil.
func (*PowerTelemetry) IsFlagSupported ¶
func (pt *PowerTelemetry) IsFlagSupported(flag string) (bool, error)
IsFlagSupported takes a flag's value and returns true if first CPU supports it and false if it doesn't.
func (*PowerTelemetry) ReadPerfEvents ¶
func (pt *PowerTelemetry) ReadPerfEvents() error
ReadPerfEvents reads the perf events related to supported C0 state residency metrics and updates the storage to make metrics available. If one or more events could not be read an error is returned.
func (*PowerTelemetry) UpdatePerCPUMetrics ¶
func (pt *PowerTelemetry) UpdatePerCPUMetrics(cpuID int) error
UpdatePerCPUMetrics takes a CPU ID and updates the msr storage with offset values and deltas corresponding to msr file for CPU ID.