/
idle_perf.go
109 lines (95 loc) · 3.17 KB
/
idle_perf.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2020 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 ui
import (
"context"
"time"
"chromiumos/tast/common/perf"
"chromiumos/tast/ctxutil"
"chromiumos/tast/local/arc"
"chromiumos/tast/local/bundles/cros/ui/cuj"
"chromiumos/tast/local/cpu"
"chromiumos/tast/local/power"
"chromiumos/tast/testing"
)
type tracingMode bool
const (
tracingOn tracingMode = true
tracingOff tracingMode = false
idleDuration = 30 * time.Second
)
func init() {
testing.AddTest(&testing.Test{
Func: IdlePerf,
LacrosStatus: testing.LacrosVariantUnknown,
Desc: "Measures the CPU usage while the desktop is idle",
Contacts: []string{"xiyuan@chromium.org", "yichenz@chromium.org", "chromeos-perfmetrics-eng@google.com"},
Attr: []string{"group:crosbolt", "crosbolt_perbuild", "group:cuj"},
SoftwareDeps: []string{"chrome"},
Timeout: cuj.CPUStablizationTimeout + idleDuration,
Pre: arc.Booted(),
Params: []testing.Param{{
ExtraSoftwareDeps: []string{"android_p"},
Val: tracingOff,
}, {
Name: "trace",
ExtraSoftwareDeps: []string{"android_p"},
Val: tracingOn,
}, {
Name: "arcvm",
ExtraSoftwareDeps: []string{"android_vm"},
Val: tracingOff,
}, {
Name: "arcvm_trace",
ExtraSoftwareDeps: []string{"android_vm"},
Val: tracingOn,
}},
})
}
func IdlePerf(ctx context.Context, s *testing.State) {
tracing := s.Param().(tracingMode)
// Ensure display on to record ui performance correctly.
if err := power.TurnOnDisplay(ctx); err != nil {
s.Fatal("Failed to turn on display: ", err)
}
cr := s.PreValue().(arc.PreData).Chrome
a := s.PreValue().(arc.PreData).ARC
// Wait for cpu to stabilize before test.
if err := cpu.WaitUntilStabilized(ctx, cuj.CPUCoolDownConfig()); err != nil {
// Log the cpu stabilizing wait failure instead of make it fatal.
// TODO(b/213238698): Include the error as part of test data.
s.Log("Failed to wait for CPU to become idle: ", err)
}
// Shorten context a bit to allow for cleanup.
closeCtx := ctx
ctx, cancel := ctxutil.Shorten(ctx, 2*time.Second)
defer cancel()
// Recorder with no additional config; it records and reports memory usage and
// CPU percents of browser/GPU processes.
recorder, err := cuj.NewRecorder(ctx, cr, a, cuj.RecorderOptions{}, cuj.MetricConfig{})
if err != nil {
s.Fatal("Failed to create a recorder: ", err)
}
defer func() {
if err := recorder.Close(closeCtx); err != nil {
s.Error("Failed to stop recorder: ", err)
}
}()
if tracing {
recorder.EnableTracing(s.OutDir())
}
if err := recorder.Run(ctx, func(ctx context.Context) error {
s.Log("Just wait for ", idleDuration, " to check the load of idle status")
return testing.Sleep(ctx, idleDuration)
}); err != nil {
s.Fatal("Failed to run the test scenario: ", err)
}
pv := perf.NewValues()
if err = recorder.Record(ctx, pv); err != nil {
s.Fatal("Failed to report: ", err)
}
if err = pv.Save(s.OutDir()); err != nil {
s.Error("Failed to store values: ", err)
}
}