summaryrefslogtreecommitdiffstats
path: root/base/trace_event
diff options
context:
space:
mode:
authorfdoray <fdoray@chromium.org>2015-11-25 19:30:20 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-26 03:31:00 +0000
commit6b5d01a9e568040f653dd8e4e13f69d08d49af91 (patch)
tree00b2a2277100fde827a3fedb879e14473cbbb3d6 /base/trace_event
parent664fe1ed1c1f42cec4b13c99e17b2ddf314f4e7c (diff)
downloadchromium_src-6b5d01a9e568040f653dd8e4e13f69d08d49af91.zip
chromium_src-6b5d01a9e568040f653dd8e4e13f69d08d49af91.tar.gz
chromium_src-6b5d01a9e568040f653dd8e4e13f69d08d49af91.tar.bz2
Add TRACE_COUNTER_WITH_TIMESTAMPx macros.
base::ProcessMetrics::GetCPUUsage() gives access to the % of CPU usage for the current process in the time interval [a, b], where a is the timestamp of the previous call to the method and b is the current timestamp. In order to display a correct CPU usage graph in about:tracing from the values returned by base::ProcessMetrics::GetCPUUsage(), we need a way to emit a counter event with timestamp |b| when we read the CPU usage at timestamp |a|. This CL introduces 2 TRACE_COUNTER_WITH_TIMESTAMPx macros that can emit a counter event with a custom timestamp. BUG=553266 Review URL: https://codereview.chromium.org/1432873002 Cr-Commit-Position: refs/heads/master@{#361807}
Diffstat (limited to 'base/trace_event')
-rw-r--r--base/trace_event/common/trace_event_common.h14
-rw-r--r--base/trace_event/trace_event.h17
-rw-r--r--base/trace_event/trace_event_unittest.cc38
3 files changed, 69 insertions, 0 deletions
diff --git a/base/trace_event/common/trace_event_common.h b/base/trace_event/common/trace_event_common.h
index 16a9a37..cae3670 100644
--- a/base/trace_event/common/trace_event_common.h
+++ b/base/trace_event/common/trace_event_common.h
@@ -484,6 +484,20 @@
static_cast<int>(value1_val), value2_name, \
static_cast<int>(value2_val))
+// Similar to TRACE_COUNTERx, but with a custom |timestamp| provided.
+#define TRACE_COUNTER_WITH_TIMESTAMP1(category_group, name, timestamp, value) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
+ TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp, \
+ TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
+
+#define TRACE_COUNTER_WITH_TIMESTAMP2(category_group, name, timestamp, \
+ value1_name, value1_val, value2_name, \
+ value2_val) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
+ TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp, \
+ TRACE_EVENT_FLAG_NONE, value1_name, static_cast<int>(value1_val), \
+ value2_name, static_cast<int>(value2_val))
+
// Records the value of a counter called "name" immediately. Value
// must be representable as a 32 bit integer.
// - category and name strings must have application lifetime (statics or
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index 95ea215..14448e2 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -302,6 +302,23 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
// Implementation detail: internal macro to create static category and add
// event if the category is enabled.
+#define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \
+ timestamp, flags, ...) \
+ do { \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \
+ phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ trace_event_internal::kNoId, trace_event_internal::kNoId, \
+ TRACE_EVENT_API_CURRENT_THREAD_ID, \
+ base::TimeTicks::FromInternalValue(timestamp), \
+ flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
+ trace_event_internal::kNoId, ##__VA_ARGS__); \
+ } \
+ } while (0)
+
+// Implementation detail: internal macro to create static category and add
+// event if the category is enabled.
#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \
category_group, name, id, thread_id, timestamp, flags, ...) \
do { \
diff --git a/base/trace_event/trace_event_unittest.cc b/base/trace_event/trace_event_unittest.cc
index 084c250..533a298 100644
--- a/base/trace_event/trace_event_unittest.cc
+++ b/base/trace_event/trace_event_unittest.cc
@@ -459,6 +459,11 @@ void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) {
"a", 30000,
"b", 1415);
+ TRACE_COUNTER_WITH_TIMESTAMP1("all", "TRACE_COUNTER_WITH_TIMESTAMP1 call",
+ 42, 31415);
+ TRACE_COUNTER_WITH_TIMESTAMP2("all", "TRACE_COUNTER_WITH_TIMESTAMP2 call",
+ 42, "a", 30000, "b", 1415);
+
TRACE_COUNTER_ID1("all", "TRACE_COUNTER_ID1 call", 0x319009, 31415);
TRACE_COUNTER_ID2("all", "TRACE_COUNTER_ID2 call", 0x319009,
"a", 30000, "b", 1415);
@@ -655,6 +660,39 @@ void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) {
EXPECT_EQ(1415, value);
}
+ EXPECT_FIND_("TRACE_COUNTER_WITH_TIMESTAMP1 call");
+ {
+ std::string ph;
+ EXPECT_TRUE((item && item->GetString("ph", &ph)));
+ EXPECT_EQ("C", ph);
+
+ int value;
+ EXPECT_TRUE((item && item->GetInteger("args.value", &value)));
+ EXPECT_EQ(31415, value);
+
+ int ts;
+ EXPECT_TRUE((item && item->GetInteger("ts", &ts)));
+ EXPECT_EQ(42, ts);
+ }
+
+ EXPECT_FIND_("TRACE_COUNTER_WITH_TIMESTAMP2 call");
+ {
+ std::string ph;
+ EXPECT_TRUE((item && item->GetString("ph", &ph)));
+ EXPECT_EQ("C", ph);
+
+ int value;
+ EXPECT_TRUE((item && item->GetInteger("args.a", &value)));
+ EXPECT_EQ(30000, value);
+
+ EXPECT_TRUE((item && item->GetInteger("args.b", &value)));
+ EXPECT_EQ(1415, value);
+
+ int ts;
+ EXPECT_TRUE((item && item->GetInteger("ts", &ts)));
+ EXPECT_EQ(42, ts);
+ }
+
EXPECT_FIND_("TRACE_COUNTER_ID1 call");
{
std::string id;