Skip to content

Commit

Permalink
Enable base tracing (#3068)
Browse files Browse the repository at this point in the history
b/330561515
  • Loading branch information
andrewsavage1 committed May 15, 2024
1 parent c234cf2 commit 250bb49
Show file tree
Hide file tree
Showing 2,321 changed files with 1,402,625 additions and 267 deletions.
38 changes: 16 additions & 22 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if (false) {
group("default") {
deps = [ "//net" ]
}
} else {
group("gn_all") {
testonly = true
group("gn_all") {
testonly = true

deps = [
"//cobalt:gn_all",
"//starboard:gn_all",
]
}
deps = [
"//cobalt:gn_all",
"//starboard:gn_all",
]
}

group("default") {
testonly = true
group("default") {
testonly = true

if (is_qa || is_gold) {
deps = [
"//cobalt:default",
"//starboard:default",
]
} else {
deps = [ ":gn_all" ]
}
if (is_qa || is_gold) {
deps = [
"//cobalt:default",
"//starboard:default",
]
} else {
deps = [ ":gn_all" ]
}
}
19 changes: 14 additions & 5 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,6 @@ component("base") {
"time/time_now_starboard.cc",
"time/time_starboard.cc",
]
# Needed for at least //url/gurl.cc until enable_base_tracing = true.
sources += [ "trace_event/memory_usage_estimator.cc" ]
}

# Various files that are unused in the Chromium build, but presumably here to
Expand Down Expand Up @@ -2463,6 +2461,9 @@ component("base") {
"tracing/tracing_tls.cc",
"tracing/tracing_tls.h",
]
if (use_cobalt_customizations && use_xcode_clang) {
defines = [ "USES_XCODE_CLANG" ]
}

public_deps += [
"//base/tracing/protos:chrome_track_event_zero",
Expand All @@ -2479,7 +2480,7 @@ component("base") {
"//third_party/perfetto/gn:public_config",
]

if (is_win) {
if (is_win && !is_starboard) {
sources += [
"trace_event/trace_event_etw_export_win.cc",
"trace_event/trace_event_etw_export_win.h",
Expand All @@ -2488,7 +2489,7 @@ component("base") {
]
}

if (is_android) {
if (is_android && !is_starboard) {
sources += [
"trace_event/application_state_proto_android.cc",
"trace_event/application_state_proto_android.h",
Expand Down Expand Up @@ -4204,7 +4205,15 @@ test("base_unittests") {
"tracing/perfetto_task_runner_unittest.cc",
]

if (is_android) {
if (cobalt_pending_clean_up) {
sources -= [
"trace_event/memory_allocator_dump_unittest.cc",
"trace_event/process_memory_dump_unittest.cc",
"trace_event/typed_macros_unittest.cc",
]
}

if (is_android && !is_starboard) {
sources += [
"trace_event/cpufreq_monitor_android_unittest.cc",
"trace_event/java_heap_dump_provider_android_unittest.cc",
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ TEST(FileTest, DuplicateDeleteOnClose) {
}
#endif

#if BUILDFLAG(ENABLE_BASE_TRACING)
#if BUILDFLAG(ENABLE_BASE_TRACING) && !defined(STARBOARD)
TEST(FileTest, TracedValueSupport) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
Expand Down
6 changes: 4 additions & 2 deletions base/sampling_heap_profiler/sampling_heap_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ const char* UpdateAndGetThreadName(const char* name) {

pthread_once(&s_once_flag, InitThreadLocalKey);

const char* thread_name = static_cast<const char*>(pthread_getspecific(s_thread_local_key));
const char* thread_name =
static_cast<const char*>(pthread_getspecific(s_thread_local_key));
if (name)
pthread_setspecific(s_thread_local_key, const_cast<char*>(name));
else if (!thread_name)
pthread_setspecific(s_thread_local_key, const_cast<char*>(GetAndLeakThreadName()));
pthread_setspecific(s_thread_local_key,
const_cast<char*>(GetAndLeakThreadName()));
return static_cast<const char*>(pthread_getspecific(s_thread_local_key));
#else
static thread_local const char* thread_name;
Expand Down
5 changes: 5 additions & 0 deletions base/task/sequence_manager/thread_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,13 @@ class BASE_EXPORT ThreadController {
[[maybe_unused]] const raw_ref<const ThreadController> outer_;

#if BUILDFLAG(ENABLE_BASE_TRACING)
#if defined(STARBOARD)
TerminatingFlowLambda terminating_wakeup_lambda_{
perfetto::TerminatingFlow::FromPointer(const_cast<RunLevelTracker*>(this))};
#else
TerminatingFlowLambda terminating_wakeup_lambda_{
perfetto::TerminatingFlow::FromPointer(this)};
#endif
#endif

std::stack<RunLevel, std::vector<RunLevel>> run_levels_
Expand Down
4 changes: 2 additions & 2 deletions base/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static_library("test_support") {

if (enable_base_tracing) {
public_deps += [ "//third_party/perfetto:perfetto_test_support" ]
if (!is_chromeos) {
if (!is_chromeos && !is_starboard) {
# TODO(rasikan): Add to ios and chromeos when unblocked by the chromiumos
# change to add the shared lib to the chrome-binary-tests directory.
public_deps += [ ":test_trace_processor" ]
Expand Down Expand Up @@ -522,7 +522,7 @@ executable("test_child_process") {
}
}

if (enable_base_tracing) {
if (enable_base_tracing && !use_cobalt_customizations) {
# We encapsulate the trace processor in a separate shared library to prevent
# any duplicate symbol issues. Perfetto symbols are exported by chromium’s
# base via a public_dep on libperfetto; libtrace_processor also depends on
Expand Down
33 changes: 32 additions & 1 deletion base/trace_event/builtin_categories.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,38 @@
X(TRACE_DISABLED_BY_DEFAULT("webgpu")) \
X(TRACE_DISABLED_BY_DEFAULT("webrtc")) \
X(TRACE_DISABLED_BY_DEFAULT("worker.scheduler")) \
X(TRACE_DISABLED_BY_DEFAULT("xr.debug"))
X(TRACE_DISABLED_BY_DEFAULT("xr.debug")) \
X("cobalt::cssom") \
X("cobalt::storage") \
X("cobalt::script") \
X("cobalt::renderer") \
X("cobalt::renderer_sandbox") \
X("cobalt::network") \
X("cobalt::overlay_info") \
X("cobalt::css_parser") \
X("renderer::test::png_utils") \
X("base::task_runner_util") \
X("cobalt::audio") \
X("cobalt::browser") \
X("cobalt::dom::eme") \
X("cobalt::base") \
X("cobalt::dom") \
X("cobalt::worker") \
X("cobalt::loader") \
X("cobalt::layout") \
X("cobalt::Screencast") \
X("cobalt::web") \
X("cobalt::media") \
X("cobalt::loader::image") \
X("media") \
X("media_stream") \
X("cobalt::webdriver") \
X("cobalt::Webdriver") \
X("cobalt::WebDriver") \
X("media_stack") \
X("cobalt::loader::image_decoder") \
X("cobalt::h5vcc::trace_event") \
X("net::dial")

#define INTERNAL_TRACE_LIST_BUILTIN_CATEGORY_GROUPS(X) \
X("android_webview,toplevel") \
Expand Down
20 changes: 19 additions & 1 deletion base/trace_event/common/trace_event_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ struct BASE_EXPORT TraceTimestampTraits<::base::TimeTicks> {

// Check that nobody includes this file directly. Clients are supposed to
// include the surrounding "trace_event.h" of their project instead.
#if defined(TRACE_EVENT0) && 0
#if defined(TRACE_EVENT0)
#error "Another copy of this file has already been included."
#endif

Expand Down Expand Up @@ -388,6 +388,15 @@ struct BASE_EXPORT TraceTimestampTraits<::base::TimeTicks> {
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)

#if defined(COBALT_PENDING_CLEAN_UP)
#define TRACE_EVENT_COPY_BEGIN0(category_group, name) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
#endif

// Similar to TRACE_EVENT_BEGINx but with a custom |timestamp| provided.
// - |id| is used to match the _BEGIN event with the _END event.
// Events are considered to match if their category_group, name and id values
Expand Down Expand Up @@ -451,6 +460,15 @@ struct BASE_EXPORT TraceTimestampTraits<::base::TimeTicks> {
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)

#if defined(COBALT_PENDING_CLEAN_UP)
#define TRACE_EVENT_COPY_END0(category_group, name) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
#endif

// Adds a trace event with the given |name| and |timestamp|. |timestamp| must be
// non-null or it crashes. Use DCHECK(timestamp) before calling this to detect
// an invalid timestamp even when tracing is not enabled, as the commit queue
Expand Down
8 changes: 5 additions & 3 deletions base/trace_event/malloc_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "base/trace_event/traced_value.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_APPLE)
#if defined(STARBOARD)
#include <stdlib.h>
#elif BUILDFLAG(IS_APPLE)
#include <malloc/malloc.h>
#else
#include <malloc.h>
Expand Down Expand Up @@ -187,7 +189,7 @@ void ReportAppleAllocStats(size_t* total_virtual_size,

#if (BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && BUILDFLAG(IS_ANDROID)) || \
(!BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && !BUILDFLAG(IS_WIN) && \
!BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA))
!BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA) && !defined(STARBOARD))
void ReportMallinfoStats(ProcessMemoryDump* pmd,
size_t* total_virtual_size,
size_t* resident_size,
Expand Down Expand Up @@ -356,7 +358,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
ReportWinHeapStats(args.level_of_detail, nullptr, &total_virtual_size,
&resident_size, &allocated_objects_size,
&allocated_objects_count);
#elif BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_FUCHSIA) || defined(STARBOARD)
// TODO(fuchsia): Port, see https://crbug.com/706592.
#else
ReportMallinfoStats(/*pmd=*/nullptr, &total_virtual_size, &resident_size,
Expand Down
17 changes: 3 additions & 14 deletions base/trace_event/trace_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
#include "base/memory/raw_ptr_exclusion.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/tracing_buildflags.h"
#ifndef COBALT_PENDING_CLEAN_UP
#include "third_party/perfetto/include/perfetto/protozero/scattered_heap_buffer.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/debug_annotation.pbzero.h"
#endif

// Trace macro can have one or two optional arguments, each one of them
// identified by a name (a C string literal) and a value, which can be an
Expand Down Expand Up @@ -235,10 +233,8 @@ union BASE_EXPORT TraceValue {
RAW_PTR_EXCLUSION ConvertableToTraceFormat* as_convertable;
// This field is not a raw_ptr<> because it was filtered by the rewriter for:
// #union
#ifndef COBALT_PENDING_CLEAN_UP
RAW_PTR_EXCLUSION protozero::HeapBuffered<
perfetto::protos::pbzero::DebugAnnotation>* as_proto;
#endif

// Static method to create a new TraceValue instance from a given
// initialization value. Note that this deduces the TRACE_VALUE_TYPE_XXX
Expand Down Expand Up @@ -271,6 +267,9 @@ union BASE_EXPORT TraceValue {
private:
void Append(unsigned char type, bool as_json, std::string* out) const;

#if defined(STARBOARD)
public:
#endif
// InnerType<T>::type removes reference, cv-qualifications and decays
// function and arrays into pointers. Only used internally.
template <typename T>
Expand Down Expand Up @@ -348,7 +347,6 @@ union BASE_EXPORT TraceValue {
using ValueType = typename InnerType<T>::type;
static const unsigned char value = Helper<ValueType>::kType;
};
#ifndef COBALT_PENDING_CLEAN_UP
template <typename T>
struct TypeFor<T,
typename std::enable_if<
Expand All @@ -357,21 +355,16 @@ union BASE_EXPORT TraceValue {
typename InnerType<T>::type>::value>::type> {
static const unsigned char value = TRACE_VALUE_TYPE_PROTO;
};
#endif

// TraceValue::TypeCheck<T>::value is only defined iff T can be used to
// initialize a TraceValue instance. This is useful to restrict template
// instantiation to only the appropriate type (see TraceArguments
// constructors below).
#ifndef COBALT_PENDING_CLEAN_UP
template <typename T,
class = std::enable_if_t<
HasHelperSupport<typename InnerType<T>::type>::value ||
perfetto::internal::has_traced_value_support<
typename InnerType<T>::type>::value>>
#else
template <typename T>
#endif
struct TypeCheck {
static const bool value = true;
};
Expand All @@ -397,7 +390,6 @@ union BASE_EXPORT TraceValue {
Helper<ValueType>::SetValue(this, std::forward<T>(value));
}

#ifndef COBALT_PENDING_CLEAN_UP
template <class T>
typename std::enable_if<
!HasHelperSupport<typename InnerType<T>::type>::value &&
Expand All @@ -410,7 +402,6 @@ union BASE_EXPORT TraceValue {
perfetto::internal::CreateTracedValueFromProto(as_proto->get()),
std::forward<T>(value));
}
#endif
};

// TraceValue::Helper for integers and enums.
Expand Down Expand Up @@ -710,10 +701,8 @@ class BASE_EXPORT TraceArguments {
for (size_t n = 0; n < size_; ++n) {
if (types_[n] == TRACE_VALUE_TYPE_CONVERTABLE)
delete values_[n].as_convertable;
#ifndef COBALT_PENDING_CLEAN_UP
if (types_[n] == TRACE_VALUE_TYPE_PROTO)
delete values_[n].as_proto;
#endif
}
}

Expand Down

0 comments on commit 250bb49

Please sign in to comment.