mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-26 06:04:20 -08:00
Minor cleanup in perf collector (#1616)
* Use `strconv.Itoa()` instead of `fmt.Sprintf()` for simple conversion. * Eliminate copy-paste in collector setup. Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
ec62141388
commit
c4183f9935
|
@ -111,11 +111,22 @@ func NewPerfCollector(logger log.Logger) (Collector, error) {
|
|||
logger: logger,
|
||||
}
|
||||
|
||||
var (
|
||||
cpus []int
|
||||
err error
|
||||
)
|
||||
if perfCPUsFlag != nil && *perfCPUsFlag != "" {
|
||||
cpus, err := perfCPUFlagToCPUs(*perfCPUsFlag)
|
||||
cpus, err = perfCPUFlagToCPUs(*perfCPUsFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
cpus = make([]int, runtime.NumCPU())
|
||||
for i := range cpus {
|
||||
cpus[i] = i
|
||||
}
|
||||
}
|
||||
|
||||
for _, cpu := range cpus {
|
||||
// Use -1 to profile all processes on the CPU, see:
|
||||
// man perf_event_open
|
||||
|
@ -137,27 +148,6 @@ func NewPerfCollector(logger log.Logger) (Collector, error) {
|
|||
}
|
||||
collector.perfCacheProfilers[cpu] = &cacheProf
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
hwProf := perf.NewHardwareProfiler(-1, i)
|
||||
if err := hwProf.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
collector.perfHwProfilers[i] = &hwProf
|
||||
|
||||
swProf := perf.NewSoftwareProfiler(-1, i)
|
||||
if err := swProf.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
collector.perfSwProfilers[i] = &swProf
|
||||
|
||||
cacheProf := perf.NewCacheProfiler(-1, i)
|
||||
if err := cacheProf.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
collector.perfCacheProfilers[i] = &cacheProf
|
||||
}
|
||||
}
|
||||
|
||||
collector.desc = map[string]*prometheus.Desc{
|
||||
"cpucycles_total": prometheus.NewDesc(
|
||||
|
@ -425,7 +415,7 @@ func (c *perfCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
func (c *perfCollector) updateHardwareStats(ch chan<- prometheus.Metric) error {
|
||||
for _, profiler := range c.perfHwProfilers {
|
||||
cpuid := c.hwProfilerCPUMap[profiler]
|
||||
cpuStr := fmt.Sprintf("%d", cpuid)
|
||||
cpuStr := strconv.Itoa(cpuid)
|
||||
hwProfile, err := (*profiler).Profile()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue