Skip to content

Commit

Permalink
add "time until tx" as a stat
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 24, 2023
1 parent 9553564 commit 56b8481
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/HelperSources/TimeHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ static std::string min_max_avg_as_string(const MinMaxAvg<T>& minMaxAvg,bool aver
}
return ss.str();
}
static MinMaxAvg<uint32_t> min_max_avg_as_us(const MinMaxAvg<std::chrono::nanoseconds>& minMaxAvg){
const uint32_t min=std::chrono::duration_cast<std::chrono::microseconds>(minMaxAvg.min).count();
const uint32_t max=std::chrono::duration_cast<std::chrono::microseconds>(minMaxAvg.max).count();
const uint32_t avg=std::chrono::duration_cast<std::chrono::microseconds>(minMaxAvg.avg).count();
return {min,max,avg};
}

// Use this class to compare many samples of the same kind
// Saves the minimum,maximum and average of all the samples
Expand Down
17 changes: 11 additions & 6 deletions src/WBStreamTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ WBStreamTx::Statistics WBStreamTx::get_latest_stats() {
ret.n_dropped_frames=m_n_dropped_frames;
ret.current_injected_packets_per_second=m_packets_per_second_calculator.get_last_or_recalculate(
m_n_injected_packets,std::chrono::seconds(2));
ret.curr_block_until_tx_min_us=m_curr_block_until_tx_min_max_avg_us.min;
ret.curr_block_until_tx_max_us=m_curr_block_until_tx_min_max_avg_us.max;
ret.curr_block_until_tx_avg_us=m_curr_block_until_tx_min_max_avg_us.avg;
return ret;
}

Expand All @@ -120,9 +123,10 @@ void WBStreamTx::loop_process_data() {
}
static constexpr std::int64_t timeout_usecs=100*1000;
if(options.enable_fec){
std::shared_ptr<EnqueuedBlock> frame;
std::shared_ptr<EnqueuedBlock> frame= nullptr;
while (m_process_data_thread_run){
if(m_block_queue->wait_dequeue_timed(frame,timeout_usecs)){
// dequeued frame
m_queue_time_calculator.add(std::chrono::steady_clock::now()-frame->enqueue_time_point);
if(m_queue_time_calculator.get_delta_since_last_reset()>std::chrono::seconds(1)){
if(options.log_time_spent_in_atomic_queue){
Expand All @@ -131,13 +135,14 @@ void WBStreamTx::loop_process_data() {
m_queue_time_calculator.reset();
}
process_enqueued_block(*frame);
if(options.log_time_blocks_until_tx){
const auto delta=std::chrono::steady_clock::now()-frame->enqueue_time_point;
m_block_until_tx_time.add(delta);
if(m_block_until_tx_time.get_delta_since_last_reset()>std::chrono::seconds(2)){
const auto delta=std::chrono::steady_clock::now()-frame->enqueue_time_point;
m_block_until_tx_time.add(delta);
if(m_block_until_tx_time.get_delta_since_last_reset()>std::chrono::seconds(2)){
if(options.log_time_blocks_until_tx){
m_console->debug("Time until tx {}",m_block_until_tx_time.getAvgReadable());
m_block_until_tx_time.reset();
}
m_curr_block_until_tx_min_max_avg_us= min_max_avg_as_us(m_block_until_tx_time.getMinMaxAvg());
m_block_until_tx_time.reset();
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/WBStreamTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class WBStreamTx {
// In FEC mode (video), every time a frame is dropped this is increased by the n of fragments in this frame
uint64_t n_dropped_packets;
int32_t n_dropped_frames;
// only for frame (FEC) mode
uint32_t curr_block_until_tx_min_us;
uint32_t curr_block_until_tx_max_us;
uint32_t curr_block_until_tx_avg_us;
};
Statistics get_latest_stats();
// only valid when actually doing FEC
Expand Down Expand Up @@ -136,6 +140,7 @@ class WBStreamTx {
// Time fragments / blocks spend in the non-blocking atomic queue.
AvgCalculator m_queue_time_calculator;
AvgCalculator m_block_until_tx_time;
MinMaxAvg<uint32_t> m_curr_block_until_tx_min_max_avg_us{0,0,0};
// n of packets fed to the instance
int64_t m_n_input_packets = 0;
// count of bytes we got passed (aka for example, what the video encoder produced - does not include FEC)
Expand Down

0 comments on commit 56b8481

Please sign in to comment.