diff --git a/devtools/client/performance-new/popup/background.jsm.js b/devtools/client/performance-new/popup/background.jsm.js index 7268b6183d9a..7d3b29aea393 100644 --- a/devtools/client/performance-new/popup/background.jsm.js +++ b/devtools/client/performance-new/popup/background.jsm.js @@ -180,35 +180,33 @@ const presets = { media: { entries: 128 * 1024 * 1024, interval: 1, - features: [ - "js", - "leaf", - "stackwalk", - "cpu", - "audiocallbacktracing", - "ipcmessages", - ], + features: ["js", "leaf", "stackwalk", "cpu", "audiocallbacktracing"], threads: [ - "cubeb", - "audio", - "camera", - "capture", + "AsyncCubebTask", + "AudioEncoderQueue", + "AudioIPC", + "call_worker_queue", "Compositor", + "DecodingThread", "GeckoMain", - "gmp", - "graph", - "grph", + "GraphRunner", + "IncomingVideoStream", "InotifyEventThread", - "IPDL Background", - "media", + "libwebrtcModuleThread", + "MediaDecoderStateMachine", + "MediaPDecoder", + "MediaSupervisor", + "MediaTimer", "ModuleProcessThread", + "NativeAudioCallback", "PacerThread", "RemVidChild", "RenderBackend", "Renderer", "Socket Thread", "SwComposite", - "webrtc", + "VoiceProcessThread", + "WebrtcWorker", ], duration: 0, l10nIds: { diff --git a/dom/media/webrtc/libwebrtcglue/TaskQueueWrapper.h b/dom/media/webrtc/libwebrtcglue/TaskQueueWrapper.h index 261664499a26..20f643dcd53a 100644 --- a/dom/media/webrtc/libwebrtcglue/TaskQueueWrapper.h +++ b/dom/media/webrtc/libwebrtcglue/TaskQueueWrapper.h @@ -8,7 +8,6 @@ #include "api/task_queue/task_queue_factory.h" #include "mozilla/DataMutex.h" -#include "mozilla/ProfilerRunnable.h" #include "mozilla/TaskQueue.h" #include "VideoUtils.h" @@ -26,8 +25,8 @@ namespace mozilla { */ class TaskQueueWrapper : public webrtc::TaskQueueBase { public: - TaskQueueWrapper(RefPtr aTaskQueue, nsCString aName) - : mTaskQueue(std::move(aTaskQueue)), mName(std::move(aName)) {} + explicit TaskQueueWrapper(RefPtr aTaskQueue) + : mTaskQueue(std::move(aTaskQueue)) {} ~TaskQueueWrapper() = default; void Delete() override { @@ -45,22 +44,18 @@ class TaskQueueWrapper : public webrtc::TaskQueueBase { already_AddRefed CreateTaskRunner( std::unique_ptr aTask) { - return NS_NewRunnableFunction( - "TaskQueueWrapper::CreateTaskRunner", - [this, task = std::move(aTask), - name = nsPrintfCString("TQ %s: webrtc::QueuedTask", - mName.get())]() mutable { - CurrentTaskQueueSetter current(this); - auto hasShutdown = mHasShutdown.Lock(); - if (*hasShutdown) { - return; - } - AUTO_PROFILE_FOLLOWING_RUNNABLE(name); - bool toDelete = task->Run(); - if (!toDelete) { - task.release(); - } - }); + return NS_NewRunnableFunction("TaskQueueWrapper::CreateTaskRunner", + [this, task = std::move(aTask)]() mutable { + CurrentTaskQueueSetter current(this); + auto hasShutdown = mHasShutdown.Lock(); + if (*hasShutdown) { + return; + } + bool toDelete = task->Run(); + if (!toDelete) { + task.release(); + } + }); } already_AddRefed CreateTaskRunner(nsCOMPtr aRunnable) { @@ -72,7 +67,6 @@ class TaskQueueWrapper : public webrtc::TaskQueueBase { if (*hasShutdown) { return; } - AUTO_PROFILE_FOLLOWING_RUNNABLE(runnable); runnable->Run(); }); } @@ -94,7 +88,6 @@ class TaskQueueWrapper : public webrtc::TaskQueueBase { } const RefPtr mTaskQueue; - const nsCString mName; // This is a recursive mutex because a TaskRunner holding this mutex while // running its runnable may end up running other - tail dispatched - runnables @@ -126,7 +119,7 @@ class SharedThreadPoolWebRtcTaskQueueFactory : public webrtc::TaskQueueFactory { nsCString name(aName.data(), aName.size()); auto taskQueue = MakeRefPtr(GetMediaThreadPool(aThreadType), name.get(), aSupportTailDispatch); - return MakeUnique(std::move(taskQueue), std::move(name)); + return MakeUnique(std::move(taskQueue)); } std::unique_ptr diff --git a/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp b/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp index 17b1c2b10f73..eaddc4b60e1a 100644 --- a/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp +++ b/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp @@ -52,10 +52,8 @@ namespace { class MainAsCurrent : public TaskQueueWrapper { public: MainAsCurrent() - : TaskQueueWrapper( - MakeRefPtr(do_AddRef(GetMainThreadEventTarget()), - "MainAsCurrentTaskQueue"), - "MainAsCurrent"_ns), + : TaskQueueWrapper(MakeRefPtr( + do_AddRef(GetMainThreadEventTarget()), "MainAsCurrentTaskQueue")), mSetter(this) { MOZ_RELEASE_ASSERT(NS_IsMainThread()); } diff --git a/mozglue/baseprofiler/public/ProfileBufferEntrySerialization.h b/mozglue/baseprofiler/public/ProfileBufferEntrySerialization.h index f1be0f7e6f37..6f7a81cefebc 100644 --- a/mozglue/baseprofiler/public/ProfileBufferEntrySerialization.h +++ b/mozglue/baseprofiler/public/ProfileBufferEntrySerialization.h @@ -994,22 +994,9 @@ struct ProfileBufferEntryWriter::Serializer> { template struct ProfileBufferEntryReader::Deserializer> { - template - static void TupleIReadInto(ProfileBufferEntryReader& aER, - std::tuple& aTuple) { - aER.ReadIntoObject(std::get(aTuple)); - } - - template - static void TupleReadInto(ProfileBufferEntryReader& aER, - std::tuple& aTuple, - std::index_sequence) { - (TupleIReadInto(aER, aTuple), ...); - } - static void ReadInto(ProfileBufferEntryReader& aER, std::tuple& aTuple) { - TupleReadInto(aER, aTuple, std::index_sequence_for()); + aER.ReadBytes(&aTuple, Bytes(aTuple)); } static std::tuple Read(ProfileBufferEntryReader& aER) { @@ -1068,20 +1055,8 @@ struct ProfileBufferEntryWriter::Serializer> { template struct ProfileBufferEntryReader::Deserializer> { - template - static void TupleIReadInto(ProfileBufferEntryReader& aER, - Tuple& aTuple) { - aER.ReadIntoObject(Get(aTuple)); - } - - template - static void TupleReadInto(ProfileBufferEntryReader& aER, Tuple& aTuple, - std::index_sequence) { - (TupleIReadInto(aER, aTuple), ...); - } - static void ReadInto(ProfileBufferEntryReader& aER, Tuple& aTuple) { - TupleReadInto(aER, aTuple, std::index_sequence_for()); + aER.ReadBytes(&aTuple, Bytes(aTuple)); } static Tuple Read(ProfileBufferEntryReader& aER) { diff --git a/tools/profiler/core/MicroGeckoProfiler.cpp b/tools/profiler/core/MicroGeckoProfiler.cpp index a045793485bb..f1ba0a47fffa 100644 --- a/tools/profiler/core/MicroGeckoProfiler.cpp +++ b/tools/profiler/core/MicroGeckoProfiler.cpp @@ -4,12 +4,7 @@ #include "GeckoProfiler.h" -#include "mozilla/Maybe.h" -#include "nsPrintfCString.h" -#include "public/GeckoTraceEvent.h" - using namespace mozilla; -using webrtc::trace_event_internal::TraceValueUnion; void uprofiler_register_thread(const char* name, void* stacktop) { #ifdef MOZ_GECKO_PROFILER @@ -23,177 +18,30 @@ void uprofiler_unregister_thread() { #endif // MOZ_GECKO_PROFILER } +// The category string will be handled later in Bug 1715047 +void uprofiler_simple_event_marker(const char* name, const char*, char phase) { #ifdef MOZ_GECKO_PROFILER -namespace { -Maybe ToTiming(char phase) { switch (phase) { case 'B': - return Some(MarkerTiming::IntervalStart()); + profiler_add_marker(ProfilerString8View::WrapNullTerminatedString(name), + geckoprofiler::category::MEDIA_RT, + {MarkerTiming::IntervalStart()}); + break; case 'E': - return Some(MarkerTiming::IntervalEnd()); + profiler_add_marker(ProfilerString8View::WrapNullTerminatedString(name), + geckoprofiler::category::MEDIA_RT, + {MarkerTiming::IntervalEnd()}); + break; case 'I': - return Some(MarkerTiming::InstantNow()); + profiler_add_marker(ProfilerString8View::WrapNullTerminatedString(name), + geckoprofiler::category::MEDIA_RT, + {MarkerTiming::InstantNow()}); + break; default: - return Nothing(); + if (getenv("MOZ_LOG_UNKNOWN_TRACE_EVENT_PHASES")) { + fprintf(stderr, "XXX UProfiler: phase not handled: '%c'\n", phase); + } + break; } -} - -struct TraceOption { - bool mPassed = false; - ProfilerString8View mName; - Variant mValue = AsVariant(false); -}; - -struct TraceMarker { - static constexpr int MAX_NUM_ARGS = 2; - using OptionsType = std::tuple; - static constexpr mozilla::Span MarkerTypeName() { - return MakeStringSpan("TraceEvent"); - } - static void StreamJSONMarkerData( - mozilla::baseprofiler::SpliceableJSONWriter& aWriter, - const OptionsType& aArgs) { - auto writeValue = [&](const auto& aName, const auto& aVariant) { - aVariant.match( - [&](const int64_t& aValue) { aWriter.IntProperty(aName, aValue); }, - [&](const bool& aValue) { aWriter.BoolProperty(aName, aValue); }, - [&](const double& aValue) { aWriter.DoubleProperty(aName, aValue); }, - [&](const ProfilerString8View& aValue) { - aWriter.StringProperty(aName, aValue); - }); - }; - if (const auto& arg = std::get<0>(aArgs); arg.mPassed) { - aWriter.StringProperty("name1", arg.mName); - writeValue("val1", arg.mValue); - } - if (const auto& arg = std::get<1>(aArgs); arg.mPassed) { - aWriter.StringProperty("name2", arg.mName); - writeValue("val2", arg.mValue); - } - } - static mozilla::MarkerSchema MarkerTypeDisplay() { - using MS = MarkerSchema; - MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable}; - schema.SetChartLabel("{marker.name}"); - schema.SetTableLabel( - "{marker.name} {marker.data.name1} {marker.data.val1} " - "{marker.data.name2} {marker.data.val2}"); - schema.AddKeyLabelFormat("name1", "Key 1", MS::Format::String); - schema.AddKeyLabelFormat("val1", "Value 1", MS::Format::String); - schema.AddKeyLabelFormat("name2", "Key 2", MS::Format::String); - schema.AddKeyLabelFormat("val2", "Value 2", MS::Format::String); - return schema; - } -}; -} // namespace - -namespace mozilla { -template <> -struct ProfileBufferEntryWriter::Serializer { - static Length Bytes(const TraceOption& aOption) { - // 1 byte to store passed flag, then object size if passed. - return aOption.mPassed ? (1 + SumBytes(aOption.mName, aOption.mValue)) : 1; - } - - static void Write(ProfileBufferEntryWriter& aEW, const TraceOption& aOption) { - // 'T'/'t' is just an arbitrary 1-byte value to distinguish states. - if (aOption.mPassed) { - aEW.WriteObject('T'); - // Use the Serializer for the name/value pair. - aEW.WriteObject(aOption.mName); - aEW.WriteObject(aOption.mValue); - } else { - aEW.WriteObject('t'); - } - } -}; - -template <> -struct ProfileBufferEntryReader::Deserializer { - static void ReadInto(ProfileBufferEntryReader& aER, TraceOption& aOption) { - char c = aER.ReadObject(); - if ((aOption.mPassed = (c == 'T'))) { - aER.ReadIntoObject(aOption.mName); - aER.ReadIntoObject(aOption.mValue); - } else { - MOZ_ASSERT(c == 't'); - } - } - - static TraceOption Read(ProfileBufferEntryReader& aER) { - TraceOption option; - ReadInto(aER, option); - return option; - } -}; -} // namespace mozilla -#endif // MOZ_GECKO_PROFILER - -void uprofiler_simple_event_marker(const char* name, char phase, int num_args, - const char** arg_names, - const unsigned char* arg_types, - const unsigned long long* arg_values) { -#ifdef MOZ_GECKO_PROFILER - if (!profiler_thread_is_being_profiled_for_markers()) { - return; - } - Maybe timing = ToTiming(phase); - if (!timing) { - if (getenv("MOZ_LOG_UNKNOWN_TRACE_EVENT_PHASES")) { - fprintf(stderr, "XXX UProfiler: phase not handled: '%c'\n", phase); - } - return; - } - MOZ_ASSERT(num_args <= TraceMarker::MAX_NUM_ARGS); - TraceMarker::OptionsType tuple; - TraceOption* args[2] = {&std::get<0>(tuple), &std::get<1>(tuple)}; - for (int i = 0; i < std::min(num_args, TraceMarker::MAX_NUM_ARGS); ++i) { - auto& arg = *args[i]; - arg.mPassed = true; - arg.mName = ProfilerString8View::WrapNullTerminatedString(arg_names[i]); - switch (arg_types[i]) { - case TRACE_VALUE_TYPE_UINT: - MOZ_ASSERT(arg_values[i] <= std::numeric_limits::max()); - arg.mValue = AsVariant(static_cast( - reinterpret_cast(&arg_values[i])->as_uint)); - break; - case TRACE_VALUE_TYPE_INT: - arg.mValue = AsVariant(static_cast( - reinterpret_cast(&arg_values[i])->as_int)); - break; - case TRACE_VALUE_TYPE_BOOL: - arg.mValue = AsVariant( - reinterpret_cast(&arg_values[i])->as_bool); - break; - case TRACE_VALUE_TYPE_DOUBLE: - arg.mValue = - AsVariant(reinterpret_cast(&arg_values[i]) - ->as_double); - break; - case TRACE_VALUE_TYPE_POINTER: - arg.mValue = AsVariant(ProfilerString8View(nsPrintfCString( - "%p", reinterpret_cast(&arg_values[i]) - ->as_pointer))); - break; - case TRACE_VALUE_TYPE_STRING: - arg.mValue = AsVariant(ProfilerString8View::WrapNullTerminatedString( - reinterpret_cast(&arg_values[i]) - ->as_string)); - break; - case TRACE_VALUE_TYPE_COPY_STRING: - arg.mValue = AsVariant(ProfilerString8View( - nsCString(reinterpret_cast(&arg_values[i]) - ->as_string))); - break; - default: - MOZ_ASSERT_UNREACHABLE("Unexpected trace value type"); - arg.mValue = AsVariant(ProfilerString8View( - nsPrintfCString("Unexpected type: %u", arg_types[i]))); - break; - } - } - profiler_add_marker(ProfilerString8View::WrapNullTerminatedString(name), - geckoprofiler::category::MEDIA_RT, {timing.extract()}, - TraceMarker{}, tuple); #endif // MOZ_GECKO_PROFILER } diff --git a/tools/profiler/public/GeckoTraceEvent.h b/tools/profiler/public/GeckoTraceEvent.h index e57d91a602f4..9fc837908190 100644 --- a/tools/profiler/public/GeckoTraceEvent.h +++ b/tools/profiler/public/GeckoTraceEvent.h @@ -543,7 +543,7 @@ // const unsigned char* arg_types, // const unsigned long long* arg_values, // unsigned char flags) -#define TRACE_EVENT_API_ADD_TRACE_EVENT MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT +#define TRACE_EVENT_API_ADD_TRACE_EVENT webrtc::EventTracer::AddTraceEvent //////////////////////////////////////////////////////////////////////////////// @@ -566,64 +566,33 @@ // Implementation detail: internal macro to create static category. #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ INTERNAL_TRACE_EVENT_INFO_TYPE INTERNAL_TRACE_EVENT_UID(catstatic) = \ - reinterpret_cast(category); + TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); // Implementation detail: internal macro to create static category and add // event if the category is enabled. #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ - do { \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ - if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ - webrtc::trace_event_internal::AddTraceEvent( \ - phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ - webrtc::trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ - } \ - } while (0) + MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(name, category, phase) // Implementation detail: internal macro to create static category and add begin // event if the category is enabled. Also adds the end event when the scope // ends. #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ - webrtc::trace_event_internal::TraceEndOnScopeClose \ - INTERNAL_TRACE_EVENT_UID(profileScope); \ - if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ - webrtc::trace_event_internal::AddTraceEvent( \ - TRACE_EVENT_PHASE_BEGIN, \ - INTERNAL_TRACE_EVENT_UID(catstatic), \ - name, webrtc::trace_event_internal::kNoEventId, \ - TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ - INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ - INTERNAL_TRACE_EVENT_UID(catstatic), name); \ - } + MOZ_INTERNAL_UPROFILER_AUTO_TRACE(category, name) // Implementation detail: internal macro to create static category and add // event if the category is enabled. #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ ...) \ - do { \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ - if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ - unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ - webrtc::trace_event_internal::TraceID trace_event_trace_id( \ - id, &trace_event_flags); \ - webrtc::trace_event_internal::AddTraceEvent( \ - phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ - name, trace_event_trace_id.data(), trace_event_flags, \ - ##__VA_ARGS__); \ - } \ - } while (0) + MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(name, category, phase) #ifdef MOZ_GECKO_PROFILER -#define MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(phase, category_enabled, name, id, \ - num_args, arg_names, arg_types, \ - arg_values, flags) \ - uprofiler_simple_event_marker(name, phase, num_args, arg_names, arg_types, \ - arg_values); +#define MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(name, category, phase) \ + uprofiler_simple_event_marker(name, category, phase); +#define MOZ_INTERNAL_UPROFILER_AUTO_TRACE(category, name) \ + AutoTrace INTERNAL_TRACE_EVENT_UID(trace)(name, category); #else -#define MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(phase, category_enabled, name, id, \ - num_args, arg_names, arg_types, \ - arg_values, flags) +#define MOZ_INTERNAL_UPROFILER_SIMPLE_EVENT(name, category, phase) +#define MOZ_INTERNAL_UPROFILER_AUTO_TRACE(name, category) #endif // Notes regarding the following definitions: @@ -650,253 +619,6 @@ #define TRACE_EVENT_FLAG_HAS_ID (static_cast(1 << 1)) #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast(1 << 2)) -namespace webrtc { -namespace trace_event_internal { - -// Specify these values when the corresponding argument of AddTraceEvent is not -// used. -const int kZeroNumArgs = 0; -const unsigned long long kNoEventId = 0; - -// TraceID encapsulates an ID that can either be an integer or pointer. Pointers -// are mangled with the Process ID so that they are unlikely to collide when the -// same pointer is used on different processes. -class TraceID { - public: - class ForceMangle { - public: - explicit ForceMangle(unsigned long long id) : data_(id) {} - explicit ForceMangle(unsigned long id) : data_(id) {} - explicit ForceMangle(unsigned int id) : data_(id) {} - explicit ForceMangle(unsigned short id) : data_(id) {} - explicit ForceMangle(unsigned char id) : data_(id) {} - explicit ForceMangle(long long id) - : data_(static_cast(id)) {} - explicit ForceMangle(long id) - : data_(static_cast(id)) {} - explicit ForceMangle(int id) - : data_(static_cast(id)) {} - explicit ForceMangle(short id) - : data_(static_cast(id)) {} - explicit ForceMangle(signed char id) - : data_(static_cast(id)) {} - - unsigned long long data() const { return data_; } - - private: - unsigned long long data_; - }; - - explicit TraceID(const void* id, unsigned char* flags) - : data_(static_cast( - reinterpret_cast(id))) { - *flags |= TRACE_EVENT_FLAG_MANGLE_ID; - } - explicit TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) { - *flags |= TRACE_EVENT_FLAG_MANGLE_ID; - } - explicit TraceID(unsigned long long id, unsigned char* flags) - : data_(id) { (void)flags; } - explicit TraceID(unsigned long id, unsigned char* flags) - : data_(id) { (void)flags; } - explicit TraceID(unsigned int id, unsigned char* flags) - : data_(id) { (void)flags; } - explicit TraceID(unsigned short id, unsigned char* flags) - : data_(id) { (void)flags; } - explicit TraceID(unsigned char id, unsigned char* flags) - : data_(id) { (void)flags; } - explicit TraceID(long long id, unsigned char* flags) - : data_(static_cast(id)) { (void)flags; } - explicit TraceID(long id, unsigned char* flags) - : data_(static_cast(id)) { (void)flags; } - explicit TraceID(int id, unsigned char* flags) - : data_(static_cast(id)) { (void)flags; } - explicit TraceID(short id, unsigned char* flags) - : data_(static_cast(id)) { (void)flags; } - explicit TraceID(signed char id, unsigned char* flags) - : data_(static_cast(id)) { (void)flags; } - - unsigned long long data() const { return data_; } - - private: - unsigned long long data_; -}; - -// Simple union to store various types as unsigned long long. -union TraceValueUnion { - bool as_bool; - unsigned long long as_uint; - long long as_int; - double as_double; - const void* as_pointer; - const char* as_string; -}; - -// Simple container for const char* that should be copied instead of retained. -class TraceStringWithCopy { - public: - explicit TraceStringWithCopy(const char* str) : str_(str) {} - operator const char* () const { return str_; } - private: - const char* str_; -}; - -// Define SetTraceValue for each allowed type. It stores the type and -// value in the return arguments. This allows this API to avoid declaring any -// structures so that it is portable to third_party libraries. -#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ - union_member, \ - value_type_id) \ - static inline void SetTraceValue(actual_type arg, \ - unsigned char* type, \ - unsigned long long* value) { \ - TraceValueUnion type_value; \ - type_value.union_member = arg; \ - *type = value_type_id; \ - *value = type_value.as_uint; \ - } -// Simpler form for int types that can be safely casted. -#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ - value_type_id) \ - static inline void SetTraceValue(actual_type arg, \ - unsigned char* type, \ - unsigned long long* value) { \ - *type = value_type_id; \ - *value = static_cast(arg); \ - } - -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) -INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) -INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) -INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) -INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, - TRACE_VALUE_TYPE_POINTER) -INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, - TRACE_VALUE_TYPE_STRING) -INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, - TRACE_VALUE_TYPE_COPY_STRING) - -#undef INTERNAL_DECLARE_SET_TRACE_VALUE -#undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT - -// std::string version of SetTraceValue so that trace arguments can be strings. -static inline void SetTraceValue(const std::string& arg, - unsigned char* type, - unsigned long long* value) { - TraceValueUnion type_value; - type_value.as_string = arg.c_str(); - *type = TRACE_VALUE_TYPE_COPY_STRING; - *value = type_value.as_uint; -} - -// These AddTraceEvent template functions are defined here instead of in the -// macro, because the arg_values could be temporary objects, such as -// std::string. In order to store pointers to the internal c_str and pass -// through to the tracing API, the arg_values must live throughout -// these procedures. - -static inline void AddTraceEvent(char phase, - const unsigned char* category_enabled, - const char* name, - unsigned long long id, - unsigned char flags) { - TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_enabled, name, id, - kZeroNumArgs, nullptr, nullptr, nullptr, - flags); -} - -template -static inline void AddTraceEvent(char phase, - const unsigned char* category_enabled, - const char* name, - unsigned long long id, - unsigned char flags, - const char* arg1_name, - const ARG1_TYPE& arg1_val) { - const int num_args = 1; - unsigned char arg_types[1]; - unsigned long long arg_values[1]; - SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); - TRACE_EVENT_API_ADD_TRACE_EVENT( - phase, category_enabled, name, id, - num_args, &arg1_name, arg_types, arg_values, - flags); -} - -template -static inline void AddTraceEvent(char phase, - const unsigned char* category_enabled, - const char* name, - unsigned long long id, - unsigned char flags, - const char* arg1_name, - const ARG1_TYPE& arg1_val, - const char* arg2_name, - const ARG2_TYPE& arg2_val) { - const int num_args = 2; - const char* arg_names[2] = { arg1_name, arg2_name }; - unsigned char arg_types[2]; - unsigned long long arg_values[2]; - SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); - SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); - TRACE_EVENT_API_ADD_TRACE_EVENT( - phase, category_enabled, name, id, - num_args, arg_names, arg_types, arg_values, - flags); -} - -// Used by TRACE_EVENTx macro. Do not use directly. -class TraceEndOnScopeClose { - public: - // Note: members of data_ intentionally left uninitialized. See Initialize. - TraceEndOnScopeClose() : p_data_(nullptr) {} - ~TraceEndOnScopeClose() { - if (p_data_) - AddEventIfEnabled(); - } - - void Initialize(const unsigned char* category_enabled, - const char* name) { - data_.category_enabled = category_enabled; - data_.name = name; - p_data_ = &data_; - } - - private: - // Add the end event if the category is still enabled. - void AddEventIfEnabled() { - // Only called when p_data_ is non-null. - if (*p_data_->category_enabled) { - TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_END, - p_data_->category_enabled, p_data_->name, - kNoEventId, kZeroNumArgs, nullptr, - nullptr, nullptr, TRACE_EVENT_FLAG_NONE); - } - } - - // This Data struct workaround is to avoid initializing all the members - // in Data during construction of this object, since this object is always - // constructed, even when tracing is disabled. If the members of Data were - // members of this class instead, compiler warnings occur about potential - // uninitialized accesses. - struct Data { - const unsigned char* category_enabled; - const char* name; - }; - Data* p_data_; - Data data_; -}; - -} // namespace trace_event_internal -} // namespace webrtc #else //////////////////////////////////////////////////////////////////////////////// diff --git a/tools/profiler/public/MicroGeckoProfiler.h b/tools/profiler/public/MicroGeckoProfiler.h index 2660dd177a4d..0ea3fbf4a0f8 100644 --- a/tools/profiler/public/MicroGeckoProfiler.h +++ b/tools/profiler/public/MicroGeckoProfiler.h @@ -28,9 +28,23 @@ struct AutoRegisterProfiler { }; #endif // __cplusplus -void uprofiler_simple_event_marker(const char* name, char phase, int num_args, - const char** arg_names, - const unsigned char* arg_types, - const unsigned long long* arg_values); +void uprofiler_simple_event_marker(const char* name, const char* category, + char phase); + +#ifdef __cplusplus +class AutoTrace { + public: + AutoTrace(const char* name, const char* category) + : name(name), category(category) { + uprofiler_simple_event_marker(name, category, 'B'); + } + ~AutoTrace() { uprofiler_simple_event_marker(name, category, 'E'); } + + private: + const char* name; + const char* category; +}; + +#endif #endif // MICRO_GECKO_PROFILER diff --git a/xpcom/threads/AbstractThread.cpp b/xpcom/threads/AbstractThread.cpp index 8ae55245481a..61ce4bac1f18 100644 --- a/xpcom/threads/AbstractThread.cpp +++ b/xpcom/threads/AbstractThread.cpp @@ -10,7 +10,6 @@ #include "mozilla/DelayedRunnable.h" #include "mozilla/Maybe.h" #include "mozilla/MozPromise.h" // We initialize the MozPromise logging in this file. -#include "mozilla/ProfilerRunnable.h" #include "mozilla/StateWatching.h" // We initialize the StateWatching logging in this file. #include "mozilla/StaticPtr.h" #include "mozilla/TaskDispatcher.h" @@ -209,7 +208,6 @@ class XPCOMThreadWrapper final : public AbstractThread, MOZ_ASSERT(mThread == AbstractThread::GetCurrent()); MOZ_ASSERT(mThread->IsCurrentThreadIn()); SerialEventTargetGuard guard(mThread); - AUTO_PROFILE_FOLLOWING_RUNNABLE(mRunnable); return mRunnable->Run(); } diff --git a/xpcom/threads/DelayedRunnable.cpp b/xpcom/threads/DelayedRunnable.cpp index 067b08d4ee7d..d782d52e3059 100644 --- a/xpcom/threads/DelayedRunnable.cpp +++ b/xpcom/threads/DelayedRunnable.cpp @@ -6,8 +6,6 @@ #include "DelayedRunnable.h" -#include "mozilla/ProfilerRunnable.h" - namespace mozilla { DelayedRunnable::DelayedRunnable(already_AddRefed aTarget, @@ -67,7 +65,6 @@ NS_IMETHODIMP DelayedRunnable::Notify(nsITimer* aTimer) { nsresult DelayedRunnable::DoRun() { nsCOMPtr r = std::move(mWrappedRunnable); - AUTO_PROFILE_FOLLOWING_RUNNABLE(r); return r->Run(); } diff --git a/xpcom/threads/TaskDispatcher.h b/xpcom/threads/TaskDispatcher.h index 1f27c32c7d4a..558221aa9589 100644 --- a/xpcom/threads/TaskDispatcher.h +++ b/xpcom/threads/TaskDispatcher.h @@ -11,7 +11,6 @@ # include "mozilla/AbstractThread.h" # include "mozilla/Maybe.h" -# include "mozilla/ProfilerRunnable.h" # include "mozilla/UniquePtr.h" # include "nsIDirectTaskDispatcher.h" # include "nsISupportsImpl.h" @@ -40,7 +39,6 @@ class SimpleTaskQueue { while (!queue.empty()) { nsCOMPtr r = std::move(queue.front()); queue.pop(); - AUTO_PROFILE_FOLLOWING_RUNNABLE(r); r->Run(); } } @@ -226,7 +224,6 @@ class AutoTaskDispatcher : public TaskDispatcher { MaybeDrainDirectTasks(); for (size_t i = 0; i < mTasks->mRegularTasks.Length(); ++i) { - AUTO_PROFILE_FOLLOWING_RUNNABLE(mTasks->mRegularTasks[i]); mTasks->mRegularTasks[i]->Run(); // Scope direct tasks tightly to the task that generated them. diff --git a/xpcom/threads/TaskQueue.cpp b/xpcom/threads/TaskQueue.cpp index 401f9d649941..b0b4e87f7f7d 100644 --- a/xpcom/threads/TaskQueue.cpp +++ b/xpcom/threads/TaskQueue.cpp @@ -7,7 +7,6 @@ #include "mozilla/TaskQueue.h" #include "mozilla/DelayedRunnable.h" -#include "mozilla/ProfilerRunnable.h" #include "nsThreadUtils.h" namespace mozilla { @@ -202,7 +201,6 @@ nsresult TaskQueue::Runner::Run() { { LogRunnable::Run log(event.event); - AUTO_PROFILE_FOLLOWING_RUNNABLE(event.event); event.event->Run(); // Drop the reference to event. The event will hold a reference to the