From 169cbde4642d3e5bc6eba09b73a9df3bdd4863e5 Mon Sep 17 00:00:00 2001
From: "A. Unique TensorFlower" <gardener@tensorflow.org>
Date: Tue, 20 Oct 2020 13:15:50 -0700
Subject: [PATCH] single out host plane merge function to reuse.

PiperOrigin-RevId: 338123012
Change-Id: Ib7d4dfb1fab09156c917a0b6465f88048f6cbb05
---
 .../convert/post_process_single_host_xplane.cc       | 12 ++++++++----
 .../convert/post_process_single_host_xplane.h        |  3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tensorflow/core/profiler/convert/post_process_single_host_xplane.cc b/tensorflow/core/profiler/convert/post_process_single_host_xplane.cc
index 581a003eb38..7a2fe8c9547 100644
--- a/tensorflow/core/profiler/convert/post_process_single_host_xplane.cc
+++ b/tensorflow/core/profiler/convert/post_process_single_host_xplane.cc
@@ -22,10 +22,7 @@ limitations under the License.
 namespace tensorflow {
 namespace profiler {
 
-void PostProcessSingleHostXSpace(XSpace* space, uint64 start_time_ns) {
-  VLOG(3) << "Post processing local profiler XSpace.";
-  // Post processing the collected XSpace without hold profiler lock.
-  // 1. Merge plane of host events with plane of CUPTI driver api.
+void MergeHostPlanes(XSpace* space) {
   const XPlane* cupti_driver_api_plane =
       FindPlaneWithName(*space, kCuptiDriverApiPlaneName);
   const XPlane* python_tracer_plane =
@@ -49,6 +46,13 @@ void PostProcessSingleHostXSpace(XSpace* space, uint64 start_time_ns) {
       RemovePlaneWithName(space, kPythonTracerPlaneName);
     }
   }
+}
+
+void PostProcessSingleHostXSpace(XSpace* space, uint64 start_time_ns) {
+  VLOG(3) << "Post processing local profiler XSpace.";
+  // Post processing the collected XSpace without hold profiler lock.
+  // 1. Merge plane of host events with plane of CUPTI driver api.
+  MergeHostPlanes(space);
 
   // 2. Normalize all timestamps by shifting timeline to profiling start time.
   // NOTE: this have to be done before sorting XSpace due to timestamp overflow.
diff --git a/tensorflow/core/profiler/convert/post_process_single_host_xplane.h b/tensorflow/core/profiler/convert/post_process_single_host_xplane.h
index 31ebe28c48f..70c6785591b 100644
--- a/tensorflow/core/profiler/convert/post_process_single_host_xplane.h
+++ b/tensorflow/core/profiler/convert/post_process_single_host_xplane.h
@@ -21,6 +21,9 @@ limitations under the License.
 namespace tensorflow {
 namespace profiler {
 
+// Merges XPlanes generated by TraceMe, CUPTI API trace and Python tracer.
+void MergeHostPlanes(XSpace* space);
+
 // Post process XSpaces collected locally from multiple profilers.
 void PostProcessSingleHostXSpace(XSpace* space, uint64 start_time_ns);