Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / events / latency_info.cc
index 2ef0629..0e38f20 100644 (file)
@@ -11,6 +11,9 @@
 #include <algorithm>
 
 namespace {
+
+const unsigned int kMaxLatencyInfoNumber = 100;
+
 const char* GetComponentName(ui::LatencyComponentType type) {
 #define CASE_TYPE(t) case ui::t:  return #t
   switch (type) {
@@ -21,10 +24,14 @@ const char* GetComponentName(ui::LatencyComponentType type) {
     CASE_TYPE(INPUT_EVENT_LATENCY_UI_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT);
+    CASE_TYPE(WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT);
     CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT);
+    CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT);
+    CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT);
+    CASE_TYPE(LATENCY_INFO_LIST_TERMINATED_OVERFLOW_COMPONENT);
     default:
       DLOG(WARNING) << "Unhandled LatencyComponentType.\n";
       break;
@@ -39,6 +46,9 @@ bool IsTerminalComponent(ui::LatencyComponentType type) {
     case ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT:
     case ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT:
     case ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
+    case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
+    case ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
+    case ui::LATENCY_INFO_LIST_TERMINATED_OVERFLOW_COMPONENT:
       return true;
     default:
       return false;
@@ -98,6 +108,7 @@ scoped_refptr<base::debug::ConvertableToTraceFormat> AsTraceableData(
     component_info->SetDouble("count", it->second.event_count);
     record_data->Set(GetComponentName(it->first.first), component_info);
   }
+  record_data->SetDouble("trace_id", latency.trace_id);
   return LatencyInfoTracedValue::FromValue(record_data.PassAs<base::Value>());
 }
 
@@ -111,16 +122,28 @@ LatencyInfo::LatencyInfo() : trace_id(-1), terminated(false) {
 LatencyInfo::~LatencyInfo() {
 }
 
-void LatencyInfo::MergeWith(const LatencyInfo& other) {
+bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info,
+                         const char* referring_msg) {
+  if (latency_info.size() > kMaxLatencyInfoNumber) {
+    LOG(ERROR) << referring_msg << ", LatencyInfo vector size "
+               << latency_info.size() << " is too big.";
+    return false;
+  }
+  return true;
+}
+
+void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other,
+                                  LatencyComponentType type) {
   for (LatencyMap::const_iterator it = other.latency_components.begin();
        it != other.latency_components.end();
        ++it) {
-    AddLatencyNumberWithTimestamp(it->first.first,
-                                  it->first.second,
-                                  it->second.sequence_number,
-                                  it->second.event_time,
-                                  it->second.event_count,
-                                  false);
+    if (it->first.first == type) {
+      AddLatencyNumberWithTimestamp(it->first.first,
+                                    it->first.second,
+                                    it->second.sequence_number,
+                                    it->second.event_time,
+                                    it->second.event_count);
+    }
   }
 }
 
@@ -133,8 +156,7 @@ void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) {
                                       it->first.second,
                                       it->second.sequence_number,
                                       it->second.event_time,
-                                      it->second.event_count,
-                                      false);
+                                      it->second.event_count);
       }
     }
 }
@@ -143,16 +165,15 @@ void LatencyInfo::AddLatencyNumber(LatencyComponentType component,
                                    int64 id,
                                    int64 component_sequence_number) {
   AddLatencyNumberWithTimestamp(component, id, component_sequence_number,
-                                base::TimeTicks::HighResNow(), 1, true);
+                                base::TimeTicks::HighResNow(), 1);
 }
 
 void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component,
                                                 int64 id,
                                                 int64 component_sequence_number,
                                                 base::TimeTicks time,
-                                                uint32 event_count,
-                                                bool dump_to_trace) {
-  if (dump_to_trace && IsBeginComponent(component)) {
+                                                uint32 event_count) {
+  if (IsBeginComponent(component)) {
     // Should only ever add begin component once.
     CHECK_EQ(-1, trace_id);
     trace_id = component_sequence_number;
@@ -180,7 +201,7 @@ void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component,
     }
   }
 
-  if (dump_to_trace && IsTerminalComponent(component) && trace_id != -1) {
+  if (IsTerminalComponent(component) && trace_id != -1) {
     // Should only ever add terminal component once.
     CHECK(!terminated);
     terminated = true;
@@ -203,8 +224,28 @@ bool LatencyInfo::FindLatency(LatencyComponentType type,
   return true;
 }
 
+void LatencyInfo::RemoveLatency(LatencyComponentType type) {
+  LatencyMap::iterator it = latency_components.begin();
+  while (it != latency_components.end()) {
+    if (it->first.first == type) {
+      LatencyMap::iterator tmp = it;
+      ++it;
+      latency_components.erase(tmp);
+    } else {
+      it++;
+    }
+  }
+}
+
 void LatencyInfo::Clear() {
   latency_components.clear();
 }
 
+void LatencyInfo::TraceEventType(const char* event_type) {
+  TRACE_EVENT_ASYNC_STEP_INTO0("benchmark",
+                               "InputLatency",
+                               TRACE_ID_DONT_MANGLE(trace_id),
+                               event_type);
+}
+
 }  // namespace ui