MCPcopy Create free account
hub / github.com/apache/brpc / expose

Method expose

src/bvar/latency_recorder.cpp:191–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191int LatencyRecorder::expose(const butil::StringPiece& prefix1,
192 const butil::StringPiece& prefix2) {
193 if (prefix2.empty()) {
194 LOG(ERROR) << "Parameter[prefix2] is empty";
195 return -1;
196 }
197 butil::StringPiece prefix = prefix2;
198 // User may add "_latency" as the suffix, remove it.
199 if (prefix.ends_with("latency") || prefix.ends_with("Latency")) {
200 prefix.remove_suffix(7);
201 if (prefix.empty()) {
202 LOG(ERROR) << "Invalid prefix2=" << prefix2;
203 return -1;
204 }
205 }
206 std::string tmp;
207 if (!prefix1.empty()) {
208 tmp.reserve(prefix1.size() + prefix.size() + 1);
209 tmp.append(prefix1.data(), prefix1.size());
210 tmp.push_back('_'); // prefix1 ending with _ is good.
211 tmp.append(prefix.data(), prefix.size());
212 prefix = tmp;
213 }
214
215 // set debug names for printing helpful error log.
216 _latency.set_debug_name(prefix);
217 _latency_percentile.set_debug_name(prefix);
218
219 if (_latency_window.expose_as(prefix, "latency") != 0) {
220 return -1;
221 }
222 if (_max_latency_window.expose_as(prefix, "max_latency") != 0) {
223 return -1;
224 }
225 if (_count.expose_as(prefix, "count") != 0) {
226 return -1;
227 }
228 if (_qps.expose_as(prefix, "qps") != 0) {
229 return -1;
230 }
231 char namebuf[32];
232 snprintf(namebuf, sizeof(namebuf), "latency_%d", (int)FLAGS_bvar_latency_p1);
233 if (_latency_p1.expose_as(prefix, namebuf, DISPLAY_ON_PLAIN_TEXT) != 0) {
234 return -1;
235 }
236 snprintf(namebuf, sizeof(namebuf), "latency_%d", (int)FLAGS_bvar_latency_p2);
237 if (_latency_p2.expose_as(prefix, namebuf, DISPLAY_ON_PLAIN_TEXT) != 0) {
238 return -1;
239 }
240 snprintf(namebuf, sizeof(namebuf), "latency_%u", (int)FLAGS_bvar_latency_p3);
241 if (_latency_p3.expose_as(prefix, namebuf, DISPLAY_ON_PLAIN_TEXT) != 0) {
242 return -1;
243 }
244 if (_latency_999.expose_as(prefix, "latency_999", DISPLAY_ON_PLAIN_TEXT) != 0) {
245 return -1;
246 }
247 if (_latency_9999.expose_as(prefix, "latency_9999") != 0) {
248 return -1;

Callers

nothing calls this directly

Calls 12

snprintfFunction · 0.85
ends_withMethod · 0.80
remove_suffixMethod · 0.80
emptyMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45
set_debug_nameMethod · 0.45
expose_asMethod · 0.45
set_vector_namesMethod · 0.45

Tested by

no test coverage detected