perf_test.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2012 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. #ifndef TEST_TESTSUPPORT_PERF_TEST_H_
  11. #define TEST_TESTSUPPORT_PERF_TEST_H_
  12. #include <sstream>
  13. #include <string>
  14. #include <vector>
  15. #include "api/array_view.h"
  16. #include "api/numerics/samples_stats_counter.h"
  17. namespace webrtc {
  18. namespace test {
  19. enum class ImproveDirection {
  20. // Direction is undefined.
  21. kNone,
  22. // Smaller value is better.
  23. kSmallerIsBetter,
  24. // Bigger value is better.
  25. kBiggerIsBetter,
  26. };
  27. // Prints a performance test result.
  28. //
  29. // For example,
  30. // PrintResult("ramp_up_time_", "turn_over_tcp",
  31. // "bwe_15s", 1234.2, "ms", false);
  32. //
  33. // will show up in the http://chromeperf.appspot.com under
  34. //
  35. // (test binary name) > (bot) > ramp_up_time_turn_over_tcp > bwe_15s.
  36. //
  37. // The |measurement| + |modifier| is what we're measuring. |user_story| is the
  38. // scenario we're testing under.
  39. //
  40. // The binary this runs in must be hooked up as a perf test in the WebRTC
  41. // recipes for this to actually be uploaded to chromeperf.appspot.com.
  42. void PrintResult(const std::string& measurement,
  43. const std::string& modifier,
  44. const std::string& user_story,
  45. const double value,
  46. const std::string& units,
  47. bool important,
  48. ImproveDirection improve_direction = ImproveDirection::kNone);
  49. // Like PrintResult(), but prints a (mean, standard deviation) result pair.
  50. // The |<values>| should be two comma-separated numbers, the mean and
  51. // standard deviation (or other error metric) of the measurement.
  52. // DEPRECATED: soon unsupported.
  53. void PrintResultMeanAndError(
  54. const std::string& measurement,
  55. const std::string& modifier,
  56. const std::string& user_story,
  57. const double mean,
  58. const double error,
  59. const std::string& units,
  60. bool important,
  61. ImproveDirection improve_direction = ImproveDirection::kNone);
  62. // Like PrintResult(), but prints an entire list of results. The |values|
  63. // will generally be a list of comma-separated numbers. A typical
  64. // post-processing step might produce plots of their mean and standard
  65. // deviation.
  66. void PrintResultList(
  67. const std::string& measurement,
  68. const std::string& modifier,
  69. const std::string& user_story,
  70. rtc::ArrayView<const double> values,
  71. const std::string& units,
  72. bool important,
  73. ImproveDirection improve_direction = ImproveDirection::kNone);
  74. // Like PrintResult(), but prints a (mean, standard deviation) from stats
  75. // counter. Also add specified metric to the plotable metrics output.
  76. void PrintResult(const std::string& measurement,
  77. const std::string& modifier,
  78. const std::string& user_story,
  79. const SamplesStatsCounter& counter,
  80. const std::string& units,
  81. const bool important,
  82. ImproveDirection improve_direction = ImproveDirection::kNone);
  83. // Returns a string-encoded proto as described in
  84. // tracing/tracing/proto/histogram.proto in
  85. // https://github.com/catapult-project/catapult/blob/master/.
  86. // If you want to print the proto in human readable format, use
  87. // tracing/bin/proto2json from third_party/catapult in your WebRTC checkout.
  88. std::string GetPerfResults();
  89. // Print into stdout plottable metrics for further post processing.
  90. // |desired_graphs| - list of metrics, that should be plotted. If empty - all
  91. // available metrics will be plotted. If some of |desired_graphs| are missing
  92. // they will be skipped.
  93. void PrintPlottableResults(const std::vector<std::string>& desired_graphs);
  94. // Call GetPerfResults() and write its output to a file. Returns false if we
  95. // failed to write to the file. If you want to print the proto in human readable
  96. // format, use tracing/bin/proto2json from third_party/catapult in your WebRTC
  97. // checkout.
  98. bool WritePerfResults(const std::string& output_path);
  99. // By default, human-readable perf results are printed to stdout. Set the FILE*
  100. // to where they should be printing instead. These results are not used to
  101. // upload to the dashboard, however - this is only through WritePerfResults.
  102. void SetPerfResultsOutput(FILE* output);
  103. // Only for use by tests.
  104. void ClearPerfResults();
  105. } // namespace test
  106. } // namespace webrtc
  107. #endif // TEST_TESTSUPPORT_PERF_TEST_H_