This repository has been archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbm_msg_forward.cc
89 lines (67 loc) · 2.53 KB
/
bm_msg_forward.cc
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
#include <chrono>
#include <iostream>
#include <thread>
#include <gnuradio/blocks/msg_forward.h>
#include <gnuradio/flowgraph.h>
#include <gnuradio/realtime.h>
#include <gnuradio/runtime.h>
#include <pmtf/base.hpp>
#include <iostream>
#include "CLI/App.hpp"
#include "CLI/Config.hpp"
#include "CLI/Formatter.hpp"
using namespace gr;
int main(int argc, char* argv[])
{
uint64_t samples = 10000;
uint64_t pdu_size = 100;
unsigned int nblocks = 40;
bool rt_prio = false;
std::vector<unsigned int> cpu_affinity;
CLI::App app{ "App description" };
// app.add_option("-h,--help", "display help");
app.add_option("--samples", samples, "Number of Bursts");
app.add_option("--pdu_size", pdu_size, "PDU Size");
app.add_option("--nblocks", nblocks, "Number of copy blocks");
app.add_flag("--rt_prio", rt_prio, "Enable Real-time priority");
app.add_option("--cpus",
cpu_affinity,
"Pin threads to CPUs (if nthreads > 0, will pin to 0,1,..,N");
CLI11_PARSE(app, argc, argv);
if (rt_prio && gr::enable_realtime_scheduling() != RT_OK) {
std::cout << "Error: failed to enable real-time scheduling." << std::endl;
}
{
std::vector<blocks::msg_forward::sptr> msg_blks(nblocks);
for (size_t i = 0; i < nblocks; i++) {
if (i == nblocks - 1)
msg_blks[i] = blocks::msg_forward::make({ samples });
else
msg_blks[i] = blocks::msg_forward::make({ 0 });
}
flowgraph_sptr fg(new flowgraph());
for (size_t i = 1; i < nblocks; i++) {
fg->connect(msg_blks[i - 1], "out", msg_blks[i], "in");
}
auto rt = runtime::make();
rt->initialize(fg);
for (size_t p = 0; p < samples; p++) {
pmtf::pmt msg = pmtf::vector<uint8_t>(pdu_size, 0x42);
msg_blks[0]->input_message_port("in")->post(msg);
}
// msg_blks[0]->input_message_port("system")->post("done");
// std::this_thread::sleep_for(std::chrono::seconds(3));
auto t1 = std::chrono::steady_clock::now();
rt->start();
rt->wait();
auto t2 = std::chrono::steady_clock::now();
auto time =
std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count() / 1e9;
std::cout << "[PROFILE_TIME]" << time << "[PROFILE_TIME]" << std::endl;
// for (auto& b : msg_blks)
// {
// std::cout << b->message_count() << ", ";
// }
// std::cout << std::endl;
}
}