Merge pull request #2418 from deepak1556/content_tracing_api_patch
tracing: fix api and docs
This commit is contained in:
commit
1c4f50b2df
3 changed files with 50 additions and 18 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
|
#include "base/files/file_util.h"
|
||||||
#include "content/public/browser/tracing_controller.h"
|
#include "content/public/browser/tracing_controller.h"
|
||||||
#include "native_mate/callback.h"
|
#include "native_mate/callback.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
@ -46,6 +47,31 @@ struct Converter<base::trace_event::TraceOptions> {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using CompletionCallback = base::Callback<void(const base::FilePath&)>;
|
||||||
|
|
||||||
|
scoped_refptr<TracingController::TraceDataSink> GetTraceDataSink(
|
||||||
|
const base::FilePath& path, const CompletionCallback& callback) {
|
||||||
|
base::FilePath result_file_path = path;
|
||||||
|
if (result_file_path.empty() && !base::CreateTemporaryFile(&result_file_path))
|
||||||
|
LOG(ERROR) << "Creating temporary file failed";
|
||||||
|
|
||||||
|
return TracingController::CreateFileSink(result_file_path,
|
||||||
|
base::Bind(callback,
|
||||||
|
result_file_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopRecording(const base::FilePath& path,
|
||||||
|
const CompletionCallback& callback) {
|
||||||
|
TracingController::GetInstance()->DisableRecording(
|
||||||
|
GetTraceDataSink(path, callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CaptureMonitoringSnapshot(const base::FilePath& path,
|
||||||
|
const CompletionCallback& callback) {
|
||||||
|
TracingController::GetInstance()->CaptureMonitoringSnapshot(
|
||||||
|
GetTraceDataSink(path, callback));
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
auto controller = base::Unretained(TracingController::GetInstance());
|
auto controller = base::Unretained(TracingController::GetInstance());
|
||||||
|
@ -54,14 +80,12 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
&TracingController::GetCategories, controller));
|
&TracingController::GetCategories, controller));
|
||||||
dict.SetMethod("startRecording", base::Bind(
|
dict.SetMethod("startRecording", base::Bind(
|
||||||
&TracingController::EnableRecording, controller));
|
&TracingController::EnableRecording, controller));
|
||||||
dict.SetMethod("stopRecording", base::Bind(
|
dict.SetMethod("stopRecording", &StopRecording);
|
||||||
&TracingController::DisableRecording, controller, nullptr));
|
|
||||||
dict.SetMethod("startMonitoring", base::Bind(
|
dict.SetMethod("startMonitoring", base::Bind(
|
||||||
&TracingController::EnableMonitoring, controller));
|
&TracingController::EnableMonitoring, controller));
|
||||||
dict.SetMethod("stopMonitoring", base::Bind(
|
dict.SetMethod("stopMonitoring", base::Bind(
|
||||||
&TracingController::DisableMonitoring, controller));
|
&TracingController::DisableMonitoring, controller));
|
||||||
dict.SetMethod("captureMonitoringSnapshot", base::Bind(
|
dict.SetMethod("captureMonitoringSnapshot", &CaptureMonitoringSnapshot);
|
||||||
&TracingController::CaptureMonitoringSnapshot, controller, nullptr));
|
|
||||||
dict.SetMethod("getTraceBufferUsage", base::Bind(
|
dict.SetMethod("getTraceBufferUsage", base::Bind(
|
||||||
&TracingController::GetTraceBufferUsage, controller));
|
&TracingController::GetTraceBufferUsage, controller));
|
||||||
dict.SetMethod("setWatchEvent", base::Bind(
|
dict.SetMethod("setWatchEvent", base::Bind(
|
||||||
|
|
|
@ -1,7 +1 @@
|
||||||
module.exports = process.atomBinding 'content_tracing'
|
module.exports = process.atomBinding 'content_tracing'
|
||||||
|
|
||||||
# Mirrored from content::TracingController::Options
|
|
||||||
module.exports.DEFAULT_OPTIONS = 0
|
|
||||||
module.exports.ENABLE_SYSTRACE = 1 << 0
|
|
||||||
module.exports.ENABLE_SAMPLING = 1 << 1
|
|
||||||
module.exports.RECORD_CONTINUOUSLY = 1 << 2
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ are reached.
|
||||||
Once all child processes have acked to the `getCategories` request, `callback`
|
Once all child processes have acked to the `getCategories` request, `callback`
|
||||||
is invoked with an array of category groups.
|
is invoked with an array of category groups.
|
||||||
|
|
||||||
## tracing.startRecording(categoryFilter, options, callback)
|
## tracing.startRecording(categoryFilter, traceOptions, callback)
|
||||||
|
|
||||||
* `categoryFilter` String
|
* `categoryFilter` String
|
||||||
* `options` Integer
|
* `traceOptions` String
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
||||||
Start recording on all processes.
|
Start recording on all processes.
|
||||||
|
@ -51,9 +51,23 @@ Examples:
|
||||||
* `test_MyTest*,test_OtherStuff`,
|
* `test_MyTest*,test_OtherStuff`,
|
||||||
* `"-excluded_category1,-excluded_category2`
|
* `"-excluded_category1,-excluded_category2`
|
||||||
|
|
||||||
`options` controls what kind of tracing is enabled, it could be a OR-ed
|
`traceOptions` controls what kind of tracing is enabled, it is a comma-delimited list.
|
||||||
combination of `tracing.DEFAULT_OPTIONS`, `tracing.ENABLE_SYSTRACE`,
|
Possible options are:
|
||||||
`tracing.ENABLE_SAMPLING` and `tracing.RECORD_CONTINUOUSLY`.
|
|
||||||
|
* `record-until-full`
|
||||||
|
* `record-continuously`
|
||||||
|
* `trace-to-console`
|
||||||
|
* `enable-sampling`
|
||||||
|
* `enable-systrace`
|
||||||
|
|
||||||
|
The first 3 options are trace recoding modes and hence mutually exclusive.
|
||||||
|
If more than one trace recording modes appear in the `traceOptions` string,
|
||||||
|
the last one takes precedence. If none of the trace recording mode is specified,
|
||||||
|
recording mode is `record-until-full`.
|
||||||
|
|
||||||
|
The trace option will first be reset to the default option (record_mode set to
|
||||||
|
`record-until-full`, enable_sampling and enable_systrace set to false)
|
||||||
|
before options parsed from `traceOptions` are applied on it.
|
||||||
|
|
||||||
## tracing.stopRecording(resultFilePath, callback)
|
## tracing.stopRecording(resultFilePath, callback)
|
||||||
|
|
||||||
|
@ -75,10 +89,10 @@ Trace data will be written into `resultFilePath` if it is not empty, or into a
|
||||||
temporary file. The actual file path will be passed to `callback` if it's not
|
temporary file. The actual file path will be passed to `callback` if it's not
|
||||||
null.
|
null.
|
||||||
|
|
||||||
## tracing.startMonitoring(categoryFilter, options, callback)
|
## tracing.startMonitoring(categoryFilter, traceOptions, callback)
|
||||||
|
|
||||||
* `categoryFilter` String
|
* `categoryFilter` String
|
||||||
* `options` Integer
|
* `traceOptions` String
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
||||||
Start monitoring on all processes.
|
Start monitoring on all processes.
|
||||||
|
@ -107,7 +121,7 @@ Get the current monitoring traced data.
|
||||||
|
|
||||||
Child processes typically are caching trace data and only rarely flush and send
|
Child processes typically are caching trace data and only rarely flush and send
|
||||||
trace data back to the main process. That is because it may be an expensive
|
trace data back to the main process. That is because it may be an expensive
|
||||||
operation to send the trace data over IPC, and we would like to avoid unneeded
|
operation to send the trace data over IPC, and we would like to avoid unneeded
|
||||||
runtime overhead of tracing. So, to end tracing, we must asynchronously ask all
|
runtime overhead of tracing. So, to end tracing, we must asynchronously ask all
|
||||||
child processes to flush any pending trace data.
|
child processes to flush any pending trace data.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue