@@ -17,6 +17,11 @@ DATADIR = DATAROOTDIR
1717
1818LTTNG_ARCHIVE_SIZE = '50M'
1919LTTNG_ARCHIVE_TIMER = '60s'
20+ # --no-overhead snapshot (flight-recorder) ring-buffer geometry.
21+ # Total RAM per channel ~= subbuf-size * num-subbuf * ncpu (per-uid buffers),
22+ # so these are large on many-core nodes. Tune here if needed.
23+ LTTNG_NO_OVERHEAD_SUBBUF_SIZE = '128M'
24+ LTTNG_NO_OVERHEAD_NUM_SUBBUF = '10'
2025LTTNG_DIRWATCH_SIZE = '500' # In MiB
2126LTTNG_DIRWATCH_LOCK_RETRY_DELAY = 0.1
2227MAX_UINT64_VALUE = ( 2 **64 ) - 1
@@ -280,6 +285,13 @@ def trace_bt_prefix
280285 end
281286end
282287
288+ # `--no-overhead` is exposed as the negatable `--[no-]overhead` switch (default
289+ # on), so `--no-overhead` stores `:overhead => false`. This helper centralizes
290+ # the double negative: true when the user asked for the low-overhead mode.
291+ def no_overhead?
292+ !OPTIONS [ :overhead ]
293+ end
294+
283295# THAPI/xprof use multiple folder
284296# - lttng_trace_dir_tmp
285297# where the 'raw' lttng trace is saved.
@@ -729,12 +741,30 @@ module LocalMaster
729741 FileUtils . mkdir_p ( lttng_home_dir )
730742 FileUtils . mkdir_p ( lttng_trace_dir_tmp )
731743 exec ( 'lttng-sessiond --daemonize' )
732- exec ( "lttng create #{ lttng_session_uuid } -o #{ lttng_trace_dir_tmp } " )
744+ if no_overhead?
745+ # Snapshot (flight-recorder) mode: buffers live only in RAM and are flushed
746+ # to disk once, at teardown (see lttng_teardown_session).
747+ exec ( "lttng create #{ lttng_session_uuid } --snapshot" )
748+ else
749+ exec ( "lttng create #{ lttng_session_uuid } -o #{ lttng_trace_dir_tmp } " )
750+ end
733751
734752 File . write ( File . join ( lttng_trace_dir_tmp , 'thapi_metadata.yaml' ) , { type : 'lttng' } . to_yaml )
735753
736754 channel_name = 'blocking-channel'
737- exec ( "lttng enable-channel --userspace --session=#{ lttng_session_uuid } --blocking-timeout=inf #{ channel_name } " )
755+ if no_overhead?
756+ # Overwrite ring buffers with the periodic switch/read timers disabled: no
757+ # background consumer wake-ups and no disk I/O during execution.
758+ exec ( "lttng enable-channel --userspace --session=#{ lttng_session_uuid } " \
759+ "--overwrite --switch-timer=0 --read-timer=0 " \
760+ "--subbuf-size=#{ LTTNG_NO_OVERHEAD_SUBBUF_SIZE } --num-subbuf=#{ LTTNG_NO_OVERHEAD_NUM_SUBBUF } " \
761+ "#{ channel_name } " )
762+ else
763+ exec ( "lttng enable-channel --userspace --session=#{ lttng_session_uuid } --blocking-timeout=inf #{ channel_name } " )
764+ end
765+ # vpid/vtid are cheap cached values in LTTng-UST and are *required* by THAPI's
766+ # analysis (the interval filter reads them positionally), so keep them even in
767+ # --no-overhead mode.
738768 exec ( "lttng add-context --userspace --session=#{ lttng_session_uuid } --channel=#{ channel_name } -t vpid -t vtid" )
739769
740770 # Enable backend events
@@ -768,6 +798,13 @@ module LocalMaster
768798 end
769799
770800 def lttng_teardown_session
801+ if no_overhead?
802+ # In snapshot mode nothing has been written yet: stop to flush the UST
803+ # ring buffers, then record the single on-disk snapshot into the directory
804+ # babeltrace_thapi reads (it discovers the CTF trace recursively).
805+ exec ( "lttng stop #{ lttng_session_uuid } " )
806+ exec ( "lttng snapshot record --session=#{ lttng_session_uuid } --path=#{ lttng_trace_dir_tmp } " )
807+ end
771808 exec ( "lttng rotate #{ lttng_session_uuid } " ) if OPTIONS [ :archive ]
772809 exec ( "lttng destroy #{ lttng_session_uuid } " )
773810 end
@@ -912,14 +949,20 @@ def all_env_tracers(usr_binary)
912949 h [ "LTTNG_UST_#{ name . upcase } _PROFILE" ] = 1 if OPTIONS [ :profile ]
913950 h [ "LTTNG_UST_#{ name . upcase } _VERBOSE" ] = 1 if LOGGER . level <= Logger ::DEBUG
914951 end
915- # Only support blocking, so lttng doesn't drop messages
916- h [ 'LTTNG_UST_ALLOW_BLOCKING' ] = 1
952+ # Only support blocking, so lttng doesn't drop messages.
953+ # In --no-overhead mode we deliberately use overwrite (non-blocking) buffers,
954+ # so blocking must not be requested.
955+ h [ 'LTTNG_UST_ALLOW_BLOCKING' ] = 1 unless no_overhead?
917956
918957 # Each tracee rank tries to register simultaneously.
919958 # With the default (3s) timeout, ranks that lose the registration race give up
920959 # and run untraced. Block until registration completes instead.
921960 h [ 'LTTNG_UST_REGISTER_TIMEOUT' ] = -1
922961
962+ # Pre-fault (populate) the shared-memory ring-buffer pages at registration so
963+ # tracepoints don't take minor page faults on the hot path at run time.
964+ h [ 'LTTNG_UST_MAP_POPULATE_POLICY' ] = 'cpu_possible' if no_overhead?
965+
923966 # Customization
924967 if OPTIONS [ :'backend-names' ] . include? ( 'ze' )
925968 h [ 'LTTNG_UST_ZE_PARANOID_DRIFT' ] = 1 if OPTIONS [ :profile ]
@@ -1039,6 +1082,15 @@ if $thapi_launch || __FILE__ == $PROGRAM_NAME
10391082 end
10401083 parser . on ( '--[no-]profile' , 'Enable or disable device profiling.' , default : true )
10411084 parser . on ( '--[no-]analysis' , 'Enable or disable analysis of the LTTng trace.' , default : true )
1085+ parser . on ( '--[no-]overhead' ,
1086+ 'Tracing fidelity vs. run-time overhead (default: full fidelity).' ,
1087+ 'Use `--no-overhead` to minimize the run-time distortion of tracing:' ,
1088+ ' * snapshot (flight-recorder) mode: records stay in RAM and are' ,
1089+ ' flushed to disk once, at program exit (no disk I/O while running);' ,
1090+ ' * overwrite ring buffers with switch/read timers disabled;' ,
1091+ ' * pre-fault the trace buffers to avoid run-time page faults.' ,
1092+ 'Trade-off: on long runs the oldest events can be overwritten, giving an' ,
1093+ 'incomplete tally. Incompatible with `--archive`.' , default : true )
10421094
10431095 # General Options
10441096 parser . on ( '-b' , '--backends BACKENDS' , Array , 'Select which backends to use and their grouping level.' ,
@@ -1107,6 +1159,19 @@ if $thapi_launch || __FILE__ == $PROGRAM_NAME
11071159 end
11081160
11091161 options [ :'backend-names' ] = options [ :backends ] . map { |name_level | name_level . split ( ':' ) . first }
1162+
1163+ # `--no-overhead` uses snapshot/overwrite buffers, which is fundamentally
1164+ # incompatible with the rotation-based `--archive` streaming.
1165+ unless options [ :overhead ]
1166+ if options [ :archive ]
1167+ puts ( 'ERROR: --no-overhead is incompatible with --archive (snapshot mode cannot use rotation).' )
1168+ print_help_and_exit ( parser )
1169+ end
1170+ warn ( 'THAPI: --no-overhead uses snapshot/overwrite buffers; on long runs the oldest events ' \
1171+ 'may be overwritten, yielding an incomplete tally. Tune LTTNG_NO_OVERHEAD_SUBBUF_SIZE / ' \
1172+ 'LTTNG_NO_OVERHEAD_NUM_SUBBUF if needed.' )
1173+ end
1174+
11101175 OPTIONS = options . freeze
11111176
11121177 if ( launcher = %w[ mpirun mpiexec ] . find { |b | ARGV . include? ( b ) } )
0 commit comments