Example #1
0
add_task(function *() {
  ok(utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", count: true, bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() passes with preset"),

  ok(!utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", count: false, bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() fails when deep properties do not match");

  ok(!utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() fails when deep properties are missing.");

  let s1 = utils.createSnapshot();
  let s2 = utils.createSnapshot();
  ok(s1.state, states.SAVING, "utils.createSnapshot() creates snapshot in saving state");
  ok(s1.id !== s2.id, "utils.createSnapshot() creates snapshot with unique ids");

  ok(utils.breakdownEquals(utils.breakdownNameToSpec("coarseType"), breakdowns.coarseType.breakdown),
    "utils.breakdownNameToSpec() works for presets");
  ok(utils.breakdownEquals(utils.breakdownNameToSpec("coarseType"), breakdowns.coarseType.breakdown),
    "utils.breakdownNameToSpec() works for presets");

  let custom = { by: "internalType", then: { by: "count", bytes: true }};
  Preferences.set("devtools.memory.custom-breakdowns", JSON.stringify({ "My Breakdown": custom }));

  ok(utils.breakdownEquals(utils.getCustomBreakdowns()["My Breakdown"], custom),
    "utils.getCustomBreakdowns() returns custom breakdowns");
});
Example #2
0
  task: function* (heapWorker, id, removeFromCache, dispatch, getState) {
    const snapshot = getSnapshot(getState(), id);
    assert(dominatorTreeIsComputed(snapshot),
           "Should have dominator tree model and it should be computed");

    let display;
    let root;
    do {
      display = getState().labelDisplay;
      assert(display && display.breakdown,
             `Should have a breakdown to describe nodes with, got: ${uneval(display)}`);

      dispatch({ type: actions.FETCH_DOMINATOR_TREE_START, id, display });

      try {
        root = yield heapWorker.getDominatorTree({
          dominatorTreeId: snapshot.dominatorTree.dominatorTreeId,
          breakdown: display.breakdown,
          maxRetainingPaths: Preferences.get("devtools.memory.max-retaining-paths"),
        });
      } catch (error) {
        removeFromCache();
        reportException("actions/snapshot/fetchDominatorTree", error);
        dispatch({ type: actions.DOMINATOR_TREE_ERROR, id, error });
        return null;
      }
    }
    while (display !== getState().labelDisplay);

    removeFromCache();
    dispatch({ type: actions.FETCH_DOMINATOR_TREE_END, id, root });
    telemetry.countDominatorTree({ display });
    return root;
  }
Example #3
0
add_task(function *() {
  ok(utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", count: true, bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() passes with preset"),

  ok(!utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", count: false, bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() fails when deep properties do not match");

  ok(!utils.breakdownEquals(breakdowns.allocationStack.breakdown, {
    by: "allocationStack",
    then: { by: "count", bytes: true },
    noStack: { by: "count", count: true, bytes: true },
  }), "utils.breakdownEquals() fails when deep properties are missing.");

  let s1 = utils.createSnapshot({});
  let s2 = utils.createSnapshot({});
  equal(s1.state, states.SAVING, "utils.createSnapshot() creates snapshot in saving state");
  ok(s1.id !== s2.id, "utils.createSnapshot() creates snapshot with unique ids");

  ok(utils.breakdownEquals(utils.breakdownNameToSpec("coarseType"), breakdowns.coarseType.breakdown),
    "utils.breakdownNameToSpec() works for presets");
  ok(utils.breakdownEquals(utils.breakdownNameToSpec("coarseType"), breakdowns.coarseType.breakdown),
    "utils.breakdownNameToSpec() works for presets");

  let custom = { by: "internalType", then: { by: "count", bytes: true }};
  Preferences.set("devtools.memory.custom-breakdowns", JSON.stringify({ "My Breakdown": custom }));

  ok(utils.breakdownEquals(utils.getCustomBreakdowns()["My Breakdown"], custom),
    "utils.getCustomBreakdowns() returns custom breakdowns");

  ok(true, "test formatNumber util functions");
  equal(utils.formatNumber(12), "12", "formatNumber returns 12 for 12");

  equal(utils.formatNumber(0), "0", "formatNumber returns 0 for 0");
  equal(utils.formatNumber(-0), "0", "formatNumber returns 0 for -0");
  equal(utils.formatNumber(+0), "0", "formatNumber returns 0 for +0");

  equal(utils.formatNumber(1234567), "1 234 567",
    "formatNumber adds a space every 3rd digit");
  equal(utils.formatNumber(12345678), "12 345 678",
    "formatNumber adds a space every 3rd digit");
  equal(utils.formatNumber(123456789), "123 456 789",
    "formatNumber adds a space every 3rd digit");

  equal(utils.formatNumber(12, true), "+12",
    "formatNumber can display number sign");
  equal(utils.formatNumber(-12, true), "-12",
    "formatNumber can display number sign (negative)");

  ok(true, "test formatPercent util functions");
  equal(utils.formatPercent(12), "12%", "formatPercent returns 12% for 12");
  equal(utils.formatPercent(12345), "12 345%",
    "formatPercent returns 12 345% for 12345");
});
Example #4
0
exports.getCustomBreakdowns = function () {
  let customBreakdowns = Object.create(null);
  try {
    customBreakdowns = JSON.parse(Preferences.get(CUSTOM_BREAKDOWN_PREF)) || Object.create(null);
  } catch (e) {
    DevToolsUtils.reportException(
      `String stored in "${CUSTOM_BREAKDOWN_PREF}" pref cannot be parsed by \`JSON.parse()\`.`);
  }
  return customBreakdowns;
}
/**
 * Get the preference value of whether this property is enabled. Returns an empty string
 * if no preference exists.
 *
 * @param {String} propertyName
 * @return {Boolean|undefined}
 */
function getPreference(propertyName) {
  const preference = PREFERENCES.find(([prefPropertyName, preferenceKey]) => {
    return prefPropertyName === propertyName && !!preferenceKey;
  });

  if (preference) {
    return Preferences.get(preference[1]);
  }
  return undefined;
}
function getCustomDisplaysHelper(pref) {
  let customDisplays = Object.create(null);
  try {
    customDisplays = JSON.parse(Preferences.get(pref)) || Object.create(null);
  } catch (e) {
    DevToolsUtils.reportException(
      `String stored in "${pref}" pref cannot be parsed by \`JSON.parse()\`.`);
  }
  return Object.freeze(customDisplays);
}
Example #7
0
add_task(function* () {
  let s1 = utils.createSnapshot({ view: { state: viewState.CENSUS } });
  let s2 = utils.createSnapshot({ view: { state: viewState.CENSUS } });
  equal(s1.state, states.SAVING,
        "utils.createSnapshot() creates snapshot in saving state");
  ok(s1.id !== s2.id, "utils.createSnapshot() creates snapshot with unique ids");

  let custom = { by: "internalType", then: { by: "count", bytes: true }};
  Preferences.set("devtools.memory.custom-census-displays",
                  JSON.stringify({ "My Display": custom }));

  equal(utils.getCustomCensusDisplays()["My Display"].by, custom.by,
        "utils.getCustomCensusDisplays() returns custom displays");

  ok(true, "test formatNumber util functions");
  equal(utils.formatNumber(12), "12", "formatNumber returns 12 for 12");

  equal(utils.formatNumber(0), "0", "formatNumber returns 0 for 0");
  equal(utils.formatNumber(-0), "0", "formatNumber returns 0 for -0");
  equal(utils.formatNumber(+0), "0", "formatNumber returns 0 for +0");

  equal(utils.formatNumber(1234567), "1 234 567",
    "formatNumber adds a space every 3rd digit");
  equal(utils.formatNumber(12345678), "12 345 678",
    "formatNumber adds a space every 3rd digit");
  equal(utils.formatNumber(123456789), "123 456 789",
    "formatNumber adds a space every 3rd digit");

  equal(utils.formatNumber(12, true), "+12",
    "formatNumber can display number sign");
  equal(utils.formatNumber(-12, true), "-12",
    "formatNumber can display number sign (negative)");

  ok(true, "test formatPercent util functions");
  equal(utils.formatPercent(12), "12%", "formatPercent returns 12% for 12");
  equal(utils.formatPercent(12345), "12 345%",
    "formatPercent returns 12 345% for 12345");

  equal(utils.formatAbbreviatedBytes(12), "12B", "Formats bytes");
  equal(utils.formatAbbreviatedBytes(12345), "12KiB", "Formats kilobytes");
  equal(utils.formatAbbreviatedBytes(12345678), "11MiB", "Formats megabytes");
  equal(utils.formatAbbreviatedBytes(12345678912), "11GiB", "Formats gigabytes");

  equal(utils.hslToStyle(0.5, 0.6, 0.7),
    "hsl(180,60%,70%)", "hslToStyle converts an array to a style string");
  equal(utils.hslToStyle(0, 0, 0),
    "hsl(0,0%,0%)", "hslToStyle converts an array to a style string");
  equal(utils.hslToStyle(1, 1, 1),
    "hsl(360,100%,100%)", "hslToStyle converts an array to a style string");

  equal(utils.lerp(5, 7, 0), 5, "lerp return first number for 0");
  equal(utils.lerp(5, 7, 1), 7, "lerp return second number for 1");
  equal(utils.lerp(5, 7, 0.5), 6, "lerp interpolates the numbers for 0.5");
});
Example #8
0
function set(name, value) {
  var prefType;
  if (typeof value != "undefined" && value != null)
    prefType = value.constructor.name;

  switch (prefType) {
  case "Number":
    if (value % 1 != 0)
      throw new Error("cannot store non-integer number: " + value);
  }

  prefs.set(name, value);
}
Example #9
0
  task: function* (heapWorker, id, lazyChildren, removeFromCache, dispatch, getState) {
    const snapshot = getSnapshot(getState(), id);
    assert(snapshot.dominatorTree, "Should have dominator tree model");
    assert(snapshot.dominatorTree.state === dominatorTreeState.LOADED ||
           snapshot.dominatorTree.state === dominatorTreeState.INCREMENTAL_FETCHING,
           "Cannot fetch immediately dominated nodes in a dominator tree unless " +
           " the dominator tree has already been computed");

    let display;
    let response;
    do {
      display = getState().labelDisplay;
      assert(display, "Should have a display to describe nodes with.");

      dispatch({ type: actions.FETCH_IMMEDIATELY_DOMINATED_START, id });

      try {
        response = yield heapWorker.getImmediatelyDominated({
          dominatorTreeId: snapshot.dominatorTree.dominatorTreeId,
          breakdown: display.breakdown,
          nodeId: lazyChildren.parentNodeId(),
          startIndex: lazyChildren.siblingIndex(),
          maxRetainingPaths: Preferences.get("devtools.memory.max-retaining-paths"),
        });
      } catch (error) {
        removeFromCache();
        reportException("actions/snapshot/fetchImmediatelyDominated", error);
        dispatch({ type: actions.DOMINATOR_TREE_ERROR, id, error });
        return null;
      }
    }
    while (display !== getState().labelDisplay);

    removeFromCache();
    dispatch({
      type: actions.FETCH_IMMEDIATELY_DOMINATED_END,
      id,
      path: response.path,
      nodes: response.nodes,
      moreChildrenAvailable: response.moreChildrenAvailable,
    });
  }
Example #10
0
exports.rollbackPrefsToDefault = function () {
  for (let prefName of Object.keys(exports.DEFAULT_PREF_VALUES)) {
    Preferences.set(prefName, exports.DEFAULT_PREF_VALUES[prefName]);
  }
};
Example #11
0
].reduce((prefValues, prefName) => {
  prefValues[prefName] = Preferences.get(prefName);
  return prefValues;
}, {});
Example #12
0
  return function* (dispatch, getState) {
    if (getState().view.state !== viewState.INDIVIDUALS) {
      dispatch(view.changeView(viewState.INDIVIDUALS));
    }

    const snapshot = getSnapshot(getState(), id);
    assert(snapshot && snapshot.state === states.READ,
           "The snapshot should already be read into memory");

    if (!dominatorTreeIsComputed(snapshot)) {
      yield dispatch(computeAndFetchDominatorTree(heapWorker, id));
    }

    const snapshot_ = getSnapshot(getState(), id);
    assert(snapshot_.dominatorTree && snapshot_.dominatorTree.root,
           "Should have a dominator tree with a root.");

    const dominatorTreeId = snapshot_.dominatorTree.dominatorTreeId;

    const indices = isSet(reportLeafIndex)
      ? reportLeafIndex
      : new Set([reportLeafIndex]);

    let labelDisplay;
    let nodes;
    do {
      labelDisplay = getState().labelDisplay;
      assert(labelDisplay && labelDisplay.breakdown && labelDisplay.breakdown.by,
             `Should have a breakdown to label nodes with, got: ${uneval(labelDisplay)}`);

      if (getState().view.state !== viewState.INDIVIDUALS) {
        // We switched views while in the process of fetching individuals -- any
        // further work is useless.
        return;
      }

      dispatch({ type: actions.FETCH_INDIVIDUALS_START });

      try {
        ({ nodes } = yield heapWorker.getCensusIndividuals({
          dominatorTreeId,
          indices,
          censusBreakdown,
          labelBreakdown: labelDisplay.breakdown,
          maxRetainingPaths: Preferences.get("devtools.memory.max-retaining-paths"),
          maxIndividuals: Preferences.get("devtools.memory.max-individuals"),
        }));
      } catch (error) {
        reportException("actions/snapshot/fetchIndividuals", error);
        dispatch({ type: actions.INDIVIDUALS_ERROR, error });
        return;
      }
    }
    while (labelDisplay !== getState().labelDisplay);

    dispatch({
      type: actions.FETCH_INDIVIDUALS_END,
      id,
      censusBreakdown,
      indices,
      labelDisplay,
      nodes,
      dominatorTree: snapshot_.dominatorTree,
    });
  };
Example #13
0
function get(name, defaultValue) {
  return prefs.get(name, defaultValue);
}
Example #14
0
 set: function (prefName, value) {
   let fullName = this.branchName + prefName;
   Preferences.set(fullName, value);
 },
Example #15
0
 get: function (prefName) {
   let fullName = this.branchName + prefName;
   return Preferences.get(fullName);
 },