1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsISupports.idl"
9 [scriptable
,function
, uuid(3d3b9075
-5549-4244-9c08
-b64fefa1dd60
)]
10 interface nsIFetchTelemetryDataCallback
: nsISupports
15 [scriptable
, uuid(273d2dd0
-6c63
-475a
-b864
-cb65160a1909
)]
16 interface nsITelemetry
: nsISupports
20 * HISTOGRAM_EXPONENTIAL - buckets increase exponentially
21 * HISTOGRAM_LINEAR - buckets increase linearly
22 * HISTOGRAM_BOOLEAN - For storing 0/1 values
23 * HISTOGRAM_FLAG - For storing a single value; its count is always == 1.
24 * HISTOGRAM_COUNT - For storing counter values without bucketing.
25 * HISTOGRAM_CATEGORICAL - For storing enumerated values by label.
27 const unsigned long HISTOGRAM_EXPONENTIAL
= 0;
28 const unsigned long HISTOGRAM_LINEAR
= 1;
29 const unsigned long HISTOGRAM_BOOLEAN
= 2;
30 const unsigned long HISTOGRAM_FLAG
= 3;
31 const unsigned long HISTOGRAM_COUNT
= 4;
32 const unsigned long HISTOGRAM_CATEGORICAL
= 5;
36 * SCALAR_TYPE_COUNT - for storing a numeric value
37 * SCALAR_TYPE_STRING - for storing a string value
38 * SCALAR_TYPE_BOOLEAN - for storing a boolean value
40 const unsigned long SCALAR_TYPE_COUNT
= 0;
41 const unsigned long SCALAR_TYPE_STRING
= 1;
42 const unsigned long SCALAR_TYPE_BOOLEAN
= 2;
46 * DATASET_ALL_CHANNELS - the basic dataset that is on-by-default on all channels
47 * DATASET_PRERELEASE_CHANNELS - the extended dataset that is opt-in on release,
48 * opt-out on pre-release channels.
50 const unsigned long DATASET_ALL_CHANNELS
= 0;
51 const unsigned long DATASET_PRERELEASE_CHANNELS
= 1;
54 * Serializes the histogram labels for categorical hitograms.
55 * The returned structure looks like:
56 * { "histogram1": [ "histogram1_label1", "histogram1_label2", ...],
57 * "histogram2": [ "histogram2_label1", "histogram2_label2", ...]
61 * Note that this function should only be used in tests and about:telemetry.
64 jsval getCategoricalLabels
();
67 * Serializes the histograms from the given store to a JSON-style object.
68 * The returned structure looks like:
69 * { "process": { "name1": histogramData1, "name2": histogramData2 }, ... }
71 * Each histogram is represented in a packed format and has the following properties:
72 * bucket_count - Number of buckets of this histogram
73 * histogram_type - HISTOGRAM_EXPONENTIAL, HISTOGRAM_LINEAR, HISTOGRAM_BOOLEAN,
74 * HISTOGRAM_FLAG, HISTOGRAM_COUNT, or HISTOGRAM_CATEGORICAL
75 * sum - sum of the bucket contents
76 * range - A 2-item array of minimum and maximum bucket size
77 * values - Map from bucket to the bucket's count
79 * @param aStoreName The name of the store to snapshot.
81 * Custom stores are available when probes have them defined.
82 * See the `record_into_store` attribute on histograms.
83 * @see https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/histograms.html#record-into-store
84 * @param aClearStore Whether to clear out the histograms in the named store after snapshotting.
86 * @param aFilterTest If true, `TELEMETRY_TEST_` histograms will be filtered out.
87 Filtered histograms are still cleared if `aClearStore` is true.
91 jsval getSnapshotForHistograms
([optional] in ACString aStoreName
, [optional] in boolean aClearStore
, [optional] in boolean aFilterTest
);
94 * Serializes the keyed histograms from the given store to a JSON-style object.
95 * The returned structure looks like:
96 * { "process": { "name1": { "key_1": histogramData1, "key_2": histogramData2 }, ...}, ... }
98 * @param aStoreName The name of the store to snapshot.
100 * Custom stores are available when probes have them defined.
101 * See the `record_into_store` attribute on histograms.
102 * @see https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/histograms.html#record-into-store
103 * @param aClearStore Whether to clear out the keyed histograms in the named store after snapshotting.
105 * @param aFilterTest If true, `TELEMETRY_TEST_` histograms will be filtered out.
106 Filtered histograms are still cleared if `aClearStore` is true.
110 jsval getSnapshotForKeyedHistograms
([optional] in ACString aStoreName
, [optional] in boolean aClearStore
, [optional] in boolean aFilterTest
);
113 * Serializes the scalars from the given store to a JSON-style object.
114 * The returned structure looks like:
115 * { "process": { "category1.probe": 1,"category1.other_probe": false, ... }, ... }.
117 * @param aStoreName The name of the store to snapshot.
118 * Defaults to "main".
119 * Custom stores are available when probes have them defined.
120 * See the `record_into_store` attribute on scalars.
121 * @see https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/scalars.html#optional-fields
122 * @param aClearStore Whether to clear out the scalars in the named store after snapshotting.
124 * @param aFilterTest If true, `telemetry.test` scalars will be filtered out.
125 Filtered scalars are still cleared if `aClearStore` is true.
129 jsval getSnapshotForScalars
([optional] in ACString aStoreName
, [optional] in boolean aClearStore
, [optional] in boolean aFilterTest
);
132 * Serializes the keyed scalars from the given store to a JSON-style object.
133 * The returned structure looks like:
134 * { "process": { "category1.probe": { "key_1": 2, "key_2": 1, ... }, ... }, ... }
136 * @param aStoreName The name of the store to snapshot.
137 * Defaults to "main".
138 * Custom stores are available when probes have them defined.
139 * See the `record_into_store` attribute on scalars.
140 * @see https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/scalars.html#optional-fields
141 * @param aClearStore Whether to clear out the keyed scalars in the named store after snapshotting.
143 * @param aFilterTest If true, `telemetry.test` scalars will be filtered out.
144 Filtered scalars are still cleared if `aClearStore` is true.
148 jsval getSnapshotForKeyedScalars
([optional] in ACString aStoreName
, [optional] in boolean aClearStore
, [optional] in boolean aFilterTest
);
151 * The amount of time, in milliseconds, that the last session took
152 * to shutdown. Reads as 0 to indicate failure.
154 readonly attribute uint32_t lastShutdownDuration
;
157 * The number of failed profile lock attempts that have occurred prior to
158 * successfully locking the profile
160 readonly attribute uint32_t failedProfileLockCount
;
163 * An object containing information about slow SQL statements.
166 * mainThread: { "sqlString1": [<hit count>, <total time>], "sqlString2": [...], ... },
167 * otherThreads: { "sqlString3": [<hit count>, <total time>], "sqlString4": [...], ... }
171 * mainThread: Slow statements that executed on the main thread
172 * otherThreads: Slow statements that executed on a non-main thread
173 * sqlString - String of the offending statement (see note)
174 * hit count - The number of times this statement required longer than the threshold time to execute
175 * total time - The sum of all execution times above the threshold time for this statement
177 * Note that dynamic SQL strings and SQL strings executed against addon DBs could contain private information.
178 * This property represents such SQL as aggregate database-level stats and the sqlString contains the database
182 readonly attribute jsval slowSQL
;
187 * An object containing full strings of every slow SQL statement if toolkit.telemetry.debugSlowSql = true
188 * The returned SQL strings may contain private information and should not be reported to Telemetry.
191 readonly attribute jsval debugSlowSQL
;
194 * Flags for getUntrustedModuleLoadEvents.
198 * This flag is set to retrieve all data including instances which have been
199 * retrieved before. If not set, only new instances since the last call
201 * If this flag is set, KEEP_LOADEVENTS_NEW must not be set unless
202 * EXCLUDE_STACKINFO_FROM_LOADEVENTS is set.
203 * (See also MultiGetUntrustedModulesData::Serialize.)
205 const unsigned long INCLUDE_OLD_LOADEVENTS
= 1 << 0;
208 * This flag is set to keep the returned instances as if they were not
209 * retrieved, meaning those instances will be returned by a next method
210 * call without INCLUDE_OLD_LOADEVENTS. If not set, the returned instances
211 * can be re-retrieved only when INCLUDE_OLD_LOADEVENTS is specified.
212 * If this flag is set, INCLUDE_OLD_LOADEVENTS must not be set unless
213 * EXCLUDE_STACKINFO_FROM_LOADEVENTS is set.
214 * (See also MultiGetUntrustedModulesData::Serialize.)
216 const unsigned long KEEP_LOADEVENTS_NEW
= 1 << 1;
219 * This flag is set to include private fields.
220 * Do not specify this flag to retrieve data to be submitted.
222 const unsigned long INCLUDE_PRIVATE_FIELDS_IN_LOADEVENTS
= 1 << 2;
225 * This flag is set to exclude the "combinedStacks" field.
226 * Without this flag, the flags INCLUDE_OLD_LOADEVENTS and KEEP_LOADEVENTS_NEW
227 * cannot be set at the same time.
229 const unsigned long EXCLUDE_STACKINFO_FROM_LOADEVENTS
= 1 << 3;
232 * An array of untrusted module load events. Each element describes one or
233 * more modules that were loaded, contextual information at the time of the
234 * event (including stack trace), and flags describing the module's
237 * @param aFlags Combination (bitwise OR) of the flags specified above.
241 Promise getUntrustedModuleLoadEvents
([optional] in unsigned long aFlags
);
244 * Whether the untrusted module load events are ready for processing.
245 * Calling getUntrustedModuleLoadEvents() before this attribute is true
246 * will result in an empty array. */
247 readonly attribute
boolean areUntrustedModuleLoadEventsReady
;
250 * Asynchronously get an array of the modules loaded in the process.
252 * The data has the following structure:
256 * "name": <string>, // Name of the module file (e.g. xul.dll)
257 * "version": <string>, // Version of the module
258 * "debugName": <string>, // ID of the debug information file
259 * "debugID": <string>, // Name of the debug information file
260 * "certSubject": <string>, // Name of the organization that signed the binary (Optional, only defined when present)
265 * @return A promise that resolves to an array of modules or rejects with
266 NS_ERROR_FAILURE on failure.
267 * @throws NS_ERROR_NOT_IMPLEMENTED if the Gecko profiler is not enabled.
270 Promise getLoadedModules
();
273 * An object with two fields: memoryMap and stacks.
274 * * memoryMap is a list of loaded libraries.
275 * * stacks is a list of stacks. Each stack is a list of pairs of the form
276 * [moduleIndex, offset]. The moduleIndex is an index into the memoryMap and
277 * offset is an offset in the library at memoryMap[moduleIndex].
278 * This format is used to make it easier to send the stacks to the
279 * symbolication server.
282 readonly attribute jsval lateWrites
;
285 * Create and return a histogram registered in TelemetryHistograms.h.
287 * @param id - unique identifier from TelemetryHistograms.h
288 * The returned object has the following functions:
289 * add(value) - Adds a sample of `value` to the histogram.
290 `value` may be a categorical histogram's label as a string,
291 a boolean histogram's value as a boolean,
292 or a number that fits inside a uint32_t.
293 * snapshot([optional] {store}) - Returns a snapshot of the histogram with the same data fields
294 as in getSnapshotForHistograms().
295 Defaults to the "main" store.
296 * clear([optional] {store}) - Zeros out the histogram's buckets and sum.
297 Defaults to the "main" store.
298 Note: This is intended to be only used in tests.
301 jsval getHistogramById
(in ACString
id);
304 * Create and return a histogram registered in TelemetryHistograms.h.
306 * @param id - unique identifier from TelemetryHistograms.h
307 * The returned object has the following functions:
308 * add(string key, [optional] value) - Adds a sample of `value` to the histogram for that key.
309 If no histogram for that key exists yet, it is created.
310 `value` may be a categorical histogram's label as a string,
311 a boolean histogram's value as a boolean,
312 or a number that fits inside a uint32_t.
313 * snapshot([optional] {store}) - Returns the snapshots of all the registered keys in the form
314 {key1: snapshot1, key2: snapshot2, ...} in the specified store.
315 * Defaults to the "main" store.
316 * keys([optional] {store}) - Returns an array with the string keys of the currently registered
317 histograms in the given store.
319 * clear([optional] {store}) - Clears the registered histograms from this.
320 * Defaults to the "main" store.
321 * Note: This is intended to be only used in tests.
324 jsval getKeyedHistogramById
(in ACString
id);
327 * A flag indicating if Telemetry can record base data (FHR data). This is true if the
328 * FHR data reporting service or self-support are enabled.
330 * In the unlikely event that adding a new base probe is needed, please check the data
331 * collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
334 attribute
boolean canRecordBase
;
337 * A flag indicating if Telemetry is allowed to record extended data. Returns false if
338 * the user hasn't opted into "extended Telemetry" on the Release channel, when the
339 * user has explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually
340 * set to false during tests.
342 * Set this to false in tests to disable gathering of extended telemetry statistics.
344 attribute
boolean canRecordExtended
;
347 * A flag indicating whether Telemetry is recording release data, which is a
348 * smallish subset of our usage data that we're prepared to handle from our
349 * largish release population.
351 * This is true most of the time.
353 * This will always return true in the case of a non-content child process.
354 * Only values returned on the parent process are valid.
356 * This does not indicate whether Telemetry will send any data. That is
357 * governed by user preference and other mechanisms.
359 * You may use this to determine if it's okay to record your data.
361 readonly attribute
boolean canRecordReleaseData
;
364 * A flag indicating whether Telemetry is recording prerelease data, which is
365 * a largish amount of usage data that we're prepared to handle from our
366 * smallish pre-release population.
368 * This is true on pre-release branches of Firefox.
370 * This does not indicate whether Telemetry will send any data. That is
371 * governed by user preference and other mechanisms.
373 * You may use this to determine if it's okay to record your data.
375 readonly attribute
boolean canRecordPrereleaseData
;
378 * A flag indicating whether Telemetry can submit official results (for base or extended
379 * data). This is true on official, non-debug builds with built in support for Mozilla
380 * Telemetry reporting.
382 * This will always return true in the case of a non-content child process.
383 * Only values returned on the parent process are valid.
385 readonly attribute
boolean isOfficialTelemetry
;
388 * Read data from the previous run. After the callback is called, the last
389 * shutdown time is available in lastShutdownDuration and any late
390 * writes in lateWrites.
392 void asyncFetchTelemetryData
(in nsIFetchTelemetryDataCallback aCallback
);
395 * Get statistics of file IO reports, null, if not recorded.
397 * The statistics are returned as an object whose propoerties are the names
398 * of the files that have been accessed and whose corresponding values are
399 * arrays of size three, representing startup, normal, and shutdown stages.
400 * Each stage's entry is either null or an array with the layout
401 * [total_time, #creates, #reads, #writes, #fsyncs, #stats]
404 readonly attribute jsval fileIOReports
;
407 * Return the number of milliseconds since process start using monotonic
408 * timestamps (unaffected by system clock changes). On Windows, this includes
409 * the period of time the device was suspended. On Linux and macOS, this does
410 * not include the period of time the device was suspneded.
412 double msSinceProcessStart
();
415 * Return the number of milliseconds since process start using monotonic
416 * timestamps (unaffected by system clock changes), including the periods of
417 * time the device was suspended.
418 * @throws NS_ERROR_NOT_AVAILABLE if unavailable.
420 double msSinceProcessStartIncludingSuspend
();
423 * Return the number of milliseconds since process start using monotonic
424 * timestamps (unaffected by system clock changes), excluding the periods of
425 * time the device was suspended.
426 * @throws NS_ERROR_NOT_AVAILABLE if unavailable.
428 double msSinceProcessStartExcludingSuspend
();
431 * Time since the system wide epoch. This is not a monotonic timer but
432 * can be used across process boundaries.
434 double msSystemNow
();
437 * Resets all the stored scalars. This is intended to be only used in tests.
442 * Immediately sends any Telemetry batched on this process to the parent
443 * process. This is intended only to be used on process shutdown.
445 void flushBatchedChildTelemetry
();
448 * Serializes the recorded events to a JSON-appropriate array and optionally resets them.
449 * The returned structure looks like this:
451 * // [timestamp, category, method, object, stringValue, extraValues]
452 * [43245, "category1", "method1", "object1", "string value", null],
453 * [43258, "category1", "method2", "object1", null, {"key1": "string value"}],
457 * @param aDataset DATASET_ALL_CHANNELS or DATASET_PRERELEASE_CHANNELS.
458 * @param [aClear=false] Whether to clear out the flushed events after snapshotting.
459 * @param aEventLimit How many events per process to limit the snapshot to contain, all if unspecified.
460 * Even if aClear, the leftover event records are not cleared.
462 [implicit_jscontext
, optional_argc
]
463 jsval snapshotEvents
(in uint32_t aDataset
, [optional] in boolean aClear
, [optional] in uint32_t aEventLimit
);
466 * Parent process only. Register dynamic builtin events.
468 * This function is only meant to be used to support the "artifact build"/
469 * "build faster" developers by allowing to add new events without rebuilding
470 * the C++ components including the headers files.
472 * @param aCategory The unique category the events are registered in.
473 * @param aEventData An object that contains registration data for 1-N events of the form:
476 * "methods": ["test1"],
477 * "objects": ["object1"],
478 * "record_on_release": false,
479 * "extra_keys": ["key1", "key2"], // optional
480 * "expired": false // optional, defaults to false.
484 * @param aEventData.<name>.methods List of methods for this event entry.
485 * @param aEventData.<name>.objects List of objects for this event entry.
486 * @param aEventData.<name>.extra_keys Optional, list of allowed extra keys for this event entry.
487 * @param aEventData.<name>.record_on_release Optional, whether to record this data on release.
489 * @param aEventData.<name>.expired Optional, whether this event entry is expired. This allows
490 * recording it without error, but it will be discarded. Defaults to false.
493 void registerBuiltinEvents
(in ACString aCategory
, in jsval aEventData
);
496 * Parent process only. Register dynamic builtin scalars. This allows
497 * registering multiple scalars for a category. They will be valid only for
498 * the current Firefox session.
500 * This function is only meant to be used to support the "artifact build"/
501 * "build faster" developers by allowing to add new scalars without rebuilding
502 * the C++ components including the headers files.
504 * @param aCategoryName The unique category the scalars are registered in.
505 * @param aScalarData An object that contains registration data for multiple scalars in the form:
508 * "kind": Ci.nsITelemetry.SCALAR_TYPE_COUNT,
509 * "keyed": true, //optional, defaults to false
510 * "record_on_release: true, // optional, defaults to false
511 * "expired": false // optional, defaults to false.
515 * @param aScalarData.<name>.kind One of the scalar types defined in this file (SCALAR_TYPE_*)
516 * @param aScalarData.<name>.keyed Optional, whether this is a keyed scalar or not. Defaults to false.
517 * @param aScalarData.<name>.record_on_release Optional, whether to record this data on release.
519 * @param aScalarData.<name>.expired Optional, whether this scalar entry is expired. This allows
520 * recording it without error, but it will be discarded. Defaults to false.
523 void registerBuiltinScalars
(in ACString aCategoryName
, in jsval aScalarData
);
526 * Resets all the stored events. This is intended to be only used in tests.
527 * Events recorded but not yet flushed to the parent process storage won't be cleared.
528 * Override the pref. `toolkit.telemetry.ipcBatchTimeout` to reduce the time to flush events.
533 * Get a list of all registered stores.
535 * The list is deduplicated, but unordered.
538 jsval getAllStores
();
541 * Does early, cheap initialization for native telemetry data providers.
542 * Currently, this includes only MemoryTelemetry.
547 * Does late, expensive initialization for native telemetry data providers.
548 * Currently, this includes only MemoryTelemetry.
550 * This should only be called after startup has completed and the event loop
556 * Shuts down native telemetry providers. Currently, this includes only
562 * Gathers telemetry data for memory usage and records it to the data store.
563 * Returns a promise which resolves when asynchronous data collection has
564 * completed and all data has been recorded.
567 Promise gatherMemory
();