memoryuser

package
v0.0.0-...-683b059 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Overview

Package memoryuser contains common code to run multifaceted memory tests with Chrome, ARC, and VMs.

Index

Constants

View Source
const (
	AllocPageFilename  = "memory_stress.html"
	JavascriptFilename = "memory_stress.js"
)

Resources needed by MemoryStressServer to create MemoryStressTasks.

View Source
const ArcLifecycleUnitCount = 100

ArcLifecycleUnitCount is the number of different ARC lifecycle app packages, which is the number of different lifecycle apps we can run at the same time.

Variables

This section is empty.

Functions

func FillArcMemory

func FillArcMemory(ctx context.Context, a *arc.ARC, tconn *chrome.TestConn, unitBytes int64, ratio float64) (func(context.Context) error, error)

FillArcMemory installs, launches, and allocated in ArcLifecycleTest apps until one is killed, filling up memory in ARC.

func FillChromeOSMemory

func FillChromeOSMemory(ctx context.Context, dataFileSystem http.FileSystem, cr *chrome.Chrome, unitMiB int, ratio float32) (func(context.Context) error, error)

FillChromeOSMemory launches memory stress tabs until one is killed, filling up memory in ChromeOS.

func FillCrostiniMemory

func FillCrostiniMemory(ctx context.Context, cont *vm.Container, unitMiB int64, ratio float64) (func(context.Context) error, error)

FillCrostiniMemory installs, launches, and allocates in crostini lifecycle processes until one is killed, filling up memory in Crostini.

func InstallArcLifecycleTestApps

func InstallArcLifecycleTestApps(ctx context.Context, a *arc.ARC, num int) error

InstallArcLifecycleTestApps installs 'howMany' copies of ArcLifecycleTest. The maximum number of apps that can be installed is ArcLifecycleUnitCount.

func InstallCrostiniLifecycle

func InstallCrostiniLifecycle(ctx context.Context, cont *vm.Container) error

InstallCrostiniLifecycle installs the binary needed to run CrostiniLifecycleTask.

func RunTest

func RunTest(ctx context.Context, outDir string, tasks []MemoryTask, p *RunParameters) (errRet error)

RunTest creates a new TestEnv and then runs ARC, Chrome, and VM tasks in parallel. It also logs memory and cpu usage throughout the test, and copies output from /var/log/memd and /var/log/vmlog when finished. All passed-in tasks will be closed automatically.

func UninstallCrostiniLifecycle

func UninstallCrostiniLifecycle(ctx context.Context, cont *vm.Container) error

UninstallCrostiniLifecycle deletes the binary used to run CrostiniLifecycleTask, and kills any processes that might still be running.

Types

type AndroidTask

type AndroidTask struct {
	// APKPath is the path to use to access the APK file.
	APKPath string
	// APK is a filename of an APK file in the data directory.
	APK string
	// Pkg is the package name of the app to launch.
	Pkg string
	// ActivityName is the activity class name of the app to launch.
	ActivityName string
	// TestFunc is the test body function to run.
	TestFunc func(a *arc.ARC)
}

AndroidTask implements MemoryTask to run ARC apps.

func (*AndroidTask) Close

func (at *AndroidTask) Close(ctx context.Context, testEnv *TestEnv)

Close stops everything associated with the package defined in the AndroidTask.

func (*AndroidTask) NeedVM

func (at *AndroidTask) NeedVM() bool

NeedVM returns false to indicate no VM is required for an AndroidTask.

func (*AndroidTask) Run

func (at *AndroidTask) Run(ctx context.Context, testEnv *TestEnv) error

Run installs the app APK and runs the test function defined in the AndroidTask in the existing ARC instance.

func (*AndroidTask) String

func (at *AndroidTask) String() string

String returns a string describing the AndroidTask.

type ArcLifecycleTask

type ArcLifecycleTask struct {
	ArcLifecycleUnit
}

ArcLifecycleTask wraps ArcLifecycleUnit to conform to the MemoryTask and KillableTask interfaces.

func NewArcLifecycleTask

func NewArcLifecycleTask(id int, allocateBytes int64, ratio float64, limit memory.Limit, minimize bool) *ArcLifecycleTask

NewArcLifecycleTask creates a MemoryTask that runs the ArcLifecycleTest app and uses it to allocate memory.

id            - Which copy of ArcLifecycleTest app to use.
allocateBytes - mow much memory to allocate.
ratio         - the compression ratio of allocated memory.
limit         - if not nil, wait for Limit after allocation.
minimize      - minimize the app window after allocation completes.

func (*ArcLifecycleTask) Close

func (t *ArcLifecycleTask) Close(ctx context.Context, testEnv *TestEnv)

Close kills the AndroidLifecycleTest app.

func (*ArcLifecycleTask) NeedVM

func (t *ArcLifecycleTask) NeedVM() bool

NeedVM returns false, because we don't need Crostini.

func (*ArcLifecycleTask) Run

func (t *ArcLifecycleTask) Run(ctx context.Context, testEnv *TestEnv) error

Run starts the AndroidLifecycleTest app, and uses it to allocate memory.

func (*ArcLifecycleTask) StillAlive

func (t *ArcLifecycleTask) StillAlive(ctx context.Context, testEnv *TestEnv) bool

StillAlive checks to see if the AndroidLifecycleTest app is alive and responding to intents.

func (*ArcLifecycleTask) String

func (t *ArcLifecycleTask) String() string

String returns a friendly string containing the

type ArcLifecycleUnit

type ArcLifecycleUnit struct {
	// contains filtered or unexported fields
}

ArcLifecycleUnit launches an Android app which allocates memory.

func NewArcLifecycleUnit

func NewArcLifecycleUnit(id int, allocateBytes int64, ratio float64, limit memory.Limit, minimize bool) *ArcLifecycleUnit

NewArcLifecycleUnit creates a helper to allocate memory inside an app in ARC.

id            - Which copy of ArcLifecycleTest app to use.
allocateBytes - mow much memory to allocate.
ratio         - the compression ratio of allocated memory.
limit         - if not nil, wait for Limit after allocation.
minimize      - minimize the app window after allocation completes.

func (*ArcLifecycleUnit) Close

func (t *ArcLifecycleUnit) Close(ctx context.Context, a *arc.ARC)

Close kills the AndroidLifecycleTest app.

func (*ArcLifecycleUnit) Run

func (t *ArcLifecycleUnit) Run(ctx context.Context, a *arc.ARC, tconn *chrome.TestConn) error

Run starts the AndroidLifecycleTest app, and uses it to allocate memory.

func (*ArcLifecycleUnit) StillAlive

func (t *ArcLifecycleUnit) StillAlive(ctx context.Context, a *arc.ARC) bool

StillAlive checks to see if the AndroidLifecycleTest app is alive and responding to intents.

type ChromeTask

type ChromeTask struct {
	// URLs is a cyclical list of URLs to be opened.
	URLs []string
	// NumTabs is the total number of tabs to be opened.
	NumTabs int
	// contains filtered or unexported fields
}

ChromeTask implements MemoryTask to open Chrome tabs.

func (*ChromeTask) Close

func (ct *ChromeTask) Close(ctx context.Context, testEnv *TestEnv)

Close closes all of the Chrome connections defined in ChromeTask, created in Run.

func (*ChromeTask) NeedVM

func (ct *ChromeTask) NeedVM() bool

NeedVM returns false to indicate that no VM is required for a ChromeTask.

func (*ChromeTask) Run

func (ct *ChromeTask) Run(ctx context.Context, testEnv *TestEnv) error

Run opens the number of tabs defined in ChromeTask, cycling through the list of URLs defined in ChromeTask for each new tab.

func (*ChromeTask) String

func (ct *ChromeTask) String() string

String returns a string describing the ChromeTask.

type CrostiniLifecycleTask

type CrostiniLifecycleTask struct{ CrostiniLifecycleUnit }

CrostiniLifecycleTask wraps CrostiniLifecycleTask to conform to the MemoryTask and KillableTask interfaces.

func NewCrostiniLifecycleTask

func NewCrostiniLifecycleTask(cont *vm.Container, id int, allocateMiB int64, ratio float64, limit memory.Limit) *CrostiniLifecycleTask

NewCrostiniLifecycleTask creates a helper to allocate memory inside Crostini.

id            - A debug ID for logging.
allocateBytes - mow much memory to allocate.
ratio         - the compression ratio of allocated memory.
limit         - if not nil, wait for Limit after allocation.

func (*CrostiniLifecycleTask) Close

func (t *CrostiniLifecycleTask) Close(ctx context.Context, testEnv *TestEnv)

Close kills the CrostiniLifecycleUnit process.

func (*CrostiniLifecycleTask) NeedVM

func (t *CrostiniLifecycleTask) NeedVM() bool

NeedVM returns false because, while we do need a Crostini VM, we don't want a new one created ust for this MemoryTask.

func (*CrostiniLifecycleTask) Run

func (t *CrostiniLifecycleTask) Run(ctx context.Context, testEnv *TestEnv) error

Run starts the CrostiniLifecycleUnit process, and uses it to allocate memory.

func (*CrostiniLifecycleTask) StillAlive

func (t *CrostiniLifecycleTask) StillAlive(ctx context.Context, testEnv *TestEnv) bool

StillAlive returns false if the process has exited, or if it never started.

func (*CrostiniLifecycleTask) String

func (t *CrostiniLifecycleTask) String() string

String returns a friendly name for the task.

type CrostiniLifecycleUnit

type CrostiniLifecycleUnit struct {
	// contains filtered or unexported fields
}

CrostiniLifecycleUnit launches a process in Crostini which allocates memory.

func NewCrostiniLifecycleUnit

func NewCrostiniLifecycleUnit(cont *vm.Container, id int, allocateMiB int64, ratio float64, limit memory.Limit) *CrostiniLifecycleUnit

NewCrostiniLifecycleUnit creates a helper to allocate memory inside Crostini.

id            - A debug ID for logging.
allocateBytes - mow much memory to allocate.
ratio         - the compression ratio of allocated memory.
limit         - if not nil, wait for Limit after allocation.

func (*CrostiniLifecycleUnit) Close

Close kills the CrostiniLifecycleUnit process.

func (*CrostiniLifecycleUnit) Run

Run starts the CrostiniLifecycleUnit process, and uses it to allocate memory.

func (*CrostiniLifecycleUnit) StillAlive

func (t *CrostiniLifecycleUnit) StillAlive(ctx context.Context) bool

StillAlive returns false if the process has exited, or if it never started.

type KillableTask

type KillableTask interface {
	StillAlive(context.Context, *TestEnv) bool
}

KillableTask allows querying whether a task has been killed or not.

type MemPressureTask

type MemPressureTask struct {
	Params *mempressure.RunParameters
}

MemPressureTask implements MemoryTask to create memory pressure by opening Chrome tabs.

func (*MemPressureTask) Close

func (mpt *MemPressureTask) Close(ctx context.Context, testEnv *TestEnv)

Close does nothing, the Run method of platform.MemoryPressure already closes the connections

func (*MemPressureTask) NeedVM

func (mpt *MemPressureTask) NeedVM() bool

NeedVM returns false to indicate that no VM is required for a MemPressureTask.

func (*MemPressureTask) Run

func (mpt *MemPressureTask) Run(ctx context.Context, testEnv *TestEnv) error

Run starts the platform.MemoryPressure test, creating memory pressure by opening Chrome tabs

func (*MemPressureTask) String

func (mpt *MemPressureTask) String() string

String returns a string describing the MemPressureTask.

type MemoryStressServer

type MemoryStressServer struct {
	// contains filtered or unexported fields
}

MemoryStressServer is an http server that hosts the html and js needed to create MemoryStressTasks.

func NewMemoryStressServer

func NewMemoryStressServer(dataFileSystem http.FileSystem) *MemoryStressServer

NewMemoryStressServer creates a server that can create MemoryStressTasks. Close() should be called after use.

func (*MemoryStressServer) Close

func (s *MemoryStressServer) Close()

Close shuts down the http server.

func (*MemoryStressServer) NewMemoryStressTask

func (s *MemoryStressServer) NewMemoryStressTask(allocMiB int, ratio float32, cooldown time.Duration) *MemoryStressTask

NewMemoryStressTask creates a new MemoryStressTask. allocMiB - The amount of memory the tab will allocate. ratio - How compressible the allocated memory will be. cooldown - How long to wait after allocating before returning.

func (*MemoryStressServer) NewMemoryStressUnit

func (s *MemoryStressServer) NewMemoryStressUnit(allocMiB int, ratio float32, cooldown time.Duration) *MemoryStressUnit

NewMemoryStressUnit creates a new MemoryStressUnit. allocMiB - The amount of memory the tab will allocate. ratio - How compressible the allocated memory will be. cooldown - How long to wait after allocating before returning.

type MemoryStressTask

type MemoryStressTask struct{ MemoryStressUnit }

MemoryStressTask wraps MemoryStressUnit to conform to the MemoryTask and KillableTask interfaces.

func (*MemoryStressTask) Close

func (st *MemoryStressTask) Close(ctx context.Context, testEnv *TestEnv)

Close closes the memory stress allocation tab.

func (*MemoryStressTask) NeedVM

func (st *MemoryStressTask) NeedVM() bool

NeedVM is false because we do not need Crostini.

func (*MemoryStressTask) Run

func (st *MemoryStressTask) Run(ctx context.Context, testEnv *TestEnv) error

Run creates a Chrome tab that allocates memory, then waits for the provided cooldown.

func (*MemoryStressTask) StillAlive

func (st *MemoryStressTask) StillAlive(ctx context.Context, testEnv *TestEnv) bool

StillAlive returns false if the tab has been discarded, or was never opened.

func (*MemoryStressTask) String

func (st *MemoryStressTask) String() string

String returns a friendly name for the task.

type MemoryStressUnit

type MemoryStressUnit struct {
	// contains filtered or unexported fields
}

MemoryStressUnit creates a Chrome tab that allocates memory like the platform.MemoryStressBasic test.

func (*MemoryStressUnit) Close

func (st *MemoryStressUnit) Close(ctx context.Context, cr *chrome.Chrome) error

Close closes the memory stress allocation tab.

func (*MemoryStressUnit) Run

func (st *MemoryStressUnit) Run(ctx context.Context, cr *chrome.Chrome) error

Run creates a Chrome tab that allocates memory, then waits for the provided cooldown.

func (*MemoryStressUnit) StillAlive

func (st *MemoryStressUnit) StillAlive(ctx context.Context, cr *chrome.Chrome) bool

StillAlive uses Chrome's debug tools to determine if a tab has been killed. It has not been killed if it is still a target for debugging.

type MemoryTask

type MemoryTask interface {
	// Run performs the memory-related task.
	Run(ctx context.Context, testEnv *TestEnv) error
	// Close closes any initialized data and connections for the memory-related task.
	Close(ctx context.Context, testEnv *TestEnv)
	// String returns a string describing the memory-related task.
	String() string
	// NeedVM returns a bool indicating whether the task needs a VM
	NeedVM() bool
}

MemoryTask describes a memory-consuming task to perform. This allows various types of activities, such as ARC, Chrome, and VMs, to be defined using the same setup and run in parallel.

type MinStillAliveMetricTask

type MinStillAliveMetricTask struct {
	// contains filtered or unexported fields
}

MinStillAliveMetricTask is a MemoryTask that reports the minimum value reported by a slice of StillAliveMetricTasks.

func NewMinStillAliveMetricTask

func NewMinStillAliveMetricTask(tasks []*StillAliveMetricTask, name string) *MinStillAliveMetricTask

NewMinStillAliveMetricTask creates a new MemoryTask that records a perf.Metric for the minimum value of a set of StillAliveMetricsTasks.

func (*MinStillAliveMetricTask) Close

Close does nothing.

func (*MinStillAliveMetricTask) NeedVM

func (t *MinStillAliveMetricTask) NeedVM() bool

NeedVM is false because we do not need a new Crostini VM spun up.

func (*MinStillAliveMetricTask) Run

func (t *MinStillAliveMetricTask) Run(ctx context.Context, testEnv *TestEnv) error

Run actually computes the metric.

func (*MinStillAliveMetricTask) String

func (t *MinStillAliveMetricTask) String() string

String gives MemoryUser a friendly string for logging.

type RunParameters

type RunParameters struct {
	// WPRMode is the mode to start WPR.
	WPRMode wpr.Mode
	// WPRArchivePath is the full path to an archive for WPR. If set, WPR is used
	// and Chrome sends its traffic through WPR. Otherwise, Chrome uses live
	// sites.
	WPRArchivePath string
	// UseARC indicates whether Chrome should be started with ARC enabled.
	UseARC bool
	// ParallelTasks indicates whether the memory tasks should be run in parallel
	ParallelTasks bool
	// ExistingChrome indicates that we should use this Chrome instance instead
	// of creating a new one.
	ExistingChrome *chrome.Chrome
	// ExistingARC indicates that we should use this ARC instance instead of
	// creating a new one. ExistingChrome and UseARC must be set.
	ExistingARC *arc.ARC
	// ExistingPerfValues indicates that we should use this perf.Values instead
	// of creating a new one. The caller is responsible calling
	// perf.Values.Save().
	ExistingPerfValues *perf.Values
}

RunParameters contains the configurable parameters for RunTest.

type StillAliveMetricTask

type StillAliveMetricTask struct {
	// contains filtered or unexported fields
}

StillAliveMetricTask is a MemoryTask that counts how many of a set of KillableTask are still alive, and records it as a perf.Metric.

func NewStillAliveMetricTask

func NewStillAliveMetricTask(tasks []KillableTask, name string) *StillAliveMetricTask

NewStillAliveMetricTask creates a new MemoryTask that records a perf.Metric for how many of a set of tasks are still alive.

func (*StillAliveMetricTask) Close

func (t *StillAliveMetricTask) Close(_ context.Context, _ *TestEnv)

Close does nothing.

func (*StillAliveMetricTask) NeedVM

func (t *StillAliveMetricTask) NeedVM() bool

NeedVM is false because we do not need a new Crostini VM spun up.

func (*StillAliveMetricTask) Run

func (t *StillAliveMetricTask) Run(ctx context.Context, testEnv *TestEnv) error

Run actually computes the metric.

func (*StillAliveMetricTask) StillAlive

func (t *StillAliveMetricTask) StillAlive() int

StillAlive returns how many tasks were reported to be still alive. Returns -1 if this task hasn't run yet.

func (*StillAliveMetricTask) String

func (t *StillAliveMetricTask) String() string

String gives MemoryUser a friendly string for logging.

type TestEnv

type TestEnv struct {
	// contains filtered or unexported fields
}

TestEnv is a struct containing the data to be used across the test.

func (*TestEnv) Close

func (te *TestEnv) Close(ctx context.Context, p *RunParameters)

Close closes the Chrome, ARC, and WPR instances used in the TestEnv.

type VMCmd

type VMCmd []string

VMCmd contains a list of vshArgs to use in the container command.

type VMTask

type VMTask struct {
	// VMCommands is a list of VMCmds.
	Cmds  []VMCmd
	Files []string
}

VMTask implements MemoryTask to run commands in a VM.

func (*VMTask) Close

func (vt *VMTask) Close(ctx context.Context, testEnv *TestEnv)

Close does nothing since VMTask does not initialize anything in Run.

func (*VMTask) NeedVM

func (vt *VMTask) NeedVM() bool

NeedVM returns true to indicate that a VM is required for a VMTask.

func (*VMTask) Run

func (vt *VMTask) Run(ctx context.Context, testEnv *TestEnv) error

Run executes the list of VMCommands defined in VMTask in the existing VM from the TestEnvironment.

func (*VMTask) String

func (vt *VMTask) String() string

String returns a string describing the VMTask.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL