<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { oneLine } from 'common-tags';
import {
  formatNumber,
  formatPercent,
  formatBytes,
  formatSeconds,
  formatMilliseconds,
  formatTimestamp,
  formatMicroseconds,
  formatNanoseconds,
} from '../utils/format-numbers';
import { ensureExists } from '../utils/flow';
import type {
  CategoryList,
  MarkerFormatType,
  MarkerSchema,
  MarkerSchemaByName,
  Marker,
  MarkerIndex,
} from 'firefox-profiler/types';

/**
 * The marker schema comes from Gecko, and is embedded in the profile. However,
 * we may want to define schemas that are front-end only. This is the location
 * to do that. The schema will get merged in with the Gecko schema.
 */
export const markerSchemaFrontEndOnly: MarkerSchema[] = [
  {
    name: 'Jank',
    display: ['marker-table', 'marker-chart'],
    tooltipLabel: 'Jank – event processing delay',
    tableLabel: 'Event processing delay',
    data: [
      {
        label: 'Description',
        value: oneLine`
          Jank markers show when the main event loop of a thread has been busy. It is
          a good indicator that there may be some kind of performance problem that
          is worth investigating.
        `,
      },
    ],
  },
  // Note, these can also come from Gecko, but since we have lots of special handling
  // for IPC, the Gecko ones get overwritten by this definition.
  {
    name: 'IPC',
    tooltipLabel: 'IPC — {marker.data.niceDirection}',
    tableLabel:
      '{marker.name} — {marker.data.messageType} — {marker.data.niceDirection}',
    chartLabel: '{marker.data.messageType}',
    display: ['marker-chart', 'marker-table', 'timeline-ipc'],
    data: [
      { key: 'messageType', label: 'Type', format: 'string' },
      { key: 'sync', label: 'Sync', format: 'string' },
      { key: 'sendThreadName', label: 'From', format: 'string' },
      { key: 'recvThreadName', label: 'To', format: 'string' },
    ],
  },
];

/**
 * For the most part, schema is matched up by the Payload's "type" field,
 * but for practical purposes, there are a few other options, see the
 * implementation of this function for details.
 */
export function getMarkerSchemaName(
  markerSchemaByName: MarkerSchemaByName,
  marker: Marker
): string {
  const { data, name } = marker;
  // Fall back to using the name if no payload exists.

  if (data) {
    const { type } = data;
    if (type === 'tracing' && data.category) {
      // TODO - Tracing markers have a duplicate "category" field.
      // See issue #2749
      return data.category;
    }
    if (type === 'Text') {
      // Text markers are a cheap and easy way to create markers with
      // a category. Check for schema if it exists, if not, fallback to
      // a Text type marker.
      return markerSchemaByName[name] === undefined ? 'Text' : name;
    }
    return data.type;
  }

  return name;<commit_msg>Include tracing markers without a schema in the marker chart and table<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { oneLine } from 'common-tags';
import {
  formatNumber,
  formatPercent,
  formatBytes,
  formatSeconds,
  formatMilliseconds,
  formatTimestamp,
  formatMicroseconds,
  formatNanoseconds,
} from '../utils/format-numbers';
import { ensureExists } from '../utils/flow';
import type {
  CategoryList,
  MarkerFormatType,
  MarkerSchema,
  MarkerSchemaByName,
  Marker,
  MarkerIndex,
} from 'firefox-profiler/types';

/**
 * The marker schema comes from Gecko, and is embedded in the profile. However,
 * we may want to define schemas that are front-end only. This is the location
 * to do that. The schema will get merged in with the Gecko schema.
 */
export const markerSchemaFrontEndOnly: MarkerSchema[] = [
  {
    name: 'Jank',
    display: ['marker-table', 'marker-chart'],
    tooltipLabel: 'Jank – event processing delay',
    tableLabel: 'Event processing delay',
    data: [
      {
        label: 'Description',
        value: oneLine`
          Jank markers show when the main event loop of a thread has been busy. It is
          a good indicator that there may be some kind of performance problem that
          is worth investigating.
        `,
      },
    ],
  },
  // Note, these can also come from Gecko, but since we have lots of special handling
  // for IPC, the Gecko ones get overwritten by this definition.
  {
    name: 'IPC',
    tooltipLabel: 'IPC — {marker.data.niceDirection}',
    tableLabel:
      '{marker.name} — {marker.data.messageType} — {marker.data.niceDirection}',
    chartLabel: '{marker.data.messageType}',
    display: ['marker-chart', 'marker-table', 'timeline-ipc'],
    data: [
      { key: 'messageType', label: 'Type', format: 'string' },
      { key: 'sync', label: 'Sync', format: 'string' },
      { key: 'sendThreadName', label: 'From', format: 'string' },
      { key: 'recvThreadName', label: 'To', format: 'string' },
    ],
  },
];

/**
 * For the most part, schema is matched up by the Payload's "type" field,
 * but for practical purposes, there are a few other options, see the
 * implementation of this function for details.
 */
export function getMarkerSchemaName(
  markerSchemaByName: MarkerSchemaByName,
  marker: Marker
): string {
  const { data, name } = marker;
  // Fall back to using the name if no payload exists.

  if (data) {
    const { type } = data;
    if (type === 'tracing' && data.category) {
      // TODO - Tracing markers have a duplicate "category" field.
      // See issue #2749

      // Does a marker schema for the "category" exist?
      return markerSchemaByName[data.category]
        ? // If so, use the category as the schema name.
          data.category
        : // Otherwise default back to tracing
          'tracing';
    }
    if (type === 'Text') {
      // Text markers are a cheap and easy way to create markers with
      // a category. Check for schema if it exists, if not, fallback to
      // a Text type marker.
      return markerSchemaByName[name] === undefined ? 'Text' : name;
    }
    return data.type;
  }

  return name;
{'fraction_non_alphanumeric': 0.11392009987515606, 'fraction_numerical': 0.0024968789013732834, 'mean_word_length': 2.898418491484185, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7301184', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1848, 'n_words': 722}