Constexpr-eliminate GetCategoryGroupEnabled calls for popular categories

This CL allows to avoid the cost of calling GetCategoryGroupEnabled() in
TRACE_EVENT macros for popular categories, in a way that doesn't require more
macros, nor changing all the call sites.

The idea is to put all popular categories into a static global array so an
address of a category state may be determined at compile-time through a call
to a constexpr function.

This CL makes it impossible to use non constant expressions as a category name
in the tracing macros. All the call sites that don't satisfy this requirement
have to be converted. Hopefully, there aren't a lot of such callers.

This change reduces the code size generated from each trace macro by ~16 bytes,
check the full report here:
https://docs.google.com/document/d/1piIq_yi2fsqOEKObx0tFHeunMyX7hp2ZdAGKK6t0k80/edit?usp=sharing.
The total Android apk size savings are ~60 KiB.

Bug: 702718, 708990
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I9f7b48fd4ee614996feaabda3e5495fd9b786c3a
Reviewed-on: https://chromium-review.googlesource.com/c/1251361
Commit-Queue: Alexandr Ilin <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Primiano Tucci <[email protected]>
Reviewed-by: Tibor Goldschwendt <[email protected]>
Reviewed-by: Frank Liberato <[email protected]>
Reviewed-by: vmpstr <[email protected]>
Reviewed-by: Sami Kyöstilä <[email protected]>
Reviewed-by: David Turner <[email protected]>
Cr-Commit-Position: refs/heads/master@{#607975}
diff --git a/cc/benchmarks/benchmark_instrumentation.h b/cc/benchmarks/benchmark_instrumentation.h
index 9b5e5ef..d946c6e6 100644
--- a/cc/benchmarks/benchmark_instrumentation.h
+++ b/cc/benchmarks/benchmark_instrumentation.h
@@ -18,7 +18,11 @@
 // The benchmarks search for events and their arguments by name.
 
 namespace internal {
-const char kCategory[] = "cc,benchmark";
+constexpr const char* Category() {
+  // Declared as a constexpr function to have an external linkage and to be
+  // known at compile-time.
+  return "cc,benchmark";
+}
 const char kBeginFrameId[] = "begin_frame_id";
 }  // namespace internal
 
@@ -31,11 +35,11 @@
  public:
   ScopedBeginFrameTask(const char* event_name, unsigned int begin_frame_id)
       : event_name_(event_name) {
-    TRACE_EVENT_BEGIN1(internal::kCategory, event_name_,
+    TRACE_EVENT_BEGIN1(internal::Category(), event_name_,
                        internal::kBeginFrameId, begin_frame_id);
   }
   ~ScopedBeginFrameTask() {
-    TRACE_EVENT_END0(internal::kCategory, event_name_);
+    TRACE_EVENT_END0(internal::Category(), event_name_);
   }
 
  private: