forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib1.cpp
More file actions
64 lines (49 loc) · 1.9 KB
/
lib1.cpp
File metadata and controls
64 lines (49 loc) · 1.9 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
#include "usdt_sample_lib1/lib1.h"
// std
#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>
// usdt_sample_lib1
#include "folly/tracing/StaticTracepoint.h"
// When using systemtap-sdt-devel, the following file should be included:
// #include "usdt_sample_lib1/lib1_sdt.h"
OperationRequest::OperationRequest(const std::string& input_)
: _input(input_)
{
}
OperationResponse::OperationResponse(const std::string& output_)
: _output(output_)
{
}
OperationProvider::OperationProvider(std::uint32_t minLatencyMs_, std::uint32_t maxLatencyMs_)
: _gen(std::random_device()())
, _dis(minLatencyMs_, maxLatencyMs_)
{
}
std::shared_future<OperationResponse> OperationProvider::executeAsync(const OperationRequest& request)
{
static std::atomic<std::uint64_t> operationIdCounter(0);
std::uint64_t operationId = operationIdCounter++;
FOLLY_SDT(usdt_sample_lib1, operation_start, operationId, request.input().c_str());
/* Below an example of how to use this sample with systemtap-sdt-devel:
if (USDT_SAMPLE_LIB1_OPERATION_START_ENABLED()) {
//std::cout << "operation_start probe enabled." << std::endl;
USDT_SAMPLE_LIB1_OPERATION_START(operationId, &inputBuf);
}
*/
auto latencyMs = _dis(_gen);
return std::async(std::launch::async, [latencyMs, operationId, request]() {
std::this_thread::sleep_for(std::chrono::milliseconds(latencyMs));
auto output = std::string("resp_") + request.input();
OperationResponse response(output);
FOLLY_SDT(usdt_sample_lib1, operation_end, operationId, response.output().c_str());
/* Below an example of how to use this sample with systemtap-sdt-devel:
if (USDT_SAMPLE_LIB1_OPERATION_END_ENABLED()) {
//std::cout << "operation_end probe enabled." << std::endl;
USDT_SAMPLE_LIB1_OPERATION_END(operationId, &outputBuf);
}
*/
return response;
});
}