<commit_before>import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';

import {MemoryProfileProtoOrNull} from 'org_xprof/frontend/app/common/interfaces/data_table';

const DATA_TABLE_OPERATION_INDEX = 0;

/** A memory breakdown table view component. */
@Component({
  selector: 'memory-breakdown-table',
  templateUrl: './memory_breakdown_table.ng.html',
  styleUrls: ['./memory_breakdown_table.scss']
})
export class MemoryBreakdownTable implements OnChanges, OnInit {
  /** The memory profile proto data. */
  @Input() memoryProfileData: MemoryProfileProtoOrNull = null;

  /** The selected memory ID to show memory profile for. */
  @Input() memoryId: string = '';

  @ViewChild('table', {static: false}) tableRef!: ElementRef;

  dataTable: google.visualization.DataTable|null = null;
  filterOperation: string = '';
  table: google.visualization.Table|null = null;

  ngOnInit() {
    this.loadGoogleChart();
  }

  ngOnChanges(changes: SimpleChanges) {
    this.dataTable = null;
    this.drawTable();
  }

  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(activeAllocations[i].snapshotIndex);
      const specialIndex = Number(activeAllocations[i].specialIndex);
      // Use snapshot index or special index, whichever is positve.
      let metadata;<commit_msg>Project import generated by Copybara<commit_after>import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';

import {MemoryProfileProtoOrNull} from 'org_xprof/frontend/app/common/interfaces/data_table';

const DATA_TABLE_OPERATION_INDEX = 0;

/** A memory breakdown table view component. */
@Component({
  selector: 'memory-breakdown-table',
  templateUrl: './memory_breakdown_table.ng.html',
  styleUrls: ['./memory_breakdown_table.scss']
})
export class MemoryBreakdownTable implements OnChanges, OnInit {
  /** The memory profile proto data. */
  @Input() memoryProfileData: MemoryProfileProtoOrNull = null;

  /** The selected memory ID to show memory profile for. */
  @Input() memoryId: string = '';

  @ViewChild('table', {static: false}) tableRef!: ElementRef;

  dataTable: google.visualization.DataTable|null = null;
  filterOperation: string = '';
  table: google.visualization.Table|null = null;

  ngOnInit() {
    this.loadGoogleChart();
  }

  ngOnChanges(changes: SimpleChanges) {
    this.dataTable = null;
    this.drawTable();
  }

  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;
{'fraction_non_alphanumeric': 0.12411989539328103, 'fraction_numerical': 0.0008046670690002012, 'mean_word_length': 4.104722792607803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7594157', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1422, 'n_words': 302}