Skip to content

Commit

Permalink
[audio_engine] refine Profiler and dump csv format
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-ray committed Nov 19, 2018
1 parent acb6bdb commit 998b224
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 80 deletions.
2 changes: 1 addition & 1 deletion client_essential/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ ReturnType Worker::syncStart(std::function<void(const NetworkState &newState, co
}
case NetPacket::PayloadType::AudioMessage: {
decodeOpusAndAecBufferFarend(netPacket);
Profiler::get().arrivalAudioOffset_.addData(
Profiler::get().packageDelayList_.addData(
(int32_t)(ProcessTime::get().getProcessUptime()) -
(int32_t)(netPacket.timestamp())
);
Expand Down
104 changes: 26 additions & 78 deletions include/evc/Profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@




template <typename T>
class DataDumper {
class EventList{
private:
const std::string fileName_;
const char *tag_ = nullptr;
std::vector<std::tuple<uint32_t, T>> list_; // {uptime, delay}
std::ofstream ofs_;
public:
DataDumper(const std::string fileName)
: fileName_(fileName)
{
ofs_.open(fileName_);
EventList(const char *tag) : tag_(tag) {
ofs_.open(tag);
}
void addData(const T &data) {
list_.push_back({ProcessTime::get().getProcessUptime(),data});
}

void dump(const std::vector<T> data) {
for (const auto &v : data) {
ofs_ << v << std::endl;
/// CSV format
void dump() {
LOGI << "dump_to: " << tag_;
for (const auto &v : list_) {
ofs_ << std::get<0>(v) << ", " << std::get<1>(v) << std::endl;
}
}
};


/* TODO
statistics media data
- packet order
- arrival time's Evenness
-
*/


/// DEPRECATED....
/// try to dump data and analyze off-line
#if 0
class Statistician {
private:
std::vector<int32_t> durationList;
Expand Down Expand Up @@ -80,76 +81,23 @@ class Statistician {

return result_;
}

};


class Timer {
private:
Statistician *stat_ = nullptr;
decltype(std::chrono::system_clock::now()) startPoint_;
public:
Timer(Statistician *stat)
: stat_(stat)
{
startPoint_ = std::chrono::system_clock::now();
}

~Timer() {
auto dur = static_cast<int32_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - startPoint_).count());
if (stat_) {
stat_->addData(dur);
}
}
};



class TimestampMarker {
using _TS = decltype(ProcessTime::get().getProcessUptime());
private:
const char *tag_ = nullptr;
std::vector<_TS> tsList_;
public:
TimestampMarker(const char *tag) : tag_(tag) {}
void dump(){
try {
LOGI << calc();
DataDumper<_TS> dumper(tag_);
dumper.dump(tsList_);
}
catch (const std::exception &e){
LOGE_STD_EXCEPTION(e);
}
}
void mark(const _TS &ts= ProcessTime::get().getProcessUptime()) { tsList_.push_back(ts); }
private:
std::string calc() {
if (tsList_.empty()) {
return "list is empty";
}
std::string result_ = "{@tag [min,max]#nbElements}";
const auto &v = tsList_;
auto nbElements = v.size();
auto minV = *std::min_element(std::begin(v), std::end(v));
auto maxV = *std::max_element(std::begin(v), std::end(v));
result_ = result_ + "\t{@" + tag_ + "[" + std::to_string(minV) + "," + std::to_string(maxV) + "]#" + std::to_string(nbElements) + "}";
return result_;
}
};
#endif


class Profiler : public Singleton<Profiler> {
public:
Statistician arrivalAudioOffset_;
TimestampMarker emptyAudioOutBufferTS_;
//Statistician arrivalAudioOffset_;
EventList<int32_t> packageDelayList_;
EventList<bool> emptyAudioOutBuffer_;
public:
Profiler()
: arrivalAudioOffset_("arrivalOffset(ms)")
, emptyAudioOutBufferTS_("emptyBufferTS(uptime, ms)")
: packageDelayList_("packageDelayList_.csv")
, emptyAudioOutBuffer_("emptyBuffer_.csv")
{ }

void dump() {
arrivalAudioOffset_.dump();
emptyAudioOutBufferTS_.dump();
packageDelayList_.dump();
emptyAudioOutBuffer_.dump();
}
};
4 changes: 3 additions & 1 deletion include/evc/Worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ enum class NetworkState : unsigned char{
TODO
- Packet loss compensation
- cross fading for PLC
- store encoded package?
- Timestamp information should be stored
// https://www.boost.org/doc/libs/1_67_0/doc/html/boost/lockfree/spsc_queue.html ?
*/
class AudioOutBuffer {
Expand Down Expand Up @@ -88,7 +90,7 @@ class AudioOutBuffer {
std::memcpy((void*)outData, (void*)data.data(), sizeof(int16_t)*blockSize);
}
else {
Profiler::get().emptyAudioOutBufferTS_.mark();
Profiler::get().emptyAudioOutBuffer_.addData(true);
std::memcpy((char*)outData, (char*)emptyBuffer_.data(), emptyBuffer_.size() * sizeof(int16_t));
}

Expand Down

0 comments on commit 998b224

Please sign in to comment.