syntax = "proto3";

package tensorflow.profiler;

message OpInstance {
  uint64 start_time_ps = 1;
  uint64 duration_ps = 2;
}

message DcnSlack {
  string rendezvous = 1;
  // XProf observed send start time.
  uint64 send_start_time_us = 2;
  // XProf observed recv_done end time.
  uint64 recv_done_end_time_us = 3;

  // Slack is defined as the time the collective has to send and recv data
  // without stalling the tpu. The effect of the network and other overlapping
  // collectives are removed from the collective of interest.
  //
  //
  // HOST 1 :
  // |--------|SEND1|-------|SEND1.DONE|-------|RECV1|------|RECV1.DONE|-------
  // HOST 2:
  // |------|SEND2|-------|SEND2.DONE|-------|RECV2|------|RECV2.DONE    |-----
  //
  // Slack is computed as
  // RECV2.DONE.StartTime - SEND2.StartTime - (Overlapping Communication)
  // In this case, Overlapping communication is the duration of SEND2,
  // SEND2.DONE and RECV2. In cases where other collectives are interspaced
  // between this collective, Overlapping duration would include their durations
  // as well. Host 1 is ignored while computing the slack, as we assume that the
  // similar ops are executing each core. This also prevents clock drifts to
  // effect the analysis.
  uint64 slack_us = 4;

  uint64 bytes_transmitted_over_network = 5;

  // Duration the collective stalled the TPU.
  uint64 stall_duration_us = 6;

  // Recv op name
  string recv_op_name = 7;

  // Send op name
  string send_op_name = 8;

  // Timestamp for the send/send-done/recv/recv-done ops
  OpInstance send = 9;
  OpInstance send_done = 10;
  OpInstance recv = 11;
  OpInstance recv_done = 12;

  string transfer_type = 13;

  OpInstance host_graph_execution = 14;
}

message DcnSlackSummary {
  // Rendezvous name for the collective.
  string rendezvous = 1;
  // Slack Time in Microseconds,
  uint64 slack_us = 2;
  // Number of occurrences in the sampled duration.
  uint64 occurrences = 3;
  // Bytes transmitted over the network.
  uint64 bytes_transmitted_over_network = 4;
  // Duration the collective stalled the TPU.
  uint64 stall_duration_us = 5;
  // Observed duration.
  uint64 observed_duration_us = 6;
  // Recv op name.
  string recv_op_name = 7;

  // Send op name.
  string send_op_name = 8;

  // Stall duration based on the op.
  uint64 send_duration_us = 9;
  uint64 recv_duration_us = 10;
  uint64 send_done_duration_us = 11;
  uint64 recv_done_duration_us = 12;

  string transfer_type = 13;

  int64 host_stall_us = 14;
  uint64 host_events_count = 15;
}

message DcnSlackAnalysis {
  repeated DcnSlack dcn_slack = 1;
  repeated DcnSlackSummary dcn_slack_summary = 2;
}
