From c2add4bc1431ba56f4e7a7e557374e00225077f0 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 6 Nov 2020 11:50:47 -0500 Subject: [PATCH] Simplify calling TraceWrite and consistently check its return value. --- client/TracySysTrace.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 10795432..a7b36d36 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -841,28 +841,34 @@ static bool TraceWrite( const char* path, size_t psz, const char* val, size_t vs return true; } +template +static bool TraceWrite( const char (&path)[path_size], const char* val, size_t vsz ) +{ + return TraceWrite(path, path_size, val, vsz); +} + bool SysTraceStart( int64_t& samplingPeriod ) { #ifndef CLOCK_MONOTONIC_RAW return false; #endif - if( !TraceWrite( TracingOn, sizeof( TracingOn ), "0", 2 ) ) return false; - if( !TraceWrite( CurrentTracer, sizeof( CurrentTracer ), "nop", 4 ) ) return false; - TraceWrite( TraceOptions, sizeof( TraceOptions ), "norecord-cmd", 13 ); - TraceWrite( TraceOptions, sizeof( TraceOptions ), "norecord-tgid", 14 ); - TraceWrite( TraceOptions, sizeof( TraceOptions ), "noirq-info", 11 ); - TraceWrite( TraceOptions, sizeof( TraceOptions ), "noannotate", 11 ); + if( !TraceWrite( TracingOn, "0", 2 ) ) return false; + if( !TraceWrite( CurrentTracer, "nop", 4 ) ) return false; + if( !TraceWrite( TraceOptions, "norecord-cmd", 13 ) ) return false; + if( !TraceWrite( TraceOptions, "norecord-tgid", 14 ) ) return false; + if( !TraceWrite( TraceOptions, "noirq-info", 11 ) ) return false; + if( !TraceWrite( TraceOptions, "noannotate", 11 ) ) return false; #if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) - if( !TraceWrite( TraceClock, sizeof( TraceClock ), "x86-tsc", 8 ) ) return false; + if( !TraceWrite( TraceClock, "x86-tsc", 8 ) ) return false; #else - if( !TraceWrite( TraceClock, sizeof( TraceClock ), "mono_raw", 9 ) ) return false; + if( !TraceWrite( TraceClock, "mono_raw", 9 ) ) return false; #endif - if( !TraceWrite( SchedSwitch, sizeof( SchedSwitch ), "1", 2 ) ) return false; - if( !TraceWrite( SchedWakeup, sizeof( SchedWakeup ), "1", 2 ) ) return false; - if( !TraceWrite( BufferSizeKb, sizeof( BufferSizeKb ), "4096", 5 ) ) return false; + if( !TraceWrite( SchedSwitch, "1", 2 ) ) return false; + if( !TraceWrite( SchedWakeup, "1", 2 ) ) return false; + if( !TraceWrite( BufferSizeKb, "4096", 5 ) ) return false; - if( !TraceWrite( TracingOn, sizeof( TracingOn ), "1", 2 ) ) return false; + if( !TraceWrite( TracingOn, "1", 2 ) ) return false; traceActive.store( true, std::memory_order_relaxed ); SetupSampling( samplingPeriod );