createDataTable()

in frontend/app/components/memory_profile/memory_breakdown_table/memory_breakdown_table.ts [35:94]


  createDataTable() {
    if (!this.table || !this.memoryProfileData ||
        !this.memoryProfileData.memoryProfilePerAllocator || !!this.dataTable) {
      return;
    }

    this.dataTable = new google.visualization.DataTable();
    this.dataTable.addColumn('string', 'Op Name');
    this.dataTable.addColumn('number', 'Allocation Size (GiBs)');
    this.dataTable.addColumn('number', 'Requested Size (GiBs)');
    this.dataTable.addColumn('number', 'Occurrences');
    this.dataTable.addColumn('string', 'Region type');
    this.dataTable.addColumn('string', 'Data type');
    this.dataTable.addColumn('string', 'Shape');

    const snapshots =
        this.memoryProfileData.memoryProfilePerAllocator[this.memoryId]
            .memoryProfileSnapshots;
    const activeAllocations =
        this.memoryProfileData.memoryProfilePerAllocator[this.memoryId]
            .activeAllocations;
    const specialAllocations =
        this.memoryProfileData.memoryProfilePerAllocator[this.memoryId]
            .specialAllocations;
    if (!snapshots || !activeAllocations || !specialAllocations) {
      return;
    }

    for (let i = 0; i < activeAllocations.length; i++) {
      const index: number = Number(activeAllocations[i].snapshotIndex);
      const specialIndex = Number(activeAllocations[i].specialIndex);
      // Use snapshot index or special index, whichever is positve.
      let metadata;
      if (index >= 0) {
        // It may be dropped depending on the max_num_snapshots query parameter
        // which is set to 1000 by default.
        if (!(index in snapshots)) continue;
        metadata = snapshots[index].activityMetadata;
      } else {
        metadata = specialAllocations[specialIndex];
      }
      if (!metadata) {
        continue;
      }
      this.dataTable.addRow([
        metadata.tfOpName,
        this.bytesToGiBs(metadata.allocationBytes),
        this.bytesToGiBs(metadata.requestedBytes),
        Number(activeAllocations[i].numOccurrences),
        metadata.regionType,
        metadata.dataType,
        metadata.tensorShape,
      ]);
    }

    const decimalPtFormatter =
        new google.visualization.NumberFormat({fractionDigits: 3});
    decimalPtFormatter.format(this.dataTable, 1); /* requested_size */
    decimalPtFormatter.format(this.dataTable, 2); /* allocation_size */
  }