| // 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/power" |
| "chromiumos/tast/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: IdlePerf, |
| Desc: "Measures the CPU usage while the desktop is idle", |
| Contacts: []string{"mukai@chromium.org", "tclaiborne@chromium.org"}, |
| Attr: []string{"group:crosbolt", "crosbolt_perbuild"}, |
| SoftwareDeps: []string{"chrome"}, |
| Pre: arc.Booted(), |
| Params: []testing.Param{{ |
| ExtraSoftwareDeps: []string{"android_p"}, |
| }, { |
| Name: "arcvm", |
| ExtraSoftwareDeps: []string{"android_vm"}, |
| }}, |
| }) |
| } |
| |
| func IdlePerf(ctx context.Context, s *testing.State) { |
| // 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 |
| |
| // Shorten context a bit to allow for cleanup. |
| closeCtx := ctx |
| ctx, cancel := ctxutil.Shorten(ctx, 2*time.Second) |
| defer cancel() |
| |
| tconn, err := cr.TestAPIConn(ctx) |
| if err != nil { |
| s.Fatal("Failed to connect to test API: ", err) |
| } |
| |
| // Recorder with no additional config; it records and reports memory usage and |
| // CPU percents of browser/GPU processes. |
| recorder, err := cuj.NewRecorder(ctx, tconn) |
| 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 err := recorder.Run(ctx, func(ctx context.Context) error { |
| s.Log("Just wait for 30 seconds to check the load of idle status") |
| return testing.Sleep(ctx, 30*time.Second) |
| }); 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) |
| } |
| } |