srs-control
0.2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
AnalysisHandle.cpp
Go to the documentation of this file.
1
#include "
srs/workflow/AnalysisHandle.hpp
"
2
#include "
srs/Application.hpp
"
3
#include "
srs/data/BufferQueue.hpp
"
4
#include "
srs/data/DataStructsFormat.hpp
"
5
#include "
srs/data/LargeBuffer.hpp
"
6
#include "
srs/utils/ExitLogger.hpp
"
7
#include "
srs/workflow/DataMonitor.hpp
"
8
#include "
srs/workflow/FrameMissMonitor.hpp
"
9
#include "
srs/workflow/TaskDiagram.hpp
"
10
#include <asio/any_io_executor.hpp>
11
#include <cassert>
12
#include <chrono>
13
#include <cstddef>
14
#include <cstdint>
15
#include <memory>
16
#include <mutex>
17
#include <spdlog/spdlog.h>
18
19
namespace
srs::workflow
20
{
21
22
AnalysisHandle::AnalysisHandle
(
App
* control, std::size_t n_lines)
23
:
is_data_drop_warn_
{ control->get_config().warn_if_data_drop }
24
,
n_lines_
{ n_lines }
25
,
app_
{ control }
26
,
monitor_
{ this, &(control->get_io_context()) }
27
,
buffer_queue_
{
BufferQueue
{ { .buffer_size =
app_
->get_config().data_buffer_size,
28
.reserve_size = control->
get_config
().buffer_queue_capacity / 2,
29
.queue_capacity = control->
get_config
().buffer_queue_capacity } } }
30
{
31
spdlog::debug(
"Handler: Setting the capacity of the buffer queue to {}"
,
32
control->get_config().buffer_queue_capacity);
33
if
(app_->get_config().enable_frame_counter_check)
34
{
35
writers_.enable_frame_count_checker();
36
}
37
}
38
39
void
AnalysisHandle::print_statistics
()
40
{
41
42
auto
& report =
app_
->get_report();
43
44
task_diagram_
->register_report(report);
45
46
auto
frame_stat =
AppReport::FrameReadingStat
{};
47
48
frame_stat.
total_time_ns
=
total_time_ns_
;
49
frame_stat.total_bytes_read =
total_read_data_bytes_
;
50
frame_stat.n_frames =
total_frame_counts_
;
51
report.register_frame_reading_result(
"Workflow"
, frame_stat);
52
53
buffer_queue_
.register_report(report);
54
}
55
56
void
AnalysisHandle::start
(asio::any_io_executor executor)
57
{
58
auto
_ =
ExitLogger
{};
59
is_stopped_
.store(
false
);
60
task_diagram_
= std::make_unique<TaskDiagram>(*
this
,
n_lines_
);
61
62
const
auto
& app_config =
app_
->get_config();
63
64
const
auto
* frame_count_checker =
writers_
.get_frame_count_checker();
65
if
(app_config.enable_frame_counter_check and frame_count_checker !=
nullptr
)
66
{
67
68
frame_counter_monitor_
= std::make_unique<FrameMissMonitor>(
69
FrameMissMonitor::Config
{ .sample_size = 200, .sample_time_ms = 10 }, *frame_count_checker);
70
frame_counter_monitor_
->launch(executor);
71
}
72
73
if
(
print_mode_
== print_speed)
74
{
75
monitor_
.start();
76
}
77
78
cv_
.notify_all();
79
spdlog::trace(
"Analysis workflow: entering workflow loop"
);
80
81
task_diagram_
->construct_taskflow_and_run(
buffer_queue_
,
is_stopped_
);
82
spdlog::trace(
"Analysis workflow: workflow loop ended"
);
83
}
84
85
AnalysisHandle::~AnalysisHandle
()
86
{
87
// stop();
88
spdlog::debug(
"Analysis workflow: total read data bytes: {} "
,
total_read_data_bytes_
.load());
89
spdlog::debug(
"Analysis workflow: total frame counts: {} "
,
total_frame_counts_
.load());
90
}
91
// DataProcessor::~DataProcessor() = default;
92
93
void
AnalysisHandle::stop_workflow
()
94
{
95
auto
_ =
ExitLogger
{};
96
// stop may be called before start, where the task_diagram_ is constructed. To prevent task_diagram_ to be
97
// nullptr, wait for a condition variable, notified by the start function.
98
auto
lock = std::unique_lock{
cv_mutex_
};
99
cv_
.wait(lock, [
this
]() {
return
task_diagram_
!=
nullptr
; });
100
101
// CAS operation to guarantee the thread safety
102
auto
expected =
false
;
103
spdlog::trace(
"Analysis workflow: trying to stop ... "
);
104
spdlog::trace(
"Analysis workflow: current is_stopped status: {}"
,
is_stopped_
.load());
105
if
(
is_stopped_
.compare_exchange_strong(expected,
true
))
106
{
107
const
auto
_ =
ExitLogger
{
"scope"
};
108
109
while
(not
task_diagram_
->is_taskflow_abort_ready())
110
{
111
// spdlog::trace("waiting for task diagram to be abort ready");
112
}
113
spdlog::trace(
"Analysis workflow: taskflow is ready to abort."
);
114
buffer_queue_
.enqueue_empty(
task_diagram_
->get_n_lines());
115
}
116
}
117
118
auto
AnalysisHandle::get_data_workflow
() const -> const
TaskDiagram
&
119
{
120
assert(
task_diagram_
!=
nullptr
);
121
return
*
task_diagram_
;
122
}
123
124
void
AnalysisHandle::read_data_once
(
LargeBuffer
& read_data,
BufferQueue::Token
& token)
125
{
126
const
auto
data_size = read_data.
get_size
();
127
total_read_data_bytes_
+= data_size;
128
++
total_frame_counts_
;
129
130
time_point_
=
clock_
.now();
131
auto
is_success =
buffer_queue_
.enqueue(read_data, token);
132
total_time_ns_
+=
static_cast<
uint64_t
>
((
clock_
.now() -
time_point_
).count());
133
134
if
(not is_success)
135
{
136
total_drop_data_bytes_
+= data_size;
137
if
(
is_data_drop_warn_
)
138
{
139
spdlog::warn(
"Data drop as the buffer queue is full: Current size/capacity: {}/{}."
,
140
buffer_queue_
.size(),
141
buffer_queue_
.capacity());
142
}
143
}
144
}
145
}
// namespace srs::workflow
AnalysisHandle.hpp
Application.hpp
BufferQueue.hpp
DataMonitor.hpp
DataStructsFormat.hpp
ExitLogger.hpp
FrameMissMonitor.hpp
LargeBuffer.hpp
TaskDiagram.hpp
srs::App
The primary interface class of SRS-Control.
Definition
Application.hpp:82
srs::App::get_config
auto get_config() const -> const auto &
Definition
Application.hpp:208
srs::BufferQueue
Class to manage the production and consumption of LargeBuffer asynchronously.
Definition
BufferQueue.hpp:23
srs::BufferQueue::Token
std::pair< moodycamel::ProducerToken, moodycamel::ConsumerToken > Token
A queue token type used for enqueue and dequeue action. The token type consists of one producer token...
Definition
BufferQueue.hpp:41
srs::ExitLogger
Definition
ExitLogger.hpp:12
srs::LargeBuffer
Class for buffer for storing large data.
Definition
LargeBuffer.hpp:23
srs::LargeBuffer::get_size
auto get_size() const -> std::size_t
Getter for the size.
Definition
LargeBuffer.hpp:122
srs::workflow::AnalysisHandle::total_read_data_bytes_
std::atomic< uint64_t > total_read_data_bytes_
Definition
AnalysisHandle.hpp:98
srs::workflow::AnalysisHandle::total_drop_data_bytes_
std::atomic< uint64_t > total_drop_data_bytes_
Definition
AnalysisHandle.hpp:99
srs::workflow::AnalysisHandle::cv_
std::condition_variable cv_
Definition
AnalysisHandle.hpp:109
srs::workflow::AnalysisHandle::get_data_workflow
auto get_data_workflow() const -> const TaskDiagram &
Definition
AnalysisHandle.cpp:118
srs::workflow::AnalysisHandle::read_data_once
void read_data_once(LargeBuffer &read_data, BufferQueue::Token &token)
Definition
AnalysisHandle.cpp:124
srs::workflow::AnalysisHandle::task_diagram_
std::unique_ptr< TaskDiagram > task_diagram_
Definition
AnalysisHandle.hpp:113
srs::workflow::AnalysisHandle::app_
gsl::not_null< App * > app_
Definition
AnalysisHandle.hpp:102
srs::workflow::AnalysisHandle::start
void start(asio::any_io_executor executor)
Definition
AnalysisHandle.cpp:56
srs::workflow::AnalysisHandle::n_lines_
std::size_t n_lines_
Definition
AnalysisHandle.hpp:94
srs::workflow::AnalysisHandle::buffer_queue_
BufferQueue buffer_queue_
Definition
AnalysisHandle.hpp:112
srs::workflow::AnalysisHandle::is_data_drop_warn_
bool is_data_drop_warn_
Definition
AnalysisHandle.hpp:93
srs::workflow::AnalysisHandle::stop_workflow
void stop_workflow()
Definition
AnalysisHandle.cpp:93
srs::workflow::AnalysisHandle::total_frame_counts_
std::atomic< uint64_t > total_frame_counts_
Definition
AnalysisHandle.hpp:101
srs::workflow::AnalysisHandle::cv_mutex_
std::mutex cv_mutex_
Definition
AnalysisHandle.hpp:108
srs::workflow::AnalysisHandle::total_time_ns_
std::uint64_t total_time_ns_
Definition
AnalysisHandle.hpp:117
srs::workflow::AnalysisHandle::is_stopped_
std::atomic< bool > is_stopped_
Definition
AnalysisHandle.hpp:95
srs::workflow::AnalysisHandle::monitor_
DataMonitor monitor_
Definition
AnalysisHandle.hpp:104
srs::workflow::AnalysisHandle::writers_
sink::Manager writers_
Definition
AnalysisHandle.hpp:103
srs::workflow::AnalysisHandle::AnalysisHandle
AnalysisHandle(App *control, std::size_t n_lines=1)
Definition
AnalysisHandle.cpp:22
srs::workflow::AnalysisHandle::print_mode_
common::DataPrintMode print_mode_
Definition
AnalysisHandle.hpp:97
srs::workflow::AnalysisHandle::clock_
std::chrono::steady_clock clock_
Definition
AnalysisHandle.hpp:115
srs::workflow::AnalysisHandle::frame_counter_monitor_
std::unique_ptr< FrameMissMonitor > frame_counter_monitor_
Definition
AnalysisHandle.hpp:105
srs::workflow::AnalysisHandle::print_statistics
void print_statistics()
Definition
AnalysisHandle.cpp:39
srs::workflow::AnalysisHandle::time_point_
std::chrono::time_point< std::chrono::steady_clock, std::chrono::nanoseconds > time_point_
Definition
AnalysisHandle.hpp:116
srs::workflow::AnalysisHandle::~AnalysisHandle
~AnalysisHandle()
Definition
AnalysisHandle.cpp:85
srs::workflow::TaskDiagram
Class for analysis taskflow.
Definition
TaskDiagram.hpp:35
srs::workflow
Definition
Application.hpp:29
srs::AppReport::FrameReadingStat
Definition
AppReport.hpp:34
srs::AppReport::FrameReadingStat::total_time_ns
std::size_t total_time_ns
Definition
AppReport.hpp:36
srs::workflow::FrameMissMonitor::Config
Definition
FrameMissMonitor.hpp:28
backend
srs
workflow
AnalysisHandle.cpp
Impressum
Datenschutzerklärung
Generated by
1.17.0