Skip to content

Commit

Permalink
[tracing] OPTIONAL_TRACE_EVENT
Browse files Browse the repository at this point in the history
Add OPTIONAL_TRACE_EVENT{0,1,2} macros. They are equivalent to regular
TRACE_EVENTs, but they are disabled by default on the platforms where
binary size is a significant factor.

R=eseckler@chromium.org
BUG=1043616

Change-Id: Ifb4265856826423c5079c5d412fc1234db19e820
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359132
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800770}
  • Loading branch information
Alexander Timin authored and Commit Bot committed Aug 21, 2020
1 parent c37fddb commit a63ce7f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# huge sequence of random-looking conditionals.

import("//base/allocator/allocator.gni")
import("//base/trace_event/tracing.gni")
import("//build/buildflag_header.gni")
import("//build/config/allocator.gni")
import("//build/config/arm.gni")
Expand Down Expand Up @@ -2106,6 +2107,7 @@ component("base") {
"trace_event/memory_infra_background_allowlist.h",
"trace_event/memory_usage_estimator.cc",
"trace_event/memory_usage_estimator.h",
"trace_event/optional_trace_event.h",
"trace_event/process_memory_dump.cc",
"trace_event/process_memory_dump.h",
"trace_event/thread_instruction_count.cc",
Expand Down Expand Up @@ -2298,6 +2300,7 @@ buildflag_header("tracing_buildflags") {
flags = [
"ENABLE_BASE_TRACING=$enable_base_tracing",
"USE_PERFETTO_CLIENT_LIBRARY=$use_perfetto_client_library",
"OPTIONAL_TRACE_EVENTS_ENABLED=$optional_trace_events_enabled",
]
}

Expand Down
31 changes: 31 additions & 0 deletions base/trace_event/optional_trace_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_TRACE_EVENT_OPTIONAL_TRACE_EVENT_H_
#define BASE_TRACE_EVENT_OPTIONAL_TRACE_EVENT_H_

#include "base/trace_event/trace_event.h"
#include "base/tracing_buildflags.h"
#include "build/buildflag.h"

// These macros are functionally equivalent to TRACE_EVENTX macros,
// but they are disabled if optional_trace_events_enabled gn flag
// defined in tracing.gni is false.

#if BUILDFLAG(OPTIONAL_TRACE_EVENTS_ENABLED)

#define OPTIONAL_TRACE_EVENT0(...) TRACE_EVENT0(__VA_ARGS__)
#define OPTIONAL_TRACE_EVENT1(...) TRACE_EVENT1(__VA_ARGS__)
#define OPTIONAL_TRACE_EVENT2(...) TRACE_EVENT2(__VA_ARGS__)

#else // BUILDFLAG(OPTIONAL_TRACE_EVENTS_ENABLED)

#define OPTIONAL_TRACE_EVENT0(category, name)
#define OPTIONAL_TRACE_EVENT1(category, name, arg1_name, arg1_val)
#define OPTIONAL_TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val)

#endif // BUILDFLAG(OPTIONAL_TRACE_EVENTS_ENABLED)

#endif // BASE_TRACE_EVENT_OPTIONAL_TRACE_EVENT_H_
20 changes: 20 additions & 0 deletions base/trace_event/tracing.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chrome_build.gni")

declare_args() {
# Enable more trace events. Disabled by default due to binary size impact,
# but highly recommended for local development.
extended_tracing_enabled = false
}

# Separate block so that we can refer to extended_tracing_enabled's value.
declare_args() {
# Whether OPTIONAL_TRACE_EVENT macros are included in the build or not.
# Disabled by default on Android and ChromeOS due to binary size impact,
# enabled everywhere else.
optional_trace_events_enabled =
(!is_android && !is_chromeos) || extended_tracing_enabled
}

0 comments on commit a63ce7f

Please sign in to comment.