forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemory_ablation_study.h
65 lines (47 loc) · 1.96 KB
/
memory_ablation_study.h
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
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_MEMORY_MEMORY_ABLATION_STUDY_H_
#define CHROMEOS_MEMORY_MEMORY_ABLATION_STUDY_H_
#include <cstdint>
#include <vector>
#include "base/gtest_prod_util.h"
#include "base/timer/timer.h"
#include "chromeos/chromeos_export.h"
namespace chromeos {
// This class is the implementation of a memory ablation study. It artificially
// increases memory usage for different experiment arms.
class CHROMEOS_EXPORT MemoryAblationStudy {
public:
MemoryAblationStudy();
MemoryAblationStudy(const MemoryAblationStudy&) = delete;
MemoryAblationStudy& operator=(const MemoryAblationStudy&) = delete;
~MemoryAblationStudy();
private:
FRIEND_TEST_ALL_PREFIXES(CrosMemoryAblationStudy, Basic);
using Region = std::vector<uint8_t>;
// Allocates more memory if necessary. "remaining_allocation_mb_" is
// guaranteed to be greater than 0.
void Allocate();
// Reads from all allocated pages.
void Read();
// The remaining amount of memory this class still needs to allocate, in
// megabytes.
int32_t remaining_allocation_mb_ = 0;
// When this timer fires, more memory is allocated. This timer is stopped once
// the desired allocation amount is reached.
base::RepeatingTimer allocate_timer_;
// When this timer fires, the class reads one byte from each allocated page to
// ensure that the pages are resident.
base::RepeatingTimer read_timer_;
// A dummy variable used to help force pages to become resident.
uint8_t dummy_read_ = 0;
// The index of the last region that was read/paged-in.
size_t last_region_read_ = 0;
// Holds all allocated regions.
std::vector<Region> regions_;
// This region is exactly 4096 bytes in size and contains uncompressible data.
Region uncompressible_region_;
};
} // namespace chromeos
#endif // CHROMEOS_MEMORY_MEMORY_ABLATION_STUDY_H_