perfbench.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. // perfbench: the audio engine's CPU cost per block, headless (round perfcore190ge).
  2. //
  3. // Renders a scenario through RackRenderer as the app's audio callback does (live quality, a MeterBank, the live event
  4. // queues) and reports, per repetition, the CPU time and the instructions retired by the rendering, as ns per sample
  5. // and as % of one core at real time, plus a hash of the output samples (the same hash before and after a change =
  6. // a bit-identical null test).
  7. //
  8. // usage: perfbench <scenario> [--block N] [--threads N] [--seconds S] [--reps R] [--offline] [--nometers] [--raw path]
  9. // [--stopped] [--ahead] [--live C] [--paced] [--apptransport]
  10. // scenarios:
  11. // demo the showcase song (Demo.lynx), whole song
  12. // hiphop | pop the two LYNX demo songs
  13. // synth100 100 built-in synth channels (presets in turn, chords + an arpeggio line) into 50 inserts with
  14. // 3 LYNX effects each (EQ / dynamics / space)
  15. // inserts50 one synth into 50 inserts in a chain of sends, 4 effects each: the mixer and effects alone
  16. // stream 24 audio-clip channels playing 60 s takes (long audio streaming)
  17. // idle the synth100 project with the transport stopped and nothing playing (the cost of an idle project)
  18. // afterstop the synth100 project played for --warmup seconds (not measured), then stopped (round 190gp: the
  19. // seconds after Stop, while the effects' tails die away and smart disable takes them out)
  20. // big200 200 channels, 120 inserts with LYNX's own effects, 2,000 clips, 200 automation clips (round
  21. // perfgate190id; this and the next: core/PerfProjects.h, the big-project performance gate)
  22. // automation 32 synths, 16 inserts, 400 dense automation clips and a tempo clip
  23. // calibrate a fixed piece of work no LYNX change touches: the machine's speed (the gate divides by it)
  24. // flp:<path> an FL Studio project, whole song (FL's own data from FL_ROOT, as renderwav)
  25. // --gate: one machine-readable "GATE key=value ..." line at the end (CPU, instructions, import / build / rebuild / edit time,
  26. // peak memory, hash; dropouts with --paced) for scripts/perf_gate.py.
  27. // --threads N: N worker threads besides the calling one (the app's WorkerPool); the CPU time is then the process'
  28. // (every thread, spinning included) and the instructions are the calling thread's only.
  29. // Round 190gq (render-ahead, core/RenderAhead.h):
  30. // --apptransport the position moves as the app's audio callback moves it (the tempo the renderer used, Transport's
  31. // arithmetic); implied by --ahead, so a real-time and a render-ahead run of one scenario can be nulled
  32. // --ahead render through RenderAhead as ChannelRackProcessor does (the device callback's model, the thread; it
  33. // starts when the load needs it, as in the app); --ahead-always: whenever it can (the null tests)
  34. // --live C channel C is played live (the selected channel): it and what it feeds stay real-time (repeatable)
  35. // --loop B (with --apptransport) a loop region over the song's first B bars: the blocks are split at its end
  36. // and the position wraps, as the app's callback does it (core/RenderAhead.h planSubBlock)
  37. // --correlation the meters also sum each insert's L·R, L² and R², as while the Mixer's correlation bars show (round
  38. // 190ro: their audio-thread cost, an A/B with and without)
  39. // --latency356on (round 190te) the LYNX extra "Tempo-synced effects follow the latency before them" on (issue #356)
  40. // --paced the blocks come at real time, as a device's callbacks: reports the callbacks that ran past their
  41. // block's duration (dropouts), the worst callback, and the process CPU (every thread)
  42. #include <algorithm>
  43. #include <cctype>
  44. #include <chrono>
  45. #include <ctime>
  46. #include <cmath>
  47. #include <cstdio>
  48. #include <functional>
  49. #include <cstdlib>
  50. #include <cstring>
  51. #include <filesystem>
  52. #include <fstream>
  53. #include <iterator>
  54. #include <map>
  55. #include <memory>
  56. #include <string>
  57. #include <thread>
  58. #include <vector>
  59. #include <time.h>
  60. #if ! defined(_WIN32)
  61. #include <sys/resource.h>
  62. #endif
  63. #if defined(__linux__)
  64. #include <linux/perf_event.h>
  65. #include <sys/ioctl.h>
  66. #include <sys/syscall.h>
  67. #include <unistd.h>
  68. #endif
  69. #include "WavReader.h"
  70. #include "core/DemoSongs.h"
  71. #include "core/LatencyTransport.h"
  72. #include "core/Effects.h"
  73. #include "core/AlsImport.h"
  74. #include "core/FlpImport.h"
  75. #include "core/LiveEventQueue.h"
  76. #include "core/LoadTrace.h"
  77. #include "core/Meters.h"
  78. #include "core/RackRenderer.h"
  79. #include "core/RenderAhead.h"
  80. #include "core/PerfProjects.h"
  81. #include "core/ShowcaseSong.h"
  82. #include "core/SynthPresets.h"
  83. #include "core/WorkerPool.h"
  84. #include "core/TrackStates.h"
  85. #include <sstream>
  86. // round 190gp: A/B switches of this round's changes, looked up weakly (the same tool links with the objects from before
  87. // them, which do not have them): LYNX_DECLARED_TAILS=0 (smart disable's fixed hold), LYNX_SYNTH_LANES=0 (the synth's
  88. // voices one by one)
  89. namespace lynx
  90. {
  91. void setDeclaredTails (bool on) noexcept __attribute__ ((weak));
  92. void setSynthVoiceLanes (bool on) noexcept __attribute__ ((weak));
  93. }
  94. namespace
  95. {
  96. using namespace lynx;
  97. void applySwitches()
  98. {
  99. auto off = [] (const char* name) { const char* v = std::getenv (name); return v != nullptr && std::atoi (v) == 0; };
  100. if (setDeclaredTails != nullptr)
  101. setDeclaredTails (! off ("LYNX_DECLARED_TAILS"));
  102. if (setSynthVoiceLanes != nullptr)
  103. setSynthVoiceLanes (! off ("LYNX_SYNTH_LANES"));
  104. }
  105. #if defined(_WIN32) // (no thread CPU clock here: the process' CPU time)
  106. using clockid_t = int;
  107. constexpr clockid_t CLOCK_THREAD_CPUTIME_ID = 0, CLOCK_PROCESS_CPUTIME_ID = 1;
  108. double cpuMs (clockid_t) { return 1000.0 * (double) std::clock() / CLOCKS_PER_SEC; }
  109. #else
  110. double cpuMs (clockid_t clock)
  111. {
  112. timespec ts {};
  113. clock_gettime (clock, &ts);
  114. return ts.tv_sec * 1000.0 + ts.tv_nsec * 1e-6;
  115. }
  116. #endif
  117. // instructions retired in user space by the calling thread (-1 when the PMU is not available)
  118. struct InstructionCounter
  119. {
  120. #if defined(__linux__)
  121. int fd = -1;
  122. InstructionCounter()
  123. {
  124. perf_event_attr a {};
  125. a.type = PERF_TYPE_HARDWARE;
  126. a.size = sizeof (a);
  127. a.config = PERF_COUNT_HW_INSTRUCTIONS;
  128. a.disabled = 1;
  129. a.exclude_kernel = 1;
  130. a.exclude_hv = 1;
  131. fd = (int) syscall (SYS_perf_event_open, &a, 0, -1, -1, 0);
  132. }
  133. ~InstructionCounter()
  134. {
  135. if (fd >= 0)
  136. close (fd);
  137. }
  138. void start() { if (fd >= 0) { ioctl (fd, PERF_EVENT_IOC_RESET, 0); ioctl (fd, PERF_EVENT_IOC_ENABLE, 0); } }
  139. void pause() { if (fd >= 0) ioctl (fd, PERF_EVENT_IOC_DISABLE, 0); }
  140. void resume() { if (fd >= 0) ioctl (fd, PERF_EVENT_IOC_ENABLE, 0); }
  141. long long read()
  142. {
  143. long long v = -1;
  144. if (fd >= 0 && ::read (fd, &v, sizeof (v)) != (ssize_t) sizeof (v))
  145. v = -1;
  146. return v;
  147. }
  148. #else
  149. void start() {}
  150. void pause() {}
  151. void resume() {}
  152. long long read() { return -1; }
  153. #endif
  154. };
  155. std::string toLocal (std::string p)
  156. {
  157. std::replace (p.begin(), p.end(), '\\', '/');
  158. if (p.size() > 2 && p[1] == ':' && p[2] == '/' && std::isalpha ((unsigned char) p[0]))
  159. p = "/mnt/" + std::string (1, (char) std::tolower ((unsigned char) p[0])) + p.substr (2);
  160. return p;
  161. }
  162. Song importProject (const std::string& path)
  163. {
  164. std::ifstream in (path, std::ios::binary);
  165. std::vector<std::uint8_t> bytes ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  166. const std::string flRoot = std::getenv ("FL_ROOT") ? std::getenv ("FL_ROOT") : "/mnt/c/Program Files/Image-Line/FL Studio 2026";
  167. FlpImportOptions options;
  168. options.roots = { flRoot, flRoot + "/Data", "" };
  169. options.fileExists = [] (const std::string& p) { return std::filesystem::exists (toLocal (p)); };
  170. options.readFile = [] (const std::string& p) {
  171. std::ifstream f (toLocal (p), std::ios::binary);
  172. return std::vector<std::uint8_t> ((std::istreambuf_iterator<char> (f)), std::istreambuf_iterator<char>());
  173. };
  174. return importFlp (flp::parseProject (bytes), options);
  175. }
  176. // the process' peak resident memory in MB (-1 when unknown)
  177. double peakRssMb()
  178. {
  179. #if ! defined(_WIN32)
  180. rusage usage {};
  181. if (getrusage (RUSAGE_SELF, &usage) == 0)
  182. #if defined(__APPLE__)
  183. return (double) usage.ru_maxrss / 1048576.0; // (bytes on macOS)
  184. #else
  185. return (double) usage.ru_maxrss / 1024.0; // (kilobytes on Linux)
  186. #endif
  187. #endif
  188. return -1.0;
  189. }
  190. // perfgate190id: a fixed piece of DSP-like work (biquads, a soft clip, an interpolated table read over 256 KB) that no
  191. // LYNX change touches. The gate divides its CPU times by this one's, so a faster or slower machine (CI runners differ)
  192. // moves both alike; median of 7 runs, ms of thread CPU.
  193. double calibrationMs()
  194. {
  195. std::vector<float> buffer ((std::size_t) 1 << 16), table (4096);
  196. for (std::size_t i = 0; i < table.size(); ++i)
  197. table[i] = (float) std::sin (6.283185307179586 * (double) i / (double) table.size());
  198. std::uint32_t seed = 12345u;
  199. for (auto& x : buffer)
  200. {
  201. seed = seed * 1664525u + 1013904223u;
  202. x = (float) ((int) (seed >> 9) - (1 << 22)) / (float) (1 << 22);
  203. }
  204. std::vector<double> runs;
  205. volatile float sink = 0.0f;
  206. for (int run = 0; run < 7; ++run)
  207. {
  208. const auto t0 = cpuMs (CLOCK_THREAD_CPUTIME_ID);
  209. float z1 = 0.0f, z2 = 0.0f, y1 = 0.0f, y2 = 0.0f, phase = 0.0f;
  210. for (int pass = 0; pass < 48; ++pass)
  211. for (auto& x : buffer)
  212. {
  213. const auto in = x;
  214. const auto y = 0.2f * in + 0.4f * z1 + 0.2f * z2 + 0.6f * y1 - 0.25f * y2;
  215. z2 = z1, z1 = in, y2 = y1, y1 = y;
  216. phase += 0.013f;
  217. phase -= (float) (int) phase;
  218. const auto pos = phase * 4095.0f;
  219. const auto k = (int) pos;
  220. const auto frac = pos - (float) k;
  221. const auto t = table[(std::size_t) k] + frac * (table[(std::size_t) k + 1] - table[(std::size_t) k]);
  222. const auto v = y * 0.9f + 0.1f * t;
  223. x = v / (1.0f + std::fabs (v)) + 1e-7f * in;
  224. }
  225. runs.push_back (cpuMs (CLOCK_THREAD_CPUTIME_ID) - t0);
  226. sink = sink + buffer[(std::size_t) run];
  227. }
  228. std::sort (runs.begin(), runs.end());
  229. return runs[runs.size() / 2];
  230. }
  231. std::uint64_t hashSamples (const std::vector<float>& l, const std::vector<float>& r)
  232. {
  233. std::uint64_t h = 1469598103934665603ull;
  234. auto add = [&h] (const std::vector<float>& v) {
  235. for (const auto x : v)
  236. {
  237. std::uint32_t bits;
  238. std::memcpy (&bits, &x, 4);
  239. h = (h ^ bits) * 1099511628211ull;
  240. }
  241. };
  242. add (l);
  243. add (r);
  244. return h;
  245. }
  246. } // namespace
  247. int main (int argc, char** argv)
  248. {
  249. if (argc < 2)
  250. {
  251. std::fprintf (stderr, "usage: perfbench <demo|hiphop|pop|synth100|inserts50|stream|big200|automation|idle|calibrate|flp:path|als:path> [--block N] [--threads N] "
  252. "[--seconds S] [--reps R] [--offline] [--nometers] [--raw path] [--stopped]\n");
  253. return 2;
  254. }
  255. applySwitches();
  256. const std::string scenario = argv[1];
  257. if (scenario == "calibrate") // (perfgate190id: the machine's speed, see calibrationMs)
  258. {
  259. const auto ms = calibrationMs();
  260. std::printf ("RESULT calibrate: %.2f ms\nGATE scenario=calibrate calib_ms=%.3f\n", ms, ms);
  261. return 0;
  262. }
  263. int blockSize = 256, threads = 0, reps = 5;
  264. double seconds = 0.0, warmup = 0.0;
  265. bool offline = false, meters = true, stopped = scenario == "idle" || scenario == "afterstop", units = false, aheadMode = false, paced = false, appTransport = false,
  266. aheadAlways = false, correlation = false;
  267. std::vector<int> liveChannels;
  268. std::vector<std::string> deactivateSpecs;
  269. int loopBars = 0;
  270. bool gate = false;
  271. const bool playWarmup = scenario == "afterstop"; // (the warmup plays, the measured part is stopped)
  272. const char* raw = nullptr;
  273. for (int i = 2; i < argc; ++i)
  274. {
  275. const std::string a = argv[i];
  276. auto next = [&] { return i + 1 < argc ? argv[++i] : (char*) "0"; };
  277. if (a == "--block")
  278. blockSize = std::clamp (std::atoi (next()), 16, 4096);
  279. else if (a == "--threads")
  280. threads = std::max (0, std::atoi (next()));
  281. else if (a == "--seconds")
  282. seconds = std::atof (next());
  283. else if (a == "--reps")
  284. reps = std::max (1, std::atoi (next()));
  285. else if (a == "--offline")
  286. offline = true;
  287. else if (a == "--nometers")
  288. meters = false;
  289. else if (a == "--raw")
  290. raw = next();
  291. else if (a == "--stopped")
  292. stopped = true;
  293. else if (a == "--warmup") // seconds rendered first and not measured (an idle project: past the effects' smart disable hold)
  294. warmup = std::max (0.0, std::atof (next()));
  295. else if (a == "--units") // the renderer's own per-channel / per-slot CPU (as renderwav's LYNX_PROFILE)
  296. units = true;
  297. else if (a == "--ahead")
  298. aheadMode = appTransport = true;
  299. else if (a == "--ahead-always") // (render-ahead whatever the load: the null tests)
  300. aheadMode = appTransport = aheadAlways = true;
  301. else if (a == "--live")
  302. liveChannels.push_back (std::atoi (next()));
  303. else if (a == "--paced")
  304. paced = true;
  305. else if (a == "--apptransport")
  306. appTransport = true;
  307. else if (a == "--loop")
  308. loopBars = std::max (0, std::atoi (next()));
  309. else if (a == "--gate") // (perfgate190id: one machine-readable GATE line at the end, scripts/perf_gate.py)
  310. gate = true;
  311. else if (a == "--deactivate") // round 190op (P4): "c:1,2" channels / "i:3,4" inserts deactivated (core/TrackStates.h)
  312. deactivateSpecs.push_back (next());
  313. else if (a == "--correlation") // round 190ro: the Mixer's correlation bars' sums (core/Meters.h correlationWanted)
  314. correlation = true;
  315. else if (a == "--latency356on") // round 190te (issue #356): the LYNX extra "Tempo-synced effects follow the latency before them"
  316. latencytransport::patternOn = true;
  317. }
  318. constexpr int sampleRate = 44100;
  319. std::map<std::string, std::shared_ptr<const SampleData>> cache;
  320. Song song;
  321. const auto import0 = std::chrono::steady_clock::now();
  322. if (scenario == "demo")
  323. song = makeShowcaseSong();
  324. else if (scenario == "hiphop")
  325. song = demos::make (1);
  326. else if (scenario == "pop")
  327. song = demos::make (2);
  328. else if (scenario == "idle" || scenario == "afterstop")
  329. song = perfprojects::synth100 (16);
  330. else if (perfprojects::make (scenario, song, cache)) // (the gate's synthetic projects, core/PerfProjects.h)
  331. {
  332. }
  333. else if (scenario.rfind ("als:", 0) == 0) // (round 190gq: a Live set, its arrangement on the Playlist)
  334. {
  335. const auto path = scenario.substr (4);
  336. std::ifstream in (path, std::ios::binary);
  337. std::vector<std::uint8_t> bytes ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  338. AlsImportOptions options;
  339. options.sessionOnPlaylist = true;
  340. options.common.projectFolder = std::filesystem::path (path).parent_path().string();
  341. options.common.fileExists = [] (const std::string& p) { return std::filesystem::exists (toLocal (p)); };
  342. options.common.readFile = [] (const std::string& p) {
  343. std::ifstream f (toLocal (p), std::ios::binary);
  344. return std::vector<std::uint8_t> ((std::istreambuf_iterator<char> (f)), std::istreambuf_iterator<char>());
  345. };
  346. options.libraryRoots = { "/mnt/c/ProgramData/Ableton/Live 12 Trial/Resources/Core Library" };
  347. std::string error;
  348. auto imported = importAls (bytes, options, &error);
  349. if (! imported)
  350. {
  351. std::fprintf (stderr, "error: %s\n", error.c_str());
  352. return 1;
  353. }
  354. song = std::move (*imported);
  355. }
  356. else if (scenario.rfind ("flp:", 0) == 0)
  357. {
  358. try
  359. {
  360. song = importProject (scenario.substr (4));
  361. }
  362. catch (const std::exception& e)
  363. {
  364. std::fprintf (stderr, "error: %s\n", e.what());
  365. return 1;
  366. }
  367. }
  368. else
  369. {
  370. std::fprintf (stderr, "unknown scenario %s\n", scenario.c_str());
  371. return 2;
  372. }
  373. const auto importMs = std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - import0).count();
  374. // round 190of: LYNX_PB_SMARTALL=1 = FL's Tools > Macros > "Switch smart disable for all plugins" (every slot on), and
  375. // LYNX_PB_SLOTS=1 lists how many slots have it on as imported
  376. {
  377. int on = 0, all = 0;
  378. for (auto& track : song.mixer)
  379. for (auto& slot : track.effects)
  380. {
  381. ++all;
  382. on += slot.smartDisable ? 1 : 0;
  383. if (std::getenv ("LYNX_PB_SMARTALL") != nullptr)
  384. slot.smartDisable = true;
  385. }
  386. if (std::getenv ("LYNX_PB_SLOTS") != nullptr)
  387. std::printf ("slots: %d, smart disable on in %d%s\n", all, on, std::getenv ("LYNX_PB_SMARTALL") != nullptr ? " (now all on)" : "");
  388. }
  389. // round 190ok: LYNX_PB_REV=n gives every effect slot (inside Patchers and parallel branches too) engine revision n:
  390. // LYNX_PB_REV=1 renders as a project saved before round 190ok (the gold renders' check that those are bit for bit)
  391. if (const char* rev = std::getenv ("LYNX_PB_REV"))
  392. {
  393. const auto n = std::atoi (rev);
  394. std::function<void (EffectSlot&)> slotRev;
  395. std::function<void (PatcherDoc&)> docRev = [&] (PatcherDoc& doc) {
  396. for (auto& node : doc.nodes)
  397. {
  398. slotRev (node.effect);
  399. docRev (node.channel.patcher);
  400. }
  401. };
  402. slotRev = [&] (EffectSlot& slot) {
  403. slot.engineRev = n;
  404. for (auto& b : slot.branches)
  405. for (auto& inner : b.chain)
  406. slotRev (inner);
  407. docRev (slot.patcher);
  408. };
  409. for (auto& track : song.mixer)
  410. for (auto& slot : track.effects)
  411. slotRev (slot);
  412. for (auto& c : song.channels)
  413. docRev (c.patcher);
  414. }
  415. // round 190op (P4): deactivated channels / inserts (RackState::build plays the projection: they are not loaded)
  416. for (const auto& spec : deactivateSpecs)
  417. {
  418. if (spec.size() < 3 || spec[1] != ':')
  419. continue;
  420. std::vector<int> list;
  421. std::stringstream ss (spec.substr (2));
  422. for (std::string item; std::getline (ss, item, ',');)
  423. if (! item.empty())
  424. list.push_back (std::atoi (item.c_str()));
  425. const auto n = spec[0] == 'c' ? deactivate::setChannels (song, list, true) : deactivate::setInserts (song, list, true);
  426. std::printf ("deactivated %d %s (%s)\n", n, spec[0] == 'c' ? "channel(s)" : "insert(s)", spec.c_str());
  427. }
  428. std::int64_t songTicks = 0;
  429. song = makeExportSong (song, true, (std::int64_t) std::ceil (ticksPerSample (song.bpm, sampleRate) * sampleRate), songTicks);
  430. const auto tps = ticksPerSample (song.bpm, sampleRate);
  431. auto totalSamples = (std::size_t) ((double) songTicks / tps);
  432. if (seconds > 0.0)
  433. totalSamples = std::min (totalSamples, (std::size_t) (seconds * sampleRate));
  434. if (stopped && seconds > 0.0)
  435. totalSamples = (std::size_t) (seconds * sampleRate);
  436. totalSamples = std::max<std::size_t> (totalSamples, (std::size_t) blockSize);
  437. if (appTransport) // (whole device blocks: a device keeps its block size; render-ahead drops its window when it changes)
  438. totalSamples = totalSamples / (std::size_t) blockSize * (std::size_t) blockSize;
  439. setOfflineRendering (offline);
  440. auto provider = [&] (const std::string& p) {
  441. auto& entry = cache[p];
  442. if (entry == nullptr)
  443. entry = tools::readWav (toLocal (p));
  444. return entry;
  445. };
  446. std::unique_ptr<WorkerPool> pool;
  447. if (threads > 0)
  448. pool = std::make_unique<WorkerPool> (threads);
  449. std::printf ("scenario %s: %zu channels, %zu inserts, %.1f s at %d Hz, block %d, %d worker threads, %s, meters %s%s\n", scenario.c_str(),
  450. song.channels.size(), song.mixer.size(), (double) totalSamples / sampleRate, sampleRate, blockSize, threads,
  451. offline ? "offline quality" : "live quality", meters ? (correlation ? "on, with the correlation sums" : "on") : "off", stopped ? ", stopped" : "");
  452. std::vector<double> cpu, nsPerSample, buildMs, droppedPerMin, overPerMin;
  453. std::vector<long long> instr;
  454. std::uint64_t firstHash = 0;
  455. bool sameHash = true;
  456. for (int rep = 0; rep < reps; ++rep)
  457. {
  458. const auto build0 = std::chrono::steady_clock::now();
  459. auto state = RackState::build (song, nullptr, sampleRate, provider);
  460. buildMs.push_back (std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - build0).count());
  461. const auto* statePtr = state.get();
  462. auto renderer = std::make_unique<RackRenderer>();
  463. if (pool != nullptr)
  464. renderer->setWorkerPool (pool.get());
  465. renderer->prepare (sampleRate, std::max (2048, blockSize));
  466. renderer->setProfiling (units);
  467. auto bank = std::make_unique<MeterBank>();
  468. bank->correlationWanted.store (correlation, std::memory_order_relaxed); // (round 190ro; nothing reads them, so they stay wanted)
  469. const auto levels = std::getenv ("LYNX_PB_LEVELS") != nullptr; // (round 190of)
  470. std::vector<float> trackPeaks (song.mixer.size(), 0.0f);
  471. auto live = std::make_unique<LiveEventQueue>();
  472. auto midiLive = std::make_unique<LiveEventQueue>();
  473. // render-ahead (round 190gq): the controller as ChannelRackProcessor drives it, the snapshot from an exchange
  474. SnapshotExchange<RackState> exchange;
  475. std::unique_ptr<RenderAhead> ahead;
  476. renderahead::Targets targets;
  477. renderahead::TransportModel model;
  478. MarkerPlan markers;
  479. if (aheadMode)
  480. {
  481. ahead = std::make_unique<RenderAhead> (*renderer);
  482. ahead->setWorkerPool (pool.get());
  483. ahead->prepare (sampleRate, std::max (2048, blockSize));
  484. ahead->setTargets (&targets);
  485. ahead->setAlwaysEngage (aheadAlways);
  486. targets.publish (liveChannels.data(), (int) liveChannels.size(), nullptr, 0);
  487. exchange.publish (std::move (state));
  488. }
  489. // the device callback's transport: linear through the export song, or round the loop region (--loop)
  490. model.sampleRate = sampleRate;
  491. model.deviceBlock = blockSize;
  492. model.songMode = loopBars > 0;
  493. model.loopEnd = loopBars > 0 ? (double) loopBars * song.beatsPerBar * ppq : 0.0;
  494. model.markers = &markers;
  495. std::vector<float> left (totalSamples), right (totalSamples);
  496. std::vector<double> blockCpu;
  497. blockCpu.reserve (totalSamples / (std::size_t) blockSize + 1);
  498. // the app's transport (--apptransport): the next block's position moves with the tempo this one used
  499. auto bpmNow = song.bpm;
  500. auto blockPlaying = ! stopped; // (the warmup of 190gp's afterstop plays; rollup 0.1.28)
  501. auto renderBlock = [&] (double tick, int n, float* l, float* r) {
  502. if (ahead != nullptr)
  503. {
  504. renderahead::Block b;
  505. b.playing = blockPlaying;
  506. b.startTick = tick;
  507. b.samples = n;
  508. b.tps = renderahead::transportTps (bpmNow, sampleRate);
  509. b.metronomeTrack = 0;
  510. b.model = &model;
  511. b.metering = meters;
  512. ahead->process (exchange, b, l, r, live.get(), meters ? bank.get() : nullptr, midiLive.get());
  513. if (pool != nullptr && ! ahead->ownsWorkers())
  514. pool->park();
  515. const auto* used = ahead->currentState();
  516. bpmNow = used != nullptr && used->tempoMap ? renderer->currentBpm() : song.bpm;
  517. return;
  518. }
  519. renderer->process (statePtr, blockPlaying, tick, n, l, r, live.get(), meters ? bank.get() : nullptr, midiLive.get());
  520. if (pool != nullptr) // (as the app's audio callback ends: the workers sleep until the next block, REA round 116)
  521. pool->park();
  522. if (appTransport)
  523. bpmNow = statePtr->tempoMap ? renderer->currentBpm() : song.bpm;
  524. };
  525. auto stepTicks = [&] (int n) { return appTransport ? n * renderahead::transportTps (bpmNow, sampleRate) : n * tps; };
  526. double warmTick = 0.0;
  527. if (warmup > 0.0) // (stopped: the same position; playing: the song advances and the measured part starts later)
  528. {
  529. std::vector<float> wl ((std::size_t) blockSize), wr ((std::size_t) blockSize);
  530. for (int done = 0, total = (int) (warmup * sampleRate); done < total; done += blockSize)
  531. {
  532. const auto step = stepTicks (blockSize);
  533. const auto play = ! stopped || playWarmup; // (round 190gp's afterstop: the warmup plays)
  534. blockPlaying = play;
  535. renderBlock (play ? (appTransport ? warmTick : done * tps) : 0.0, blockSize, wl.data(), wr.data());
  536. warmTick += step;
  537. }
  538. blockPlaying = ! stopped;
  539. if (units)
  540. renderer->resetUnitTimes();
  541. }
  542. InstructionCounter counter;
  543. const auto clock = pool != nullptr || ahead != nullptr || paced ? CLOCK_PROCESS_CPUTIME_ID : CLOCK_THREAD_CPUTIME_ID;
  544. const auto warmupBlocks = (int) std::ceil (warmup * sampleRate / blockSize);
  545. double tick = stopped ? 0.0 : (appTransport ? warmTick : (double) warmupBlocks * blockSize * tps), used = 0.0;
  546. const auto wall0 = std::chrono::steady_clock::now();
  547. const auto period = std::chrono::duration<double> ((double) blockSize / sampleRate);
  548. auto due = wall0;
  549. int dropouts = 0, over = 0;
  550. double worstMs = 0.0, spinMs = 0.0;
  551. std::vector<double> callbackMs;
  552. const auto processCpu0 = cpuMs (CLOCK_PROCESS_CPUTIME_ID);
  553. const auto pool0 = pool != nullptr ? pool->stats() : WorkerPool::Stats {}; // (round 190kb)
  554. counter.start();
  555. for (std::size_t pos = 0; pos < totalSamples; pos += (std::size_t) blockSize)
  556. {
  557. const auto n = (int) std::min<std::size_t> ((std::size_t) blockSize, totalSamples - pos);
  558. if (paced) // the device asks for the next block at its time (sleep, then spin the last 300 µs: the wake-up's
  559. { // timer slack is not the engine's; the spinning's CPU is taken out of the total below)
  560. std::this_thread::sleep_until (due - std::chrono::microseconds (300));
  561. const auto spin0 = cpuMs (CLOCK_THREAD_CPUTIME_ID);
  562. while (std::chrono::steady_clock::now() < due)
  563. WorkerPool::relax();
  564. spinMs += cpuMs (CLOCK_THREAD_CPUTIME_ID) - spin0;
  565. due += std::chrono::duration_cast<std::chrono::steady_clock::duration> (period);
  566. }
  567. const auto c0 = cpuMs (clock);
  568. const auto w0 = std::chrono::steady_clock::now();
  569. if (appTransport && ! stopped)
  570. {
  571. // the callback's loop: sub-blocks up to the loop's end, the position as Transport moves it
  572. model.deviceBlock = n;
  573. for (int done = 0; done < n;)
  574. {
  575. const auto tpsNow = renderahead::transportTps (bpmNow, sampleRate);
  576. const auto sb = renderahead::planSubBlock (model, tick, done, tpsNow);
  577. model.offset = done;
  578. renderBlock (sb.start, sb.samples, left.data() + pos + (std::size_t) done, right.data() + pos + (std::size_t) done);
  579. tick = sb.next;
  580. done += sb.samples;
  581. }
  582. }
  583. else
  584. {
  585. const auto step = stepTicks (n);
  586. renderBlock (stopped ? 0.0 : tick, n, left.data() + pos, right.data() + pos);
  587. tick += stopped ? 0.0 : step;
  588. }
  589. const auto spent = cpuMs (clock) - c0;
  590. const auto wallSpent = std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - w0).count();
  591. if (paced)
  592. {
  593. callbackMs.push_back (wallSpent);
  594. worstMs = std::max (worstMs, wallSpent);
  595. if (wallSpent > 1000.0 * n / sampleRate)
  596. ++over; // the callback itself took longer than its block lasts
  597. if (std::chrono::steady_clock::now() > due) // finished after the next block was due: a dropout
  598. {
  599. ++dropouts;
  600. due = std::chrono::steady_clock::now(); // (the device goes on from now)
  601. }
  602. }
  603. used += spent;
  604. blockCpu.push_back (paced ? wallSpent : spent);
  605. if (meters) // the UI's meter reads (Mixer + Playlist headers), as often as a 60 Hz timer would
  606. if ((pos / (std::size_t) blockSize) % std::max<std::size_t> (1, (std::size_t) (sampleRate / 60 / blockSize)) == 0)
  607. {
  608. counter.pause();
  609. // round 190of: LYNX_PB_LEVELS=1 keeps each insert's highest peak over the last 2 s of rep 0 (what keeps a
  610. // stopped project's chains awake: smart disable needs -96 dB)
  611. const auto lastSeconds = rep == 0 && levels && (double) pos >= (double) totalSamples - 2.0 * sampleRate;
  612. for (int t = 0; t < (int) song.mixer.size(); ++t)
  613. for (int s = 0; s < 2; ++s)
  614. {
  615. const auto peak = bank->takePeak (t, s);
  616. (void) bank->takeViewPeak (t, s);
  617. if (lastSeconds && t < (int) trackPeaks.size())
  618. trackPeaks[(std::size_t) t] = std::max (trackPeaks[(std::size_t) t], peak);
  619. }
  620. counter.resume();
  621. }
  622. }
  623. if (paced) // every thread's CPU, the render-ahead thread and the workers included (not the pacing's spin)
  624. used = cpuMs (CLOCK_PROCESS_CPUTIME_ID) - processCpu0 - spinMs;
  625. if (paced)
  626. {
  627. std::sort (callbackMs.begin(), callbackMs.end());
  628. const auto audioSeconds = (double) totalSamples / sampleRate;
  629. droppedPerMin.push_back (dropouts * 60.0 / audioSeconds);
  630. overPerMin.push_back (over * 60.0 / audioSeconds);
  631. std::printf ("paced: %d dropouts (%.2f per minute), %d callbacks over their block (%.2f per minute), worst callback %.3f ms, p99 %.3f ms, "
  632. "median %.3f ms (budget %.3f ms)\n", dropouts, dropouts * 60.0 / audioSeconds, over, over * 60.0 / audioSeconds, worstMs, callbackMs[std::min (callbackMs.size() - 1, (std::size_t) (0.99 * (double) callbackMs.size()))],
  633. callbackMs[callbackMs.size() / 2], 1000.0 * blockSize / sampleRate);
  634. }
  635. if (pool != nullptr) // round 190kb: where the workers' time went, per second of audio (ms/s = 0.1 % of a core)
  636. {
  637. const auto p = pool->stats();
  638. const auto audioSeconds = (double) totalSamples / sampleRate;
  639. const auto ms = [audioSeconds] (std::uint64_t ns) { return (double) ns / 1.0e6 / audioSeconds; };
  640. const auto per = [audioSeconds] (std::uint64_t n) { return (double) n / audioSeconds; };
  641. std::printf ("pool: rounds %.0f/s, work %.2f ms/s, spin %.2f ms/s (%.0f/s: found %.0f, parked %.0f, timed out %.0f), sleeps %.0f/s (early %.0f), "
  642. "waits %.2f ms/s (%.0f/s, yields %.0f, sleeps %.0f = %.2f ms/s), caller wait %.2f ms/s (sleeps %.0f/s)\n",
  643. per (p.rounds - pool0.rounds), ms (p.workNs - pool0.workNs), ms (p.spinNs - pool0.spinNs), per (p.spins - pool0.spins),
  644. per (p.spinFound - pool0.spinFound), per (p.spinParked - pool0.spinParked), per (p.spinTimedOut - pool0.spinTimedOut),
  645. per (p.sleeps - pool0.sleeps), per (p.earlyWakes - pool0.earlyWakes), ms (p.waitNs - pool0.waitNs), per (p.waits - pool0.waits),
  646. per (p.waitYields - pool0.waitYields), per (p.waitSleeps - pool0.waitSleeps), ms (p.waitSleepNs - pool0.waitSleepNs),
  647. ms (p.callerWaitNs - pool0.callerWaitNs), per (p.callerSleeps - pool0.callerSleeps));
  648. // round 190kz (sched): rounds per device block, and the blocks rendered batched (one round for all their pieces)
  649. const auto blocks = (double) ((totalSamples + (std::size_t) blockSize - 1) / (std::size_t) blockSize);
  650. std::printf ("sched: %.2f rounds per block, batched blocks %llu (one round %llu) since start, of %.0f measured blocks; two-round blocks %llu\n",
  651. (double) (p.rounds - pool0.rounds) / std::max (1.0, blocks), (unsigned long long) renderer->batchedBlockCount(),
  652. (unsigned long long) renderer->batchedRoundCount(), blocks, (unsigned long long) renderer->batchedLiveRoundCount());
  653. {
  654. static const char* const why[] = { "switched off", "no graph", "big block", "live controllers", "MIDI between units",
  655. "launchers", "bindings", "held notes", "timed params", "many pieces", "other" };
  656. std::printf ("sched: not batched:");
  657. auto any = false;
  658. for (int k = 0; k < (int) RackRenderer::BatchRefusal::count; ++k)
  659. if (const auto c = renderer->batchRefusedCount ((RackRenderer::BatchRefusal) k); c > 0)
  660. std::printf (" %s %llu", why[k], (unsigned long long) c), any = true;
  661. std::printf ("%s\n", any ? "" : " none");
  662. if (*renderer->livePlanRefusal() != 0) // (round 190lv)
  663. std::printf ("sched: live controllers kept piece by piece: %s\n", renderer->livePlanRefusal());
  664. }
  665. }
  666. if (ahead != nullptr)
  667. {
  668. const auto& st = ahead->stats();
  669. std::printf ("ahead: blocks %llu, from ring %llu, waited %llu, inline %llu, flushes %llu, drains %llu, engagements %llu, ahead channels %d, "
  670. "ahead inserts %d, boundary %d, window %d samples, split mismatches %llu, backoffs %llu, probes %llu, kept on %llu (for fewer overruns %llu), kept off %llu (probe cpu %.1f%% off / %.1f%% on, overruns %.0f / %.0f per minute)\n",
  671. (unsigned long long) st.blocks.load(), (unsigned long long) st.fromRing.load(), (unsigned long long) st.waited.load(),
  672. (unsigned long long) st.inline_.load(), (unsigned long long) st.flushes.load(), (unsigned long long) st.drains.load(),
  673. (unsigned long long) st.engagements.load(), st.aheadChannels.load(), st.aheadTracks.load(), st.boundary.load(), st.window.load(),
  674. (unsigned long long) st.splitMismatches.load(), (unsigned long long) st.backoffs.load(),
  675. (unsigned long long) st.probes.load(), (unsigned long long) st.keptOn.load(), (unsigned long long) st.keptForOverruns.load(), (unsigned long long) st.keptOff.load(),
  676. (double) st.probeCpuOff.load(), (double) st.probeCpuOn.load(), (double) st.probeOverOff.load(), (double) st.probeOverOn.load());
  677. }
  678. counter.pause();
  679. const auto wallMs = std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - wall0).count();
  680. const auto instructions = counter.read();
  681. const auto audioMs = 1000.0 * (double) totalSamples / sampleRate;
  682. std::sort (blockCpu.begin(), blockCpu.end());
  683. const auto p99 = blockCpu[std::min (blockCpu.size() - 1, (std::size_t) (0.99 * (double) blockCpu.size()))];
  684. const auto budget = 1000.0 * blockSize / sampleRate;
  685. const auto h = hashSamples (left, right);
  686. if (const char* dump = std::getenv ("LYNX_PB_DUMP"); dump != nullptr && rep == 0) // (round 190lv: the samples, for a diff)
  687. if (auto* f = std::fopen (dump, "wb"); f != nullptr)
  688. {
  689. std::fwrite (left.data(), sizeof (float), left.size(), f);
  690. std::fwrite (right.data(), sizeof (float), right.size(), f);
  691. std::fclose (f);
  692. }
  693. if (rep == 0 && levels) // (round 190of: the inserts still above -140 dB at the end)
  694. for (std::size_t t = 0; t < trackPeaks.size(); ++t)
  695. if (trackPeaks[t] > 1.0e-7f)
  696. std::printf ("level insert %d \"%s\": %.1f dBFS%s\n", (int) t, song.mixer[t].name.c_str(), 20.0 * std::log10 (trackPeaks[t]),
  697. trackPeaks[t] > 1.5849e-5f ? " (above smart disable's -96 dB)" : "");
  698. if (rep == 0)
  699. firstHash = h;
  700. sameHash = sameHash && h == firstHash;
  701. cpu.push_back (used);
  702. nsPerSample.push_back (used * 1e6 / (double) totalSamples);
  703. instr.push_back (instructions);
  704. std::printf ("rep %d: cpu %.1f ms (%.2f%% of a core), wall %.1f ms, %.1f ns/sample, %.3f G instructions (%.0f/sample), "
  705. "block p99 %.1f%% of budget, hash %016llx\n",
  706. rep, used, 100.0 * used / audioMs, wallMs, used * 1e6 / (double) totalSamples, (double) instructions * 1e-9,
  707. (double) instructions / (double) totalSamples, 100.0 * p99 / budget, (unsigned long long) h);
  708. if (units && rep == 0)
  709. {
  710. const auto& u = renderer->unitTimes();
  711. std::vector<std::pair<double, std::string>> rows;
  712. for (std::size_t c = 0; c < song.channels.size() && c < (std::size_t) RackRenderer::maxChannels; ++c)
  713. if (const auto ns = (double) u.channelNs[c].load(); ns > 0.0)
  714. rows.push_back ({ ns, "channel " + std::to_string (c) + " " + song.channels[c].name + " [kind "
  715. + std::to_string ((int) song.channels[c].instrument) + (song.channels[c].samplePath.empty() ? std::string() : " " + std::filesystem::path (song.channels[c].samplePath).filename().string())
  716. + ", insert " + std::to_string (song.channels[c].mixerTrack) + "]" });
  717. for (std::size_t t = 0; t < song.mixer.size(); ++t)
  718. for (std::size_t k = 0; k < song.mixer[t].effects.size() && k < (std::size_t) maxEffectSlots; ++k)
  719. if (const auto ns = (double) u.effectNs[t * maxEffectSlots + k].load(); ns > 0.0)
  720. rows.push_back ({ ns, "insert " + std::to_string (t) + " slot " + std::to_string (k + 1) + " "
  721. + effectInfo (song.mixer[t].effects[k].kind).name });
  722. std::sort (rows.begin(), rows.end(), [] (const auto& a, const auto& b) { return a.first > b.first; });
  723. double total = 0.0;
  724. for (const auto& r : rows)
  725. total += r.first;
  726. std::printf ("units: %.1f ms in channels and slots (%.1f%% of this rep's CPU)\n", total * 1e-6, 100.0 * total * 1e-6 / used);
  727. // round 190kr: LYNX_PB_ALLUNITS=1 lists every unit (else the top 20)
  728. const auto shownRows = std::getenv ("LYNX_PB_ALLUNITS") != nullptr ? rows.size() : (std::size_t) 20;
  729. for (std::size_t i = 0; i < rows.size() && i < shownRows; ++i)
  730. std::printf (" %6.2f%% of a core %s\n", 100.0 * rows[i].first * 1e-6 / audioMs, rows[i].second.c_str());
  731. }
  732. if (raw != nullptr && rep == 0)
  733. {
  734. std::ofstream r (raw, std::ios::binary);
  735. r.write ((const char*) left.data(), (std::streamsize) (left.size() * sizeof (float)));
  736. r.write ((const char*) right.data(), (std::streamsize) (right.size() * sizeof (float)));
  737. }
  738. }
  739. auto median = [] (auto v) {
  740. std::sort (v.begin(), v.end());
  741. return v[v.size() / 2];
  742. };
  743. const auto audioMs = 1000.0 * (double) totalSamples / sampleRate;
  744. std::printf ("RESULT %s block=%d threads=%d: median cpu %.1f ms = %.2f%% of a core, %.1f ns/sample, %.0f instructions/sample, "
  745. "hash %016llx%s\n",
  746. scenario.c_str(), blockSize, threads, median (cpu), 100.0 * median (cpu) / audioMs, median (nsPerSample),
  747. (double) median (instr) / (double) totalSamples, (unsigned long long) firstHash, sameHash ? "" : " (HASH VARIES BETWEEN REPS)");
  748. // rep 0's build decodes the samples (a project's load); the later ones build everything new from decoded samples
  749. // (the reps must not share instruments: their outputs are compared). An edit's snapshot (perfgate190id) is a
  750. // build from the previous one, as AudioEngine publishes it: unchanged channels and effects are kept.
  751. const auto firstBuild = buildMs.front();
  752. const auto rebuild = buildMs.size() > 1 ? median (std::vector<double> (buildMs.begin() + 1, buildMs.end())) : firstBuild;
  753. // (rollup 0.1.31 step 5, round 190ok's gate proposal: 12 edits, not 5, and the instructions each one retires on this
  754. // thread, so the gate can hold the edit to its count while one ~5 ms timing moves +-25 % run to run)
  755. std::vector<double> editMs, editInstr;
  756. {
  757. InstructionCounter editCounter;
  758. auto previous = RackState::build (song, nullptr, sampleRate, provider);
  759. const auto trace = std::getenv ("PERFBENCH_TRACE_EDIT") != nullptr; // (the phases of the last edit snapshot)
  760. // (round 190sz: as AudioEngine::publishSong builds it since then, from a copy of the song that shares its
  761. // copy-on-write lists and states, core/CowVector.h; PERFBENCH_EDIT_DEEP=1: from a deep copy, as before)
  762. static const bool deepEdit = std::getenv ("PERFBENCH_EDIT_DEEP") != nullptr;
  763. for (int k = 0; k < 12; ++k)
  764. {
  765. if (trace)
  766. loadtrace::begin ("edit");
  767. editCounter.start();
  768. const auto t0 = std::chrono::steady_clock::now();
  769. auto next = deepEdit ? RackState::build (song, previous.get(), sampleRate, provider)
  770. : RackState::build ([&song] {
  771. const ShareCopies share;
  772. return Song (song);
  773. }(), previous.get(), sampleRate, provider);
  774. editMs.push_back (std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - t0).count());
  775. editCounter.pause();
  776. editInstr.push_back ((double) editCounter.read());
  777. previous = std::move (next);
  778. if (trace)
  779. loadtrace::end();
  780. }
  781. if (trace)
  782. std::printf ("%s", loadtrace::table().c_str());
  783. }
  784. const auto edit = median (editMs);
  785. const auto editInstructions = median (editInstr); // (-1: no CPU counter)
  786. std::printf ("project: import %.1f ms, first build %.1f ms, rebuild %.1f ms, edit snapshot %.1f ms (medians), peak memory %.0f MB; %zu channels, "
  787. "%zu inserts, %zu playlist clips, %zu automations\n",
  788. importMs, firstBuild, rebuild, edit, peakRssMb(), song.channels.size(), song.mixer.size(), song.playlist.size(), song.automations.size());
  789. if (gate)
  790. {
  791. std::printf ("GATE scenario=%s block=%d threads=%d seconds=%.2f cpu_pct=%.3f ns_per_sample=%.2f instr_per_sample=%.0f import_ms=%.2f "
  792. "build_ms=%.2f rebuild_ms=%.2f edit_ms=%.2f rss_mb=%.1f hash=%016llx hash_stable=%d",
  793. scenario.c_str(), blockSize, threads, audioMs / 1000.0, 100.0 * median (cpu) / audioMs, median (nsPerSample),
  794. median (instr) < 0 ? -1.0 : (double) median (instr) / (double) totalSamples, importMs, firstBuild, rebuild, edit, peakRssMb(),
  795. (unsigned long long) firstHash, sameHash ? 1 : 0);
  796. if (editInstructions > 0)
  797. std::printf (" edit_instr=%.0f", editInstructions);
  798. if (paced)
  799. std::printf (" dropouts_per_min=%.2f overruns_per_min=%.2f", median (droppedPerMin), median (overPerMin));
  800. std::printf ("\n");
  801. }
  802. return 0;
  803. }