telemetry.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. // This module exports methods to record telemetry data for memory tool usage.
  5. //
  6. // NB: Ensure that *every* exported function is wrapped in `makeInfallible` so
  7. // that our probes don't accidentally break code that actually does productive
  8. // work for the user!
  9. const { telemetry } = require("Services");
  10. const { makeInfallible, immutableUpdate } = require("devtools/shared/DevToolsUtils");
  11. const { labelDisplays, treeMapDisplays, censusDisplays } = require("./constants");
  12. exports.countTakeSnapshot = makeInfallible(function () {
  13. const histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_TAKE_SNAPSHOT_COUNT");
  14. histogram.add(1);
  15. }, "devtools/client/memory/telemetry#countTakeSnapshot");
  16. exports.countImportSnapshot = makeInfallible(function () {
  17. const histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_IMPORT_SNAPSHOT_COUNT");
  18. histogram.add(1);
  19. }, "devtools/client/memory/telemetry#countImportSnapshot");
  20. exports.countExportSnapshot = makeInfallible(function () {
  21. const histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_EXPORT_SNAPSHOT_COUNT");
  22. histogram.add(1);
  23. }, "devtools/client/memory/telemetry#countExportSnapshot");
  24. const COARSE_TYPE = "Coarse Type";
  25. const ALLOCATION_STACK = "Allocation Stack";
  26. const INVERTED_ALLOCATION_STACK = "Inverted Allocation Stack";
  27. const CUSTOM = "Custom";
  28. /**
  29. * @param {String|null} filter
  30. * The filter string used, if any.
  31. *
  32. * @param {Boolean} diffing
  33. * True if the census was a diffing census, false otherwise.
  34. *
  35. * @param {censusDisplayModel} display
  36. * The display used with the census.
  37. */
  38. exports.countCensus = makeInfallible(function ({ filter, diffing, display }) {
  39. let histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_INVERTED_CENSUS");
  40. histogram.add(!!display.inverted);
  41. histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_FILTER_CENSUS");
  42. histogram.add(!!filter);
  43. histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_DIFF_CENSUS");
  44. histogram.add(!!diffing);
  45. histogram = telemetry.getKeyedHistogramById("DEVTOOLS_MEMORY_BREAKDOWN_CENSUS_COUNT");
  46. if (display === censusDisplays.coarseType) {
  47. histogram.add(COARSE_TYPE);
  48. } else if (display === censusDisplays.allocationStack) {
  49. histogram.add(ALLOCATION_STACK);
  50. } else if (display === censusDisplays.invertedAllocationStack) {
  51. histogram.add(INVERTED_ALLOCATION_STACK);
  52. } else {
  53. histogram.add(CUSTOM);
  54. }
  55. }, "devtools/client/memory/telemetry#countCensus");
  56. /**
  57. * @param {Object} opts
  58. * The same parameters specified for countCensus.
  59. */
  60. exports.countDiff = makeInfallible(function (opts) {
  61. exports.countCensus(immutableUpdate(opts, { diffing: true }));
  62. }, "devtools/client/memory/telemetry#countDiff");
  63. /**
  64. * @param {Object} display
  65. * The display used to label nodes in the dominator tree.
  66. */
  67. exports.countDominatorTree = makeInfallible(function ({ display }) {
  68. let histogram = telemetry.getHistogramById("DEVTOOLS_MEMORY_DOMINATOR_TREE_COUNT");
  69. histogram.add(1);
  70. histogram = telemetry.getKeyedHistogramById("DEVTOOLS_MEMORY_BREAKDOWN_DOMINATOR_TREE_COUNT");
  71. if (display === labelDisplays.coarseType) {
  72. histogram.add(COARSE_TYPE);
  73. } else if (display === labelDisplays.allocationStack) {
  74. histogram.add(ALLOCATION_STACK);
  75. } else {
  76. histogram.add(CUSTOM);
  77. }
  78. }, "devtools/client/memory/telemetry#countDominatorTree");