5353
5454using test_clock = std::chrono::steady_clock;
5555
56+
57+
58+
59+
60+
5661struct ofstream_fixture : public benchmark ::Fixture
5762{
5863 std::ofstream trace;
@@ -89,6 +94,14 @@ struct ofstream_fixture : public benchmark::Fixture
8994 }
9095};
9196
97+ BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_StringLiteral)(benchmark::State& state)
98+ {
99+ while (state.KeepRunning ()) {
100+ trace << " {\" ph\" :\" X\" ,\" pid\" :33692,\" tid\" :33752,\" name\" :\" test_function\" ,\" ts\" :9191,\" dur\" :8},\n " ;
101+ }
102+ }
103+ BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_StringLiteral);
104+
92105BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs)(benchmark::State& state)
93106{
94107 while (state.KeepRunning ()) {
@@ -201,6 +214,129 @@ BENCHMARK_DEFINE_F(ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospac
201214}
202215BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid);
203216
217+ BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_sprintf_insertion)(benchmark::State& state)
218+ {
219+ while (state.KeepRunning ()) {
220+ std::string name;
221+ name += " test_function" ;
222+
223+ std::ostringstream args;
224+
225+ uint64_t processId = GET_PROCESS_ID ();
226+ uint64_t threadId = GET_THREAD_ID ();
227+
228+ using us = std::chrono::microseconds;
229+ uint64_t usStart =
230+ std::chrono::duration_cast<us>(start - global_start).count ();
231+ uint64_t usDelta =
232+ std::chrono::duration_cast<us>(end - start).count ();
233+
234+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
235+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
236+ processId,
237+ threadId,
238+ name.c_str (),
239+ usStart,
240+ usDelta,
241+ args.str ().c_str () );
242+ trace << buffer;
243+ }
244+ }
245+ BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_sprintf_insertion);
246+
247+ BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_sprintf_write)(benchmark::State& state)
248+ {
249+ while (state.KeepRunning ()) {
250+ std::string name;
251+ name += " test_function" ;
252+
253+ std::ostringstream args;
254+
255+ uint64_t processId = GET_PROCESS_ID ();
256+ uint64_t threadId = GET_THREAD_ID ();
257+
258+ using us = std::chrono::microseconds;
259+ uint64_t usStart =
260+ std::chrono::duration_cast<us>(start - global_start).count ();
261+ uint64_t usDelta =
262+ std::chrono::duration_cast<us>(end - start).count ();
263+
264+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
265+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
266+ processId,
267+ threadId,
268+ name.c_str (),
269+ usStart,
270+ usDelta,
271+ args.str ().c_str () );
272+ trace.write (buffer, size);
273+ }
274+ }
275+ BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_sprintf_write);
276+
277+ BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_insertion)(benchmark::State& state)
278+ {
279+ while (state.KeepRunning ()) {
280+ std::string name;
281+ name += " test_function" ;
282+
283+ std::ostringstream args;
284+
285+ uint64_t threadId = GET_THREAD_ID ();
286+
287+ using us = std::chrono::microseconds;
288+ uint64_t usStart =
289+ std::chrono::duration_cast<us>(start - global_start).count ();
290+ uint64_t usDelta =
291+ std::chrono::duration_cast<us>(end - start).count ();
292+
293+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
294+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
295+ fixture_processId,
296+ threadId,
297+ name.c_str (),
298+ usStart,
299+ usDelta,
300+ args.str ().c_str () );
301+ trace << buffer;
302+ }
303+ }
304+ BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_insertion);
305+
306+ BENCHMARK_DEFINE_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_write)(benchmark::State& state)
307+ {
308+ while (state.KeepRunning ()) {
309+ std::string name;
310+ name += " test_function" ;
311+
312+ std::ostringstream args;
313+
314+ uint64_t threadId = GET_THREAD_ID ();
315+
316+ using us = std::chrono::microseconds;
317+ uint64_t usStart =
318+ std::chrono::duration_cast<us>(start - global_start).count ();
319+ uint64_t usDelta =
320+ std::chrono::duration_cast<us>(end - start).count ();
321+
322+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
323+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
324+ fixture_processId,
325+ threadId,
326+ name.c_str (),
327+ usStart,
328+ usDelta,
329+ args.str ().c_str () );
330+ trace.write (buffer, size);
331+ }
332+ }
333+ BENCHMARK_REGISTER_F (ofstream_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_write);
334+
335+
336+
337+
338+
339+
204340struct ofstream_text_fixture : public benchmark ::Fixture
205341{
206342 std::ofstream trace;
@@ -237,6 +373,14 @@ struct ofstream_text_fixture : public benchmark::Fixture
237373 }
238374};
239375
376+ BENCHMARK_DEFINE_F (ofstream_text_fixture, ChromeCallLogging_StringLiteral)(benchmark::State& state)
377+ {
378+ while (state.KeepRunning ()) {
379+ trace << " {\" ph\" :\" X\" ,\" pid\" :33692,\" tid\" :33752,\" name\" :\" test_function\" ,\" ts\" :9191,\" dur\" :8},\n " ;
380+ }
381+ }
382+ BENCHMARK_REGISTER_F (ofstream_text_fixture, ChromeCallLogging_StringLiteral);
383+
240384BENCHMARK_DEFINE_F (ofstream_text_fixture, ChromeCallLogging_WithTimes_WithArgs)(benchmark::State& state)
241385{
242386 while (state.KeepRunning ()) {
@@ -266,6 +410,11 @@ BENCHMARK_DEFINE_F(ofstream_text_fixture, ChromeCallLogging_WithTimes_WithArgs)(
266410}
267411BENCHMARK_REGISTER_F (ofstream_text_fixture, ChromeCallLogging_WithTimes_WithArgs);
268412
413+
414+
415+
416+
417+
269418struct FILE_fixture : public benchmark ::Fixture
270419{
271420 FILE* trace;
@@ -301,6 +450,14 @@ struct FILE_fixture : public benchmark::Fixture
301450 }
302451};
303452
453+ BENCHMARK_DEFINE_F (FILE_fixture, ChromeCallLogging_StringLiteral)(benchmark::State& state)
454+ {
455+ while (state.KeepRunning ()) {
456+ fprintf (trace, " {\" ph\" :\" X\" ,\" pid\" :33692,\" tid\" :33752,\" name\" :\" test_function\" ,\" ts\" :9191,\" dur\" :8},\n " );
457+ }
458+ }
459+ BENCHMARK_REGISTER_F (FILE_fixture, ChromeCallLogging_StringLiteral);
460+
304461BENCHMARK_DEFINE_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs)(benchmark::State& state)
305462{
306463 while (state.KeepRunning ()) {
@@ -444,5 +601,63 @@ BENCHMARK_DEFINE_F(FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_s
444601}
445602BENCHMARK_REGISTER_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_sprintf_fwrite);
446603
604+ BENCHMARK_DEFINE_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_fprintf)(benchmark::State& state)
605+ {
606+ while (state.KeepRunning ()) {
607+ std::string name;
608+ name += " test_function" ;
609+
610+ std::ostringstream args;
611+
612+ uint64_t threadId = GET_THREAD_ID ();
613+
614+ using us = std::chrono::microseconds;
615+ uint64_t usStart =
616+ std::chrono::duration_cast<us>(start - global_start).count ();
617+ uint64_t usDelta =
618+ std::chrono::duration_cast<us>(end - start).count ();
619+
620+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
621+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
622+ fixture_processId,
623+ threadId,
624+ name.c_str (),
625+ usStart,
626+ usDelta,
627+ args.str ().c_str () );
628+ fprintf (trace, " %s" , buffer);
629+ }
630+ }
631+ BENCHMARK_REGISTER_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_fprintf);
632+
633+ BENCHMARK_DEFINE_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_fwrite)(benchmark::State& state)
634+ {
635+ while (state.KeepRunning ()) {
636+ std::string name;
637+ name += " test_function" ;
638+
639+ std::ostringstream args;
640+
641+ uint64_t threadId = GET_THREAD_ID ();
642+
643+ using us = std::chrono::microseconds;
644+ uint64_t usStart =
645+ std::chrono::duration_cast<us>(start - global_start).count ();
646+ uint64_t usDelta =
647+ std::chrono::duration_cast<us>(end - start).count ();
648+
649+ int size = CLI_SPRINTF (buffer, BUFFER_SIZE,
650+ " {\" ph\" :\" X\" ,\" pid\" :%" PRIu64 " ,\" tid\" :%" PRIu64 " ,\" name\" :\" %s\" ,\" ts\" :%" PRIu64 " ,\" dur\" :%" PRIu64 " %s},\n " ,
651+ fixture_processId,
652+ threadId,
653+ name.c_str (),
654+ usStart,
655+ usDelta,
656+ args.str ().c_str () );
657+ fwrite (buffer, size, 1 , trace);
658+ }
659+ }
660+ BENCHMARK_REGISTER_F (FILE_fixture, ChromeCallLogging_WithTimes_WithArgs_nospaces_fixturepid_sprintf_fwrite);
661+
447662
448663BENCHMARK_MAIN ();
0 commit comments