ibec_StartTraceSession

ibec_StartTraceSession starts a trace session using Firebird Services API and writes trace data into a file. Additional filtering of trace items is possible via callback block.

This IBEBlock function was updated in IBExpert version 2022.11.14.

Description

No additional description…

Syntax

  function ibec_StartTraceSession(ConnectParams : string; TraceConfig : string; OutputFile : string;
                              FilterBlock : variant; ProgressBlock : variant) : variant;

ConnectParams - list of connection params and some additional options delimited with semicolon:

TraceConfig - Firebird trace configuration

OutputFile - name of a result file which will contain trace data

FilterBlock - a callback block which performs additional filtering of trace items if necessary. This block is called for every trace item and accepts a trace item text as input parameter (EventSource). The output parameter NeedSkip determines whether the trace item should be skipped i.e. not included into the result file.

Support of a second input parameter has beeb added both to filter and progress blocks:

If no additional filtering is needed pass NULL or an empty string as FilterBlock value.

ProgressBlock - a callback block that is intended to display progress of tracing. It receives array of some statistical data:

The output parameter Threshold determines a delay in milliseconds before next call of ProgressBlock.

ibec_StartTraceSession returns NULL if a trace session is started successfully, otherwise it returns error message as a result.

TraceAPI.GetActiveTraceSessions function: By default (the Options param is NULL or contains unknown data) returns a number of active trace sessions. If the Return=NamesList option is specified, it will return a comma-delimited list of names of active trace sessions.

TraceAPI namespace: contains two functions and some constants. TraceAPI.StartTraceSession is just an alias for the ibec_StartTraceSession function.

Earlier implementations of the ibec_StartTraceSession function didn't return an error message if there was something wrong. This is now fixed.

Example

This example can be executed from within the IBExpert GUI, it doesn't freeze IBExpert.

execute ibeblock
as

  -- Filter block
  declare ibeblock filter_block (EventData variant, SessionData variant)
  returns (
    NeedSkip boolean)
  as
  begin
    NeedSkip = EventData[@TraceAPI.TED_EVENT_TYPE] = 'START_TRANSACTION';  -- Event type
    if (not NeedSkip) then
      NeedSkip = EventData[@TraceAPI.TED_DURATION] <= 0;
  end;

  -- Progress block
  declare ibeblock progress_block (data variant, SessionData variant)
  returns (
    threshold integer = 1000)
  as
  begin
    threshold = 1000;
    for i = 0 to ibec_High(data) do
      data[i] = ibec_Cast(data[i], __typeString);

    s = ibec_Format('| %15.15s | %16.16s | %14.14s | %16.16s |', data[0], data['EventsProcessed'], data['EventsMatched'], data['OutputSize']);
    ibec_ProgressEx(s, __poNoCRLF + __poReplaceLast);
  end;

begin
  sConfig = ibec_LoadFromFile('D:\temp\trace.conf');
  sOutFile = 'D:\Temp\tracedata.txt';
  sServer = 'avx-dell/3053';
  sClientLib = '"D:\Projects_5\IBExpert\ClientLibs\fbclient_30.dll"';


  Res = @TraceAPI.StartTraceSession('Server=' || sServer || ';
                                     User=SYSDBA; Password=masterkey;
                                     ClientLib=' || sClientLib || ';
                                     MaxFileSize=10; StopAfter=10; IncludeStatistics; ParseData; NoWait',
                                :sConfig,
                                :sOutFile,
                                filter_block,
                                progress_block);

  if (Res is not null) then  -- Error caused
    ibec_ShowMessage('ERROR: ' || Res);
  else
  begin
    iTime1 = ibec_GetTickCount();
    ibec_Progress('Trace session started');
    ibec_Progress('+-----------------+------------------+----------------+------------------+');
    ibec_Progress('| Lines processed | Events processed | Events matched | Output file size |');
    ibec_Progress('+-----------------+------------------+----------------+------------------+');
  end;

  while (@TraceAPI.GetActiveTraceSessions('Return=NamesList') <> '') do
  --while (@TraceAPI.GetActiveTraceSessions('') > 0) do
  begin
    -- ibec_Pause should be used instead of ibec_Sleep here
    ibec_Pause(2000);
  end;

  iTime2 = ibec_GetTickCount();
  sSessionTime = ibec_FormatFloat('0.00', (iTime2 - iTime1) / 1000 / 60);
 
  ibec_Progress('');
  ibec_Progress('+-----------------+------------------+----------------+------------------+');
  ibec_Progress('Session was active ' || sSessionTime || ' minutes');
  ibec_Progress('That''s all, folks!');
end;                             

Further information and examples here: White Paper: ibec_StartTraceSession