Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
153 lines (108 loc) · 5.29 KB
/
Copy pathmain.cpp
File metadata and controls
153 lines (108 loc) · 5.29 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#define MALLOC_TRACKER_IMPLEMENTATION
#include "util/malloc_tracker.h"
#include "util/logger.hpp"
#include "flash.hpp"
#include "bench.hpp"
int main() {
Generic_Bench *bench = nullptr;
// get arguments via env
std::string r_gr = std::getenv("FLASH_READ_GRANULARITY") ? std::string(std::getenv("FLASH_READ_GRANULARITY")) : "";
std::string w_gr = std::getenv("FLASH_WRITE_GRANULARITY") ? std::string(std::getenv("FLASH_WRITE_GRANULARITY")) : "";
Config flash_config{
std::getenv("FLASH_SIZE") ? atoi(std::getenv("FLASH_SIZE")) : MiB(128),
std::getenv("FLASH_PAGE_SIZE") ? atoi(std::getenv("FLASH_PAGE_SIZE")) : 256U,
std::getenv("FLASH_SECTOR_SIZE") ? atoi(std::getenv("FLASH_SECTOR_SIZE")) : KiB(4),
r_gr == "PAGE_WISE" ? Config::PAGE_WISE : Config::BYTE_WISE,
w_gr == "PAGE_WISE" ? Config::PAGE_WISE : Config::BYTE_WISE,
};
std::string fs_name = std::getenv("FS") ? std::string(std::getenv("FS")) : "LFS";
std::string bench_func = std::getenv("BENCH") ? std::string(std::getenv("BENCH")) : "write";
size_t start_size = std::getenv("START_SIZE") ? atoi(std::getenv("START_SIZE")) : 1024;
size_t its = std::getenv("ITS") ? atoi(std::getenv("ITS")) : 64;
size_t fill_level = std::getenv("PRE_FILL") ? atoi(std::getenv("PRE_FILL")) : 0;
bool keep_files = std::getenv("KEEP_FILES")
? (std::string(std::getenv("KEEP_FILES")) == "y" ? true : false)
: false;
size_t chunk_size = std::getenv("CHUNK_SIZE")
? atoi(std::getenv("CHUNK_SIZE"))
: flash_config.page_size;
LOG_INFO("FS=%s BENCH=%s START_SIZE=%zu ITS=%zu PRE_FILL=%zu%% KEEP_FILES=%s CHUNK_SIZE=%zu",
fs_name.c_str(), bench_func.c_str(), start_size, its, fill_level, keep_files ? "y" : "n", chunk_size);
bool print_malloc_stats = std::getenv("PRINT_MALLOC_STATS")
? (std::string(std::getenv("PRINT_MALLOC_STATS")) == "y" ? true : false)
: false;
BenchParams params = {
.bench_func = bench_func,
.prefill = fill_level,
.keep_prefill = keep_files,
.use_snapshot_if_avail = false,
.first_size = start_size,
.its = its,
.keep_files = keep_files,
.read_chunk_size = chunk_size,
.write_chunk_size = chunk_size,
.print_malloc_stats = print_malloc_stats,
};
// set up flash
VirtualNORFlash flash(flash_config);
flash.print_config();
// special benchmark types
bool mount_test = bench_func == "mount_test";
if (mount_test) {
printf("fill_percent, keep, ");
printf("file_size, pages_read, bytes_read, pages_written, bytes_written, sectors_erased, bytes_erased, total_used_pages, total_used_bytes, fs_reports_free\n");
bench = make_bench(fs_name, &flash);
if (fill_level)
bench->fill_fs(fill_level, keep_files);
delete (bench);
flash.reset_statistics();
Generic_Bench *bench2 = make_bench(fs_name, &flash);
printf("%zu, %d, ", fill_level, keep_files);
bench2->post(params);
delete (bench2);
flash.reset();
return 0;
}
bool gc_test = bench_func == "gc";
if (gc_test) {
printf("file_size, pages_read, bytes_read, pages_written, bytes_written, sectors_erased, bytes_erased, total_used_pages, total_used_bytes, fs_reports_free\n");
bench = make_bench(fs_name, &flash);
if (fill_level)
bench->fill_fs(fill_level, keep_files);
params.current_size = start_size;
for (size_t i = 1; i <= its; i++) {
RUN_BENCH_WRAPPED(bench, write_file(0, start_size, ("file" + std::to_string(i)).c_str()), params);
}
delete (bench);
flash.reset();
return 0;
}
// default benchmark structure, for each size:
// mount on fresh flash and prepare -> (reset stats) -> run function once -> (print stats) -> unmount
printf("file_size, pages_read, bytes_read, pages_written, bytes_written, sectors_erased, bytes_erased, total_used_pages, total_used_bytes, fs_reports_free\n");
for (size_t i = 1; i <= its; i++) {
params.current_size = start_size * i;
// Check if we have, and if yes load, a snapshot of the flash with the
// given parameters, which saves some time.
// Must (try to) load snapshot BEFORE mounting
bool snapshot_loaded = flash.load_snapshot(fs_name, fill_level, keep_files);
bench = make_bench(fs_name, &flash);
if (print_malloc_stats)
LOG_INFO("memory (after mount): current: %zu peak: %zu",
mt_current_bytes(), mt_peak_bytes());
if (fill_level && !snapshot_loaded) {
bench->fill_fs(fill_level, keep_files);
flash.take_snapshot(fs_name, fill_level, keep_files);
}
bench->set_write_chunk_size(chunk_size);
// Don't take samples of the file system mount process and
// (de-)initialization, only the benchmark itself
flame_sampler::enable_sampling();
RUN_BENCH_WRAPPED(bench, dispatch(params), params);
flame_sampler::disable_sampling();
delete (bench);
flash.reset();
}
flame_sampler::dump("stacks.folded");
return 0;
}