Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron contentTracing module


May 25, 2021 Electron


Table of contents


content-tracing module is used to collect search data generated by the underlying Chrome content module. This module does not have a web interface and all that requires us to chrome://tracing/ chrome browser to load the generated file to see the results.

const contentTracing = require('electron').contentTracing;

const options = {
  categoryFilter: '*',
  traceOptions: 'record-until-full,enable-sampling'
}

contentTracing.startRecording(options, function() {
  console.log('Tracing started');

  setTimeout(function() {
    contentTracing.stopRecording('', function(path) {
      console.log('Tracing data recorded to ' + path);
    });
  }, 5000);
});

Method

content-tracing module works:

contentTracing.getCategories(callback)

  • callback Function

Get a group of categories. The classification group can be changed to a new code path.

Once all child processes have accepted getCategories request, the classification group calls callback .

contentTracing.startRecording(options, callback)

  • options Object
    • categoryFilter String
    • traceOptions String
  • callback Function

Start recording all processes. (recording)

Once a request is received that can start recording, the record will start immediately and the sub-process is asynchronous record listening. When all child processes startRecording callback will be called.

categoryFilter a filter that controls which classification groups should be used to find. T he filter should have an optional - to exclude matching classification groups. The same list is not allowed to be both contained and excluded.

Example:

  • test_MyTest* ,
  • test_MyTest*,test_OtherStuff ,
  • "-excluded_category1,-excluded_category2

traceOptions which lookup should be started and this is a comma-separated list. The available parameters are as follows:

  • record-until-full
  • record-continuously
  • trace-to-console
  • enable-sampling
  • enable-systrace

The first 3 parameters are to find the record module and are mutually exclusive later. I f there is more than one trace record mode in traceOptions the last one has the highest priority. If the trace record mode is not indicated, it record-until-full .

Until traceOptions the find parameter initialization record_mode is set to record-until-full enable_sampling and enable_sampling enable_systrace false ).

contentTracing.stopRecording(resultFilePath, callback)

  • resultFilePath String
  • callback Function

Stop recording all child processes.

Sub-processes usually cache looking for data and only intercept and send it to the main process. T his is valuable for reducing the running overhead of lookups before sending lookup data through IPC. Therefore, to send lookup data, we should notify all child processes asynchronously to intercept any data to be found.

Once all child processes receive the stopRecording callback and a file containing the data is returned.

If resultFilePath not empty, the lookup data will be written to it or a temporary file will be written. If the actual file path is not empty, callback .

contentTracing.startMonitoring(options, callback)

  • options Object
    • categoryFilter String
    • traceOptions String
  • callback Function

Start listening to all processes. (monitoring)

Once a request is received that you can start listening, the record will start immediately and the child process will be asynchronous. When all child processes startMonitoring callback will be called.

contentTracing.stopMonitoring(callback)

  • callback Function

Stop listening to all child processes.

Once all child processes receive stopMonitoring callback .

contentTracing.captureMonitoringSnapshot(resultFilePath, callback)

  • resultFilePath String
  • callback Function

Gets the lookup data for the current listening.

Sub-processes usually cache looking for data and only intercept and send it to the main process. B ecause if sending lookup data directly through IPC is expensive, we'd rather avoid unnecessary lookup running overhead. Therefore, in order to stop the lookup, we should asynchronously notify all child processes to intercept any data to be found.

Once all sub-processes receive the captureMonitoringSnapshot callback and a file containing the data is returned.

contentTracing.getTraceBufferUsage(callback)

  • callback Function

Get the maximum percentage usage by looking for the buffer process. Callback is called when the value of TraceBufferUsage is callback .

contentTracing.setWatchEvent(categoryName, eventName, callback)

  • categoryName String
  • eventName String
  • callback Function

Callback is called at any time when an event is specified on callback .

contentTracing.cancelWatchEvent()

Cancel the watch event. If you start the lookup, this may cause an error in the callback function of the watch event.