Unify DrawProfiler/JankStats

Bug: 20822400

Change-Id: I24345c3120440bfce14e8cbe7e880b39f10b744a
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 733e5e0..6d7dcf1 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -46,7 +46,8 @@
         , mOpaque(!translucent)
         , mAnimationContext(contextFactory->createAnimationContext(mRenderThread.timeLord()))
         , mRootRenderNode(rootRenderNode)
-        , mJankTracker(thread.timeLord().frameIntervalNanos()) {
+        , mJankTracker(thread.timeLord().frameIntervalNanos())
+        , mProfiler(mFrames) {
     mRenderThread.renderState().registerCanvasContext(this);
     mProfiler.setDensity(mRenderThread.mainDisplayInfo().density);
 }
@@ -218,7 +219,6 @@
         return;
     }
 
-    profiler().markPlaybackStart();
     mCurrentFrameInfo->markIssueDrawCommandsStart();
 
     EGLint width, height;
@@ -251,8 +251,6 @@
 
     bool drew = mCanvas->finish();
 
-    profiler().markPlaybackEnd();
-
     // Even if we decided to cancel the frame, from the perspective of jank
     // metrics the frame was swapped at this point
     mCurrentFrameInfo->markSwapBuffers();
@@ -267,7 +265,6 @@
     mCurrentFrameInfo->markFrameCompleted();
     mJankTracker.addFrame(*mCurrentFrameInfo);
     mRenderThread.jankTracker().addFrame(*mCurrentFrameInfo);
-    profiler().finishFrame();
 }
 
 // Called by choreographer to do an RT-driven animation
@@ -278,7 +275,6 @@
 
     ATRACE_CALL();
 
-    profiler().startFrame();
     int64_t frameInfo[UI_THREAD_FRAME_INFO_SIZE];
     UiFrameInfoBuilder(frameInfo)
         .addFlag(FrameInfoFlags::kRTAnimation)
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 8163b0f..8d54304 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -18,9 +18,9 @@
 #define CANVASCONTEXT_H_
 
 #include "DamageAccumulator.h"
-#include "DrawProfiler.h"
 #include "IContextFactory.h"
 #include "FrameInfo.h"
+#include "FrameInfoVisualizer.h"
 #include "RenderNode.h"
 #include "utils/RingBuffer.h"
 #include "renderthread/RenderTask.h"
@@ -103,7 +103,7 @@
     void stopDrawing();
     void notifyFramePending();
 
-    DrawProfiler& profiler() { return mProfiler; }
+    FrameInfoVisualizer& profiler() { return mProfiler; }
 
     void dumpFrames(int fd);
     void resetFrameStats();
@@ -140,12 +140,12 @@
 
     const sp<RenderNode> mRootRenderNode;
 
-    DrawProfiler mProfiler;
     FrameInfo* mCurrentFrameInfo = nullptr;
-    // Ring buffer large enough for 1 second worth of frames
-    RingBuffer<FrameInfo, 60> mFrames;
+    // Ring buffer large enough for 2 seconds worth of frames
+    RingBuffer<FrameInfo, 120> mFrames;
     std::string mName;
     JankTracker mJankTracker;
+    FrameInfoVisualizer mProfiler;
 
     std::set<RenderNode*> mPrefetechedLayers;
 };
diff --git a/libs/hwui/renderthread/DrawFrameTask.cpp b/libs/hwui/renderthread/DrawFrameTask.cpp
index 35391b2..83af4ae 100644
--- a/libs/hwui/renderthread/DrawFrameTask.cpp
+++ b/libs/hwui/renderthread/DrawFrameTask.cpp
@@ -83,8 +83,6 @@
 void DrawFrameTask::run() {
     ATRACE_NAME("DrawFrame");
 
-    mContext->profiler().startFrame();
-
     bool canUnblockUiThread;
     bool canDrawThisFrame;
     {