153a5a1b3Sopenharmony_ci/*** 253a5a1b3Sopenharmony_ci This file is part of PulseAudio. 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 553a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 653a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 753a5a1b3Sopenharmony_ci or (at your option) any later version. 853a5a1b3Sopenharmony_ci 953a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1053a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1153a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1253a5a1b3Sopenharmony_ci General Public License for more details. 1353a5a1b3Sopenharmony_ci***/ 1453a5a1b3Sopenharmony_ci 1553a5a1b3Sopenharmony_ci#ifndef fooruntimetestutilhfoo 1653a5a1b3Sopenharmony_ci#define fooruntimetestutilhfoo 1753a5a1b3Sopenharmony_ci 1853a5a1b3Sopenharmony_ci#ifdef HAVE_CONFIG_H 1953a5a1b3Sopenharmony_ci#include <config.h> 2053a5a1b3Sopenharmony_ci#endif 2153a5a1b3Sopenharmony_ci 2253a5a1b3Sopenharmony_ci#include <math.h> 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2553a5a1b3Sopenharmony_ci#include <pulse/rtclock.h> 2653a5a1b3Sopenharmony_ci 2753a5a1b3Sopenharmony_ci#define PA_RUNTIME_TEST_RUN_START(l, t1, t2) \ 2853a5a1b3Sopenharmony_ci{ \ 2953a5a1b3Sopenharmony_ci int _j, _k; \ 3053a5a1b3Sopenharmony_ci int _times = (t1), _times2 = (t2); \ 3153a5a1b3Sopenharmony_ci pa_usec_t _start, _stop; \ 3253a5a1b3Sopenharmony_ci pa_usec_t _min = INT_MAX, _max = 0; \ 3353a5a1b3Sopenharmony_ci double _s1 = 0, _s2 = 0; \ 3453a5a1b3Sopenharmony_ci const char *_label = (l); \ 3553a5a1b3Sopenharmony_ci \ 3653a5a1b3Sopenharmony_ci for (_k = 0; _k < _times2; _k++) { \ 3753a5a1b3Sopenharmony_ci _start = pa_rtclock_now(); \ 3853a5a1b3Sopenharmony_ci for (_j = 0; _j < _times; _j++) 3953a5a1b3Sopenharmony_ci 4053a5a1b3Sopenharmony_ci#define PA_RUNTIME_TEST_RUN_STOP \ 4153a5a1b3Sopenharmony_ci _stop = pa_rtclock_now(); \ 4253a5a1b3Sopenharmony_ci \ 4353a5a1b3Sopenharmony_ci if (_min > (_stop - _start)) _min = _stop - _start; \ 4453a5a1b3Sopenharmony_ci if (_max < (_stop - _start)) _max = _stop - _start; \ 4553a5a1b3Sopenharmony_ci _s1 += _stop - _start; \ 4653a5a1b3Sopenharmony_ci _s2 += (_stop - _start) * (_stop - _start); \ 4753a5a1b3Sopenharmony_ci } \ 4853a5a1b3Sopenharmony_ci pa_log_debug("%s: %llu usec (avg: %g, min = %llu, max = %llu, stddev = %g).", _label, \ 4953a5a1b3Sopenharmony_ci (long long unsigned int)_s1, \ 5053a5a1b3Sopenharmony_ci ((double)_s1 / _times2), \ 5153a5a1b3Sopenharmony_ci (long long unsigned int)_min, \ 5253a5a1b3Sopenharmony_ci (long long unsigned int)_max, \ 5353a5a1b3Sopenharmony_ci sqrt(_times2 * _s2 - _s1 * _s1) / _times2); \ 5453a5a1b3Sopenharmony_ci} 5553a5a1b3Sopenharmony_ci 5653a5a1b3Sopenharmony_ci#endif 57