/
check_tracefs_instances.go
52 lines (42 loc) · 1.66 KB
/
check_tracefs_instances.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package platform
import (
"context"
"io/ioutil"
"github.com/shirou/gopsutil/v3/cpu"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: CheckTracefsInstances,
Desc: "Checks that the number of tracefs instances doesn't exceed the number of CPU cores/threads",
Contacts: []string{"chinglinyu@chromium.org"},
Attr: []string{"group:mainline", "informational"},
})
}
// CheckTracefsInstances checks that we don't have more tracefs instances than the number of processors as a warning of potential boot performance issues with SELinux labeling.
func CheckTracefsInstances(ctx context.Context, s *testing.State) {
const tracefsInstancesPath = "/sys/kernel/debug/tracing/instances"
cpuInfo, err := cpu.InfoWithContext(ctx)
if err != nil {
s.Fatal("Failed to get CPU info: ", err)
}
np := len(cpuInfo) // np: number of processors.
instances, err := ioutil.ReadDir(tracefsInstancesPath)
if err != nil {
s.Fatal("Failed to read the instances directory: ", err)
}
ni := 1 // ni: number of instances, starting from 1 (the default instance).
for _, instance := range instances {
if instance.IsDir() {
ni++ // Found additional instances.
}
}
s.Logf("Number of processors: %d, number of tracefs instances: %d", np, ni)
if ni > 0 && ni > np {
// This is potentially harmful to boot performance. Fail the test as a warning.
s.Fatalf("More tracefs instances than the number of processors (got %d, want <= %d): tracefs labeling is potentially slow", ni, np)
}
}