1 #include "usdt_sample_lib1/lib1.h"
10 #include "folly/tracing/StaticTracepoint.h"
12 // When using systemtap-sdt-devel, the following file should be included:
13 // #include "usdt_sample_lib1/lib1_sdt.h"
15 OperationRequest::OperationRequest(const std::string& input_)
20 OperationResponse::OperationResponse(const std::string& output_)
25 OperationProvider::OperationProvider(std::uint32_t minLatencyMs_, std::uint32_t maxLatencyMs_)
26 : _gen(std::random_device()())
27 , _dis(minLatencyMs_, maxLatencyMs_)
31 std::shared_future<OperationResponse> OperationProvider::executeAsync(const OperationRequest& request)
33 static std::atomic<std::uint64_t> operationIdCounter(0);
34 std::uint64_t operationId = operationIdCounter++;
36 FOLLY_SDT(usdt_sample_lib1, operation_start, operationId, request.input().c_str());
38 /* Below an example of how to use this sample with systemtap-sdt-devel:
39 if (USDT_SAMPLE_LIB1_OPERATION_START_ENABLED()) {
40 //std::cout << "operation_start probe enabled." << std::endl;
41 USDT_SAMPLE_LIB1_OPERATION_START(operationId, &inputBuf);
45 auto latencyMs = _dis(_gen);
47 return std::async(std::launch::async, [latencyMs, operationId, request]() {
48 std::this_thread::sleep_for(std::chrono::milliseconds(latencyMs));
50 auto output = std::string("resp_") + request.input();
51 OperationResponse response(output);
53 FOLLY_SDT(usdt_sample_lib1, operation_end, operationId, response.output().c_str());
55 /* Below an example of how to use this sample with systemtap-sdt-devel:
56 if (USDT_SAMPLE_LIB1_OPERATION_END_ENABLED()) {
57 //std::cout << "operation_end probe enabled." << std::endl;
58 USDT_SAMPLE_LIB1_OPERATION_END(operationId, &outputBuf);