Skip to content

Commit

Permalink
Also instrument updating ring buffer index
Browse files Browse the repository at this point in the history
  • Loading branch information
shermp committed Aug 10, 2024
1 parent fcbe712 commit 6a9887d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/asha_audio.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "asha_audio.hpp"
#ifdef ASHA_PERF_METRICS
#include "perf_metrics.hpp"
#endif

namespace asha
{
Expand Down Expand Up @@ -73,6 +76,9 @@ void AudioBuffer::encode_1ms_audio(int16_t* stereo_pcm)
++w_index;
++seq_num;
write_index = w_index;
#ifdef ASHA_PERF_METRICS
perf_metrics.add_w_index_changed(get_absolute_time());
#endif
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/perf_metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace asha

constexpr ssize_t metrics_vector_size = 1 * 1024;
struct PerfMetrics {
std::vector<absolute_time_t> w_index_changed;
std::vector<absolute_time_t> index_changed;
std::vector<absolute_time_t> send_left;
std::vector<absolute_time_t> sent_left;
Expand All @@ -18,13 +19,15 @@ struct PerfMetrics {

PerfMetrics()
{
w_index_changed.reserve(metrics_vector_size);
index_changed.reserve(metrics_vector_size);
send_left.reserve(metrics_vector_size);
sent_left.reserve(metrics_vector_size);
send_right.reserve(metrics_vector_size);
sent_right.reserve(metrics_vector_size);
}

void add_w_index_changed(absolute_time_t t) {if (w_index_changed.size() < metrics_vector_size) w_index_changed.push_back(t);}
void add_index_changed(absolute_time_t t) {if (index_changed.size() < metrics_vector_size) index_changed.push_back(t);}
void add_send_left(absolute_time_t t) {if (send_left.size() < metrics_vector_size) send_left.push_back(t);}
void add_sent_left(absolute_time_t t) {if (sent_left.size() < metrics_vector_size) sent_left.push_back(t);}
Expand All @@ -33,7 +36,8 @@ struct PerfMetrics {

bool should_dump_metrics()
{
return index_changed.size() >= metrics_vector_size; //||
return w_index_changed.size() >= metrics_vector_size ||
index_changed.size() >= metrics_vector_size ||
send_left.size() >= metrics_vector_size ||
sent_left.size() >= metrics_vector_size ||
send_right.size() >= metrics_vector_size ||
Expand All @@ -45,14 +49,15 @@ struct PerfMetrics {
// printf("%llu,", t);
// }
// printf("\n");
printf("index_changed,send_left,sent_left,send_right,sent_right\n");
printf("w_index_changed,index_changed,send_left,sent_left,send_right,sent_right\n");
for (size_t i = 0; i < metrics_vector_size; ++i) {
absolute_time_t w_index = (i < w_index_changed.size()) ? w_index_changed[i] : 0;
absolute_time_t index = (i < index_changed.size()) ? index_changed[i] : 0;
absolute_time_t send_left_packet = (i < send_left.size()) ? send_left[i] : 0;
absolute_time_t sent_left_packet = (i < sent_left.size()) ? sent_left[i] : 0;
absolute_time_t send_right_packet = (i < send_right.size()) ? send_right[i] : 0;
absolute_time_t sent_rightpacket = (i < sent_right.size()) ? sent_right[i] : 0;
printf("%llu,%llu,%llu,%llu,%llu\n", index, send_left_packet, sent_left_packet, send_right_packet, sent_rightpacket);
printf("%llu,%llu,%llu,%llu,%llu,%llu\n", w_index, index, send_left_packet, sent_left_packet, send_right_packet, sent_rightpacket);
}
}
};
Expand Down

0 comments on commit 6a9887d

Please sign in to comment.