tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

neteq_stats_plotter.cc (5366B)


      1 /*
      2 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "modules/audio_coding/neteq/tools/neteq_stats_plotter.h"
     12 
     13 #include <algorithm>
     14 #include <cinttypes>
     15 #include <cstdint>
     16 #include <cstdio>
     17 #include <memory>
     18 #include <utility>
     19 
     20 #include "absl/strings/string_view.h"
     21 #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
     22 #include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
     23 
     24 namespace webrtc {
     25 namespace test {
     26 
     27 NetEqStatsPlotter::NetEqStatsPlotter(bool make_matlab_plot,
     28                                     bool make_python_plot,
     29                                     bool show_concealment_events,
     30                                     absl::string_view base_file_name)
     31    : make_matlab_plot_(make_matlab_plot),
     32      make_python_plot_(make_python_plot),
     33      show_concealment_events_(show_concealment_events),
     34      base_file_name_(base_file_name) {
     35  std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
     36  if (make_matlab_plot || make_python_plot) {
     37    delay_analyzer.reset(new NetEqDelayAnalyzer);
     38  }
     39  stats_getter_.reset(new NetEqStatsGetter(std::move(delay_analyzer)));
     40 }
     41 
     42 void NetEqStatsPlotter::SimulationEnded(int64_t simulation_time_ms) {
     43  if (make_matlab_plot_) {
     44    auto matlab_script_name = base_file_name_;
     45    std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
     46                 '_');
     47    printf("Creating Matlab plot script %s.m\n", matlab_script_name.c_str());
     48    stats_getter_->delay_analyzer()->CreateMatlabScript(matlab_script_name +
     49                                                        ".m");
     50  }
     51  if (make_python_plot_) {
     52    auto python_script_name = base_file_name_;
     53    std::replace(python_script_name.begin(), python_script_name.end(), '.',
     54                 '_');
     55    printf("Creating Python plot script %s.py\n", python_script_name.c_str());
     56    stats_getter_->delay_analyzer()->CreatePythonScript(python_script_name +
     57                                                        ".py");
     58  }
     59 
     60  printf("Simulation statistics:\n");
     61  printf("  output duration: %" PRId64 " ms\n", simulation_time_ms);
     62  auto stats = stats_getter_->AverageStats();
     63  printf("  packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate);
     64  printf("  expand_rate: %f %%\n", 100.0 * stats.expand_rate);
     65  printf("  speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate);
     66  printf("  preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate);
     67  printf("  accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate);
     68  printf("  secondary_decoded_rate: %f %%\n",
     69         100.0 * stats.secondary_decoded_rate);
     70  printf("  secondary_discarded_rate: %f %%\n",
     71         100.0 * stats.secondary_discarded_rate);
     72  printf("  clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm);
     73  printf("  mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms);
     74  printf("  median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms);
     75  printf("  min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms);
     76  printf("  max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms);
     77  printf("  current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms);
     78  printf("  preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms);
     79  if (show_concealment_events_) {
     80    printf(" concealment_events_ms:\n");
     81    for (auto concealment_event : stats_getter_->concealment_events())
     82      printf("%s\n", concealment_event.ToString().c_str());
     83    printf(" end of concealment_events_ms\n");
     84  }
     85 
     86  const auto lifetime_stats_vector = stats_getter_->lifetime_stats();
     87  if (!lifetime_stats_vector->empty()) {
     88    auto lifetime_stats = lifetime_stats_vector->back().second;
     89    printf("  total_samples_received: %" PRIu64 "\n",
     90           lifetime_stats.total_samples_received);
     91    printf("  concealed_samples: %" PRIu64 "\n",
     92           lifetime_stats.concealed_samples);
     93    printf("  concealment_events: %" PRIu64 "\n",
     94           lifetime_stats.concealment_events);
     95    printf("  delayed_packet_outage_samples: %" PRIu64 "\n",
     96           lifetime_stats.delayed_packet_outage_samples);
     97    printf("  delayed_packet_outage_events: %" PRIu64 "\n",
     98           lifetime_stats.delayed_packet_outage_events);
     99    printf("  num_interruptions: %d\n", lifetime_stats.interruption_count);
    100    printf("  sum_interruption_length_ms: %d ms\n",
    101           lifetime_stats.total_interruption_duration_ms);
    102    printf("  interruption_ratio: %f\n",
    103           static_cast<double>(lifetime_stats.total_interruption_duration_ms) /
    104               simulation_time_ms);
    105    printf("  removed_samples_for_acceleration: %" PRIu64 "\n",
    106           lifetime_stats.removed_samples_for_acceleration);
    107    printf("  inserted_samples_for_deceleration: %" PRIu64 "\n",
    108           lifetime_stats.inserted_samples_for_deceleration);
    109    printf("  generated_noise_samples: %" PRIu64 "\n",
    110           lifetime_stats.generated_noise_samples);
    111    printf("  packets_discarded: %" PRIu64 "\n",
    112           lifetime_stats.packets_discarded);
    113  }
    114 }
    115 
    116 }  // namespace test
    117 }  // namespace webrtc