tensorflow/core/profiler/convert/xplane_to_step_events_test.cc
// Tests with a sample profile with two steps captured on the host but only one
// step on the device. On the host, each step consists of TraceContext ->
// FunctionRun -> ExecutorState::Process -> matmul. On the host, each step
// consists of matmul. The host's step db should be created only for the step
// observed on the host.
Tests with a sample profile with two steps captured on the host but only one
step on the device. On the host, each step consists of TraceContext ->
FunctionRun -> ExecutorState::Process -> matmul. On the host, each step
consists of matmul. The host's step db should be created only for the step
observed on the host.
Tests with a sample profile with two steps captured on the host but only one step on the device . On the host each step consists of TraceContext - > FunctionRun - > ExecutorState :: Process - > matmul . On the host each step consists of matmul . The host ' s step db should be created only for the step observed on the host .
TEST(ConvertXPlaneToOpStats, CpuOnlyStepDbTest) {
  constexpr int64_t kFirstStepNum = 123;
  constexpr int64_t kSecondStepNum = 456;
  constexpr int64_t kFirstStepId = 0;
  constexpr int64_t kSecondStepId = 1;
  constexpr int64_t kFirstCorrelationId = 100;
  constexpr int64_t kSecondCorrelationId = 200;
  XSpace space;
  XPlane* host_plane = GetOrCreateHostXPlane(&space);
  XPlaneBuilder host_plane_builder(host_plane);
  host_plane_builder.ReserveLines(2);
  auto main_thread = host_plane_builder.GetOrCreateLine(0);
  CreateXEvent(&host_plane_builder, &main_thread, HostEventType::kTraceContext,
               0, 100, {{StatType::kStepNum, kFirstStepNum}});
  CreateXEvent(&host_plane_builder, &main_thread, HostEventType::kFunctionRun,
               10, 90, {{StatType::kStepId, kFirstStepId}});
  CreateXEvent(&host_plane_builder, &main_thread, HostEventType::kTraceContext,
               300, 100, {{StatType::kStepNum, kSecondStepNum}});
  CreateXEvent(&host_plane_builder, &main_thread, HostEventType::kFunctionRun,
               310, 90, {{StatType::kStepId, kSecondStepId}});
  auto tf_executor_thread = host_plane_builder.GetOrCreateLine(1);
  CreateXEvent(&host_plane_builder, &tf_executor_thread,
               HostEventType::kExecutorStateProcess, 20, 20,
               {{StatType::kStepId, kFirstStepId}});
  CreateXEvent(&host_plane_builder, &tf_executor_thread, "matmul", 30, 10,
               {{StatType::kCorrelationId, kFirstCorrelationId}});
  CreateXEvent(&host_plane_builder, &tf_executor_thread,
               HostEventType::kExecutorStateProcess, 320, 20,
               {{StatType::kStepId, kSecondStepId}});
  CreateXEvent(&host_plane_builder, &tf_executor_thread, "matmul", 330, 10,
               {{StatType::kCorrelationId, kSecondCorrelationId}});
  XPlane* device_plane = space.add_planes();
  XPlaneBuilder device_plane_builder(device_plane);
  device_plane_builder.ReserveLines(1);
  auto stream = device_plane_builder.GetOrCreateLine(0);
  CreateXEvent(&device_plane_builder, &stream, "matmul", 50, 40,
               {{StatType::kCorrelationId, kFirstCorrelationId}});
  GroupTfEvents(&space);
  StepEvents device_step_events =
      ConvertDeviceTraceXPlaneToStepEvents(*device_plane);
  EXPECT_EQ(device_step_events.size(), 1);
  EXPECT_EQ(device_step_events[0].Events().size(), 1);
  StepEvents host_step_events =
      ConvertHostThreadsXPlaneToStepEvents(*host_plane, &device_step_events);
  EXPECT_EQ(host_step_events.size(), 1);
  EXPECT_EQ(host_step_events[0].Markers().size(), 1);
  EXPECT_EQ(host_step_events[0].Events().size(), 2);
}
TEST ( ConvertXPlaneToOpStats , CpuOnlyStepDbTest ) { constexpr int64_t kFirstStepNum = 123 ; constexpr int64_t kSecondStepNum = 456 ; constexpr int64_t kFirstStepId = 0 ; constexpr int64_t kSecondStepId = 1 ; constexpr int64_t kFirstCorrelationId = 100 ; constexpr int64_t kSecondCorrelationId = 200 ; XSpace space ; XPlane * host_plane = GetOrCreateHostXPlane ( & space ) ; XPlaneBuilder host_plane_builder ( host_plane ) ; host_plane_builder . ReserveLines ( 2 ) ; auto main_thread = host_plane_builder . GetOrCreateLine ( 0 ) ; CreateXEvent ( & host_plane_builder , & main_thread , HostEventType :: kTraceContext , 0 , 100 , { { StatType :: kStepNum , kFirstStepNum } } ) ; CreateXEvent ( & host_plane_builder , & main_thread , HostEventType :: kFunctionRun , 10 , 90 , { { StatType :: kStepId , kFirstStepId } } ) ; CreateXEvent ( & host_plane_builder , & main_thread , HostEventType :: kTraceContext , 300 , 100 , { { StatType :: kStepNum , kSecondStepNum } } ) ; CreateXEvent ( & host_plane_builder , & main_thread , HostEventType :: kFunctionRun , 310 , 90 , { { StatType :: kStepId , kSecondStepId } } ) ; auto tf_executor_thread = host_plane_builder . GetOrCreateLine ( 1 ) ; CreateXEvent ( & host_plane_builder , & tf_executor_thread , HostEventType :: kExecutorStateProcess , 20 , 20 , { { StatType :: kStepId , kFirstStepId } } ) ; CreateXEvent ( & host_plane_builder , & tf_executor_thread , " " , 30 , 10 , { { StatType :: kCorrelationId , kFirstCorrelationId } } ) ; CreateXEvent ( & host_plane_builder , & tf_executor_thread , HostEventType :: kExecutorStateProcess , 320 , 20 , { { StatType :: kStepId , kSecondStepId } } ) ; CreateXEvent ( & host_plane_builder , & tf_executor_thread , " " , 330 , 10 , { { StatType :: kCorrelationId , kSecondCorrelationId } } ) ; XPlane * device_plane = space . add_planes ( ) ; XPlaneBuilder device_plane_builder ( device_plane ) ; device_plane_builder . ReserveLines ( 1 ) ; auto stream = device_plane_builder . GetOrCreateLine ( 0 ) ; CreateXEvent ( & device_plane_builder , & stream , " " , 50 , 40 , { { StatType :: kCorrelationId , kFirstCorrelationId } } ) ; GroupTfEvents ( & space ) ; StepEvents device_step_events = ConvertDeviceTraceXPlaneToStepEvents ( * device_plane ) ; EXPECT_EQ ( device_step_events . size ( ) , 1 ) ; EXPECT_EQ ( device_step_events [ 0 ] . Events ( ) . size ( ) , 1 ) ; StepEvents host_step_events = ConvertHostThreadsXPlaneToStepEvents ( * host_plane , & device_step_events ) ; EXPECT_EQ ( host_step_events . size ( ) , 1 ) ; EXPECT_EQ ( host_step_events [ 0 ] . Markers ( ) . size ( ) , 1 ) ; EXPECT_EQ ( host_step_events [ 0 ] . Events ( ) . size ( ) , 2 ) ; }
Tests with a sample profile with two steps captured on the host but only one
step on the device.
Tests with a sample profile with two steps captured on the host but only one step on the device .
// Should contain only the step which is also present on the device. // TraceContext should be added as a step marker. // FunctionRun shouldn't be added.