Skip to content

Commit 6cadcc9

Browse files
author
Paweł Szulik
committed
Prepare perf event collector only when metrics are enabled.
Signed-off-by: Paweł Szulik <[email protected]>
1 parent 6acde09 commit 6cadcc9

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

manager/manager.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,12 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
934934
}
935935

936936
if cgroups.IsCgroup2UnifiedMode() {
937-
perfCgroupPath := path.Join(fs2.UnifiedMountpoint, containerName)
938-
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
939-
if err != nil {
940-
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
937+
if m.includedMetrics.Has(container.PerfMetrics) {
938+
perfCgroupPath := path.Join(fs2.UnifiedMountpoint, containerName)
939+
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
940+
if err != nil {
941+
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
942+
}
941943
}
942944
} else {
943945
devicesCgroupPath, err := handler.GetCgroupPath("devices")
@@ -949,13 +951,15 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
949951
klog.V(4).Infof("GPU metrics may be unavailable/incomplete for container %s: %s", cont.info.Name, err)
950952
}
951953
}
952-
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
953-
if err != nil {
954-
klog.Warningf("Error getting perf_event cgroup path: %q", err)
955-
} else {
956-
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
954+
if m.includedMetrics.Has(container.PerfMetrics) {
955+
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
957956
if err != nil {
958-
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
957+
klog.Warningf("Error getting perf_event cgroup path: %q", err)
958+
} else {
959+
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
960+
if err != nil {
961+
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
962+
}
959963
}
960964
}
961965
}

0 commit comments

Comments
 (0)