MCPcopy Create free account
hub / github.com/ceph/ceph / BM_KeyRing_RandomRead

Function BM_KeyRing_RandomRead

src/test/bench_secmem.cc:131–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131void
132BM_KeyRing_RandomRead(benchmark::State& state)
133{
134 const std::string secret(SECRET_SIZE, '$');
135 static std::vector<key_serial_t> serials;
136 static std::random_device rd;
137 static std::mt19937 gen(rd());
138 static std::uniform_int_distribution<size_t> dis(0, state.range(0) - 1);
139 if (state.thread_index() == 0) {
140 for (size_t i = 0; i < static_cast<size_t>(state.range(0)); ++i) {
141 const key_serial_t serial = ::add_key(
142 "user", std::to_string(i).c_str(), secret.c_str(), secret.size(),
143 KEY_SPEC_PROCESS_KEYRING);
144 if (serial == -1) {
145 state.SkipWithError(
146 std::format(
147 "serial:{} i:{} errno:{} err:{}", serial, i, errno,
148 std::strerror(errno)));
149 return;
150 }
151 serials.push_back(serial);
152 }
153 }
154 for (auto _ : state) {
155 const size_t keys_to_read = state.range(1) / state.threads();
156 thread_local size_t bytes_read = 0;
157 for (size_t i = 0; i < keys_to_read; ++i) {
158 const key_serial_t serial = serials[dis(gen)];
159 std::string out(secret.size(), '$');
160 const auto ret = ::keyctl_read(serial, out.data(), out.size());
161 if (ret < 0) {
162 state.SkipWithError("keyctl_read");
163 return;
164 }
165 bytes_read += ret;
166 }
167 state.counters["BytesRead"] = benchmark::Counter(
168 static_cast<double>(bytes_read), benchmark::Counter::kIsRate);
169 state.counters["KeysRead"] = benchmark::Counter(
170 static_cast<double>(keys_to_read), benchmark::Counter::kIsRate);
171 state.counters["KeysReadInv"] = benchmark::Counter(
172 static_cast<double>(keys_to_read),
173 benchmark::Counter::kIsRate | benchmark::Counter::kInvert);
174 }
175 if (state.thread_index() == 0) {
176 }
177}
178
179void
180BM_KeyRing_WriteReadRemove(benchmark::State& state)

Callers

nothing calls this directly

Calls 7

to_stringFunction · 0.50
formatFunction · 0.50
CounterClass · 0.50
c_strMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected