GleanMetrics.webidl (24304B)
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. 5 */ 6 7 // The definitions in this file are not sorted. 8 // Please add new ones to the bottom. 9 10 /** 11 * Base interface for all metric types to make typing more expressive. 12 */ 13 [Func="GleanWebidlEnabled", Exposed=Window] 14 interface GleanMetric {}; 15 16 [Func="GleanWebidlEnabled", Exposed=Window] 17 interface GleanBoolean : GleanMetric { 18 /** 19 * Set to the specified boolean value. 20 * 21 * @param value the value to set. 22 */ 23 undefined set(boolean value); 24 25 /** 26 * **Test-only API** 27 * 28 * Gets the currently stored value as a boolean. 29 * 30 * This function will attempt to await the last parent-process task (if any) 31 * writing to the the metric's storage engine before returning a value. 32 * This function will not wait for data from child processes. 33 * 34 * This doesn't clear the stored value. 35 * Parent process only. Panics in child processes. 36 * 37 * @param aPingName The (optional) name of the ping to retrieve the metric 38 * for. Defaults to the first value in `send_in_pings`. 39 * 40 * @return value of the stored metric, or null if there is no value. 41 */ 42 [Throws, ChromeOnly] 43 boolean? testGetValue(optional UTF8String aPingName = ""); 44 }; 45 46 [Func="GleanWebidlEnabled", Exposed=Window] 47 interface GleanDatetime : GleanMetric { 48 /** 49 * Set the datetime to the provided value, or the local now. 50 * The internal value will store the local timezone. 51 * 52 * Note: The metric's time_unit affects the resolution of the value, not the 53 * unit of this function's parameter (which is always PRTime/ 54 * microseconds). 55 * 56 * @param aValue The (optional) time value as PRTime (microseconds since 57 * epoch). 58 * Defaults to local now. 59 */ 60 undefined set(optional long long aValue); 61 62 /** 63 * **Test-only API** 64 * 65 * Gets the currently stored value as a Date. 66 * 67 * This function will attempt to await the last parent-process task (if any) 68 * writing to the the metric's storage engine before returning a value. 69 * This function will not wait for data from child processes. 70 * 71 * This doesn't clear the stored value. 72 * Parent process only. Panics in child processes. 73 * 74 * @param aPingName The (optional) name of the ping to retrieve the metric 75 * for. Defaults to the first value in `send_in_pings`. 76 * 77 * @return value of the stored metric as a JS Date with timezone, 78 * or null if there is no value. 79 */ 80 [Throws, ChromeOnly] 81 any testGetValue(optional UTF8String aPingName = ""); 82 }; 83 84 [Func="GleanWebidlEnabled", Exposed=Window] 85 interface GleanCounter : GleanMetric { 86 /* 87 * Increases the counter by `amount`. 88 * 89 * @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1. 90 */ 91 undefined add(optional long aAmount = 1); 92 93 /** 94 * **Test-only API** 95 * 96 * Gets the currently stored value as an integer. 97 * 98 * This function will attempt to await the last parent-process task (if any) 99 * writing to the the metric's storage engine before returning a value. 100 * This function will not wait for data from child processes. 101 * 102 * This doesn't clear the stored value. 103 * Parent process only. Panics in child processes. 104 * 105 * @param aPingName The (optional) name of the ping to retrieve the metric 106 * for. Defaults to the first value in `send_in_pings`. 107 * 108 * @return value of the stored metric, or null if there is no value. 109 */ 110 [Throws, ChromeOnly] 111 long? testGetValue(optional UTF8String aPingName = ""); 112 }; 113 114 dictionary GleanDistributionData { 115 required unsigned long long sum; 116 required unsigned long long count; 117 required record<UTF8String, unsigned long long> values; 118 }; 119 120 [Func="GleanWebidlEnabled", Exposed=Window] 121 interface GleanTimingDistribution : GleanMetric { 122 /** 123 * Starts tracking time for the provided metric. 124 * 125 * @returns A unique timer id for the new timer 126 */ 127 unsigned long long start(); 128 129 /** 130 * Stops tracking time for the provided metric and timer id. 131 * 132 * Adds a count to the corresponding bucket in the timing distribution. 133 * This will record an error if no `start` was called for this TimerId or 134 * if this TimerId was used to call `cancel`. 135 * 136 * @param aId The TimerId associated with this timing. This allows for 137 * concurrent timing of events associated with different ids. 138 */ 139 undefined stopAndAccumulate(unsigned long long aId); 140 141 /** 142 * Aborts a previous `start` call. No error is recorded if no `start` was 143 * called. (But then where did you get that id from?) 144 * 145 * @param aId The TimerID whose `start` you wish to abort. 146 */ 147 undefined cancel(unsigned long long aId); 148 149 /** 150 * Accumulates the provided signed samples in the metric. 151 * 152 * Sample values must be in the unit declared declared by the instance of the metric type. 153 * 154 * @param aSamples - The vector holding the samples to be recorded by the metric. 155 * 156 * Notes: Discards any negative value in `samples` 157 * and report an `ErrorType::InvalidValue` for each of them. 158 */ 159 undefined accumulateSamples(sequence<long long> aSamples); 160 161 /** 162 * Accumulates the provided single signed sample in the metric. 163 * 164 * Sample values must be in the unit declared declared by the instance of the metric type. 165 * 166 * @param aSample - The sample to be recorded by the metric. 167 * 168 * Notes: Discards any negative value of `sample` and reports an 169 * `ErrorType::InvalidValue`. 170 */ 171 undefined accumulateSingleSample(long long aSample); 172 173 /** 174 * **Test-only API** 175 * 176 * Gets the currently stored value. 177 * 178 * This function will attempt to await the last parent-process task (if any) 179 * writing to the the metric's storage engine before returning a value. 180 * This function will not wait for data from child processes. 181 * 182 * This doesn't clear the stored value. 183 * Parent process only. Panics in child processes. 184 * 185 * @param aPingName The (optional) name of the ping to retrieve the metric 186 * for. Defaults to the first value in `send_in_pings`. 187 * 188 * @return value of the stored metric, or null if there is no value. 189 */ 190 [Throws, ChromeOnly] 191 GleanDistributionData? testGetValue(optional UTF8String aPingName = ""); 192 193 /** 194 * **Test-only API** 195 * 196 * Accumulates a raw numeric sample of milliseconds. 197 * 198 * @param aSample The sample, in milliseconds, to add. 199 */ 200 [ChromeOnly] 201 undefined testAccumulateRawMillis(unsigned long long aSample); 202 }; 203 204 [Func="GleanWebidlEnabled", Exposed=Window] 205 interface GleanMemoryDistribution : GleanMetric { 206 /** 207 * Accumulates the provided signed sample in the metric. 208 * 209 * @param aSample The sample to be recorded by the metric. The sample is 210 * assumed to be in the confgured memory unit of the metric. 211 * 212 * Notes: Values bigger than 1 Terabyte (2^40 bytes) are truncated and an 213 * InvalidValue error is recorded. 214 */ 215 undefined accumulate(unsigned long long aSample); 216 217 /** 218 * **Test-only API** 219 * 220 * Gets the currently stored value as a DistributionData. 221 * 222 * This function will attempt to await the last parent-process task (if any) 223 * writing to the the metric's storage engine before returning a value. 224 * This function will not wait for data from child processes. 225 * 226 * This doesn't clear the stored value. 227 * Parent process only. Panics in child processes. 228 * 229 * @param aPingName The (optional) name of the ping to retrieve the metric 230 * for. Defaults to the first value in `send_in_pings`. 231 * 232 * @return value of the stored metric, or null if there is no value. 233 */ 234 [Throws, ChromeOnly] 235 GleanDistributionData? testGetValue(optional UTF8String aPingName = ""); 236 }; 237 238 [Func="GleanWebidlEnabled", Exposed=Window] 239 interface GleanCustomDistribution : GleanMetric { 240 /** 241 * Accumulates the provided signed samples in the metric. 242 * 243 * @param aSamples - The vector holding the samples to be recorded by the metric. 244 * 245 * Notes: Discards any negative value in `samples` 246 * and report an `ErrorType::InvalidValue` for each of them. 247 */ 248 undefined accumulateSamples(sequence<long long> aSamples); 249 250 /** 251 * Accumulates the provided single signed sample in the metric. 252 * 253 * @param aSample - The sample to be recorded by the metric. 254 * 255 * Notes: Discards any negative value of `sample` and reports an 256 * `ErrorType::InvalidValue`. 257 */ 258 undefined accumulateSingleSample(long long aSample); 259 260 /** 261 * **Test-only API** 262 * 263 * Gets the currently stored value as a DistributionData. 264 * 265 * This function will attempt to await the last parent-process task (if any) 266 * writing to the the metric's storage engine before returning a value. 267 * This function will not wait for data from child processes. 268 * 269 * This doesn't clear the stored value. 270 * Parent process only. Panics in child processes. 271 * 272 * @param aPingName The (optional) name of the ping to retrieve the metric 273 * for. Defaults to the first value in `send_in_pings`. 274 * 275 * @return value of the stored metric, or null if there is no value. 276 */ 277 [Throws, ChromeOnly] 278 GleanDistributionData? testGetValue(optional UTF8String aPingName = ""); 279 }; 280 281 [Func="GleanWebidlEnabled", Exposed=Window] 282 interface GleanString : GleanMetric { 283 /** 284 * Set the string to the provided value. 285 * 286 * @param aValue The string to set the metric to. 287 */ 288 undefined set(UTF8String? aValue); 289 290 /** 291 * **Test-only API** 292 * 293 * Gets the currently stored value as a string. 294 * 295 * This function will attempt to await the last parent-process task (if any) 296 * writing to the the metric's storage engine before returning a value. 297 * This function will not wait for data from child processes. 298 * 299 * This doesn't clear the stored value. 300 * Parent process only. Panics in child processes. 301 * 302 * @param aPingName The (optional) name of the ping to retrieve the metric 303 * for. Defaults to the first value in `send_in_pings`. 304 * 305 * @return value of the stored metric, or null if there is no value. 306 */ 307 [Throws, ChromeOnly] 308 UTF8String? testGetValue(optional UTF8String aPingName = ""); 309 }; 310 311 [Func="GleanWebidlEnabled", Exposed=Window] 312 interface GleanStringList : GleanMetric { 313 /** 314 * Adds a new string to the list. 315 * 316 * Truncates the value and logs an error if it is longer than 100 bytes. 317 * 318 * @param value The string to add. 319 */ 320 undefined add(UTF8String value); 321 322 /** 323 * Sets the string_list to the provided list of strings. 324 * 325 * Truncates the list and logs an error if longer than 100 items. 326 * Truncates any item longer than 100 bytes and logs an error. 327 * 328 * @param aValue The list of strings to set the metric to. 329 */ 330 undefined set(sequence<UTF8String> aValue); 331 332 /** 333 * **Test-only API** 334 * 335 * Gets the currently stored value. 336 * 337 * This function will attempt to await the last parent-process task (if any) 338 * writing to the the metric's storage engine before returning a value. 339 * This function will not wait for data from child processes. 340 * 341 * This doesn't clear the stored value. 342 * Parent process only. Panics in child processes. 343 * 344 * @param aPingName The (optional) name of the ping to retrieve the metric 345 * for. Defaults to the first value in `send_in_pings`. 346 * 347 * @return value of the stored metric, or null if there is no value. 348 */ 349 [Throws, ChromeOnly] 350 sequence<UTF8String>? testGetValue(optional UTF8String aPingName = ""); 351 }; 352 353 [Func="GleanWebidlEnabled", Exposed=Window] 354 interface GleanTimespan : GleanMetric { 355 /** 356 * Start tracking time for the provided metric. 357 * 358 * This records an error if it’s already tracking time (i.e. start was already 359 * called with no corresponding [stop]): in that case the original 360 * start time will be preserved. 361 */ 362 undefined start(); 363 364 /** 365 * Stop tracking time for the provided metric. 366 * 367 * Sets the metric to the elapsed time, but does not overwrite an already 368 * existing value. 369 * This will record an error if no [start] was called or there is an already 370 * existing value. 371 */ 372 undefined stop(); 373 374 /** 375 * Aborts a previous start. 376 * 377 * Does not record an error if there was no previous call to start. 378 */ 379 undefined cancel(); 380 381 /** 382 * Explicitly sets the timespan value. 383 * 384 * This API should only be used if you cannot make use of 385 * `start`/`stop`/`cancel`. 386 * 387 * @param aDuration The duration of this timespan, in units matching the 388 * `time_unit` of this metric's definition. 389 */ 390 undefined setRaw(unsigned long aDuration); 391 392 /** 393 * **Test-only API** 394 * 395 * Gets the currently stored value. 396 * 397 * This function will attempt to await the last parent-process task (if any) 398 * writing to the the metric's storage engine before returning a value. 399 * This function will not wait for data from child processes. 400 * 401 * This doesn't clear the stored value. 402 * Parent process only. Panics in child processes. 403 * 404 * @param aPingName The (optional) name of the ping to retrieve the metric 405 * for. Defaults to the first value in `send_in_pings`. 406 * 407 * @return value of the stored metric, or null if there is no value. 408 */ 409 [Throws, ChromeOnly] 410 unsigned long long? testGetValue(optional UTF8String aPingName = ""); 411 }; 412 413 [Func="GleanWebidlEnabled", Exposed=Window] 414 interface GleanUuid : GleanMetric { 415 /** 416 * Set to the specified value. 417 * 418 * @param aValue The UUID to set the metric to. 419 */ 420 undefined set(UTF8String aValue); 421 422 /** 423 * Generate a new random UUID and set the metric to it. 424 */ 425 undefined generateAndSet(); 426 427 /** 428 * **Test-only API** 429 * 430 * Gets the currently stored value. 431 * 432 * This function will attempt to await the last parent-process task (if any) 433 * writing to the the metric's storage engine before returning a value. 434 * This function will not wait for data from child processes. 435 * 436 * This doesn't clear the stored value. 437 * Parent process only. Panics in child processes. 438 * 439 * @param aPingName The (optional) name of the ping to retrieve the metric 440 * for. Defaults to the first value in `send_in_pings`. 441 * 442 * @return value of the stored metric, or null if there is no value. 443 */ 444 [Throws, ChromeOnly] 445 UTF8String? testGetValue(optional UTF8String aPingName = ""); 446 }; 447 448 dictionary GleanEventRecord { 449 required unsigned long long timestamp; 450 required UTF8String category; 451 required UTF8String name; 452 record<UTF8String, UTF8String> extra; 453 }; 454 455 [Func="GleanWebidlEnabled", Exposed=Window] 456 interface GleanEvent : GleanMetric { 457 458 /* 459 * Record an event. 460 * 461 * @param aExtra An (optional) map of extra values. 462 */ 463 undefined _record(optional record<UTF8String, UTF8String?>? aExtra); 464 465 /** 466 * **Test-only API** 467 * 468 * Gets the currently stored value. 469 * 470 * This function will attempt to await the last parent-process task (if any) 471 * writing to the the metric's storage engine before returning a value. 472 * This function will not wait for data from child processes. 473 * 474 * This doesn't clear the stored value. 475 * Parent process only. Panics in child processes. 476 * 477 * @param aPingName The (optional) name of the ping to retrieve the metric 478 * for. Defaults to the first value in `send_in_pings`. 479 * 480 * @return value of the stored metric, or null if there is no value. 481 * 482 * The difference between event timestamps is in milliseconds 483 * See https://mozilla.github.io/glean/book/user/metrics/event.html for further details. 484 * Due to limitations of numbers in JavaScript, the timestamp will only be accurate up until 2^53. 485 * (This is probably not an issue with the current clock implementation. Probably.) 486 */ 487 [Throws, ChromeOnly] 488 sequence<GleanEventRecord>? testGetValue(optional UTF8String aPingName = ""); 489 }; 490 491 [Func="GleanWebidlEnabled", Exposed=Window] 492 interface GleanQuantity : GleanMetric { 493 /** 494 * Set to the specified value. 495 * 496 * @param aValue The value to set the metric to. 497 */ 498 undefined set(long long aValue); 499 500 /** 501 * **Test-only API** 502 * 503 * Gets the currently stored value. 504 * 505 * This function will attempt to await the last parent-process task (if any) 506 * writing to the the metric's storage engine before returning a value. 507 * This function will not wait for data from child processes. 508 * 509 * This doesn't clear the stored value. 510 * Parent process only. Panics in child processes. 511 * 512 * @param aPingName The (optional) name of the ping to retrieve the metric 513 * for. Defaults to the first value in `send_in_pings`. 514 * 515 * @return value of the stored metric, or null if there is no value. 516 */ 517 [Throws, ChromeOnly] 518 long long? testGetValue(optional UTF8String aPingName = ""); 519 }; 520 521 [Func="GleanWebidlEnabled", Exposed=Window] 522 interface GleanDenominator : GleanMetric { 523 /* 524 * Increases the counter by `aAmount`. 525 * 526 * @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1. 527 */ 528 undefined add(optional long aAmount = 1); 529 530 /** 531 * **Test-only API** 532 * 533 * Gets the currently stored value as an integer. 534 * 535 * This function will attempt to await the last parent-process task (if any) 536 * writing to the the metric's storage engine before returning a value. 537 * This function will not wait for data from child processes. 538 * 539 * This doesn't clear the stored value. 540 * Parent process only. Panics in child processes. 541 * 542 * @param aPingName The (optional) name of the ping to retrieve the metric 543 * for. Defaults to the first value in `send_in_pings`. 544 * 545 * @return value of the stored metric, or null if there is no value. 546 */ 547 [Throws, ChromeOnly] 548 long? testGetValue(optional UTF8String aPingName = ""); 549 }; 550 551 dictionary GleanRateData { 552 required long numerator; 553 required long denominator; 554 }; 555 556 [Func="GleanWebidlEnabled", Exposed=Window] 557 interface GleanNumerator : GleanMetric { 558 /* 559 * Increases the numerator by `aAmount`. 560 * 561 * @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1. 562 */ 563 undefined addToNumerator(optional long aAmount = 1); 564 565 /** 566 * **Test-only API** 567 * 568 * Gets the currently stored value in the form {numerator: n, denominator: d} 569 * 570 * This function will attempt to await the last parent-process task (if any) 571 * writing to the the metric's storage engine before returning a value. 572 * This function will not wait for data from child processes. 573 * 574 * This doesn't clear the stored value. 575 * Parent process only. Panics in child processes. 576 * 577 * @param aPingName The (optional) name of the ping to retrieve the metric 578 * for. Defaults to the first value in `send_in_pings`. 579 * 580 * @return value of the stored metric, or null if there is no value. 581 */ 582 [Throws, ChromeOnly] 583 GleanRateData? testGetValue(optional UTF8String aPingName = ""); 584 }; 585 586 [Func="GleanWebidlEnabled", Exposed=Window] 587 interface GleanRate : GleanMetric { 588 /* 589 * Increases the numerator by `amount`. 590 * 591 * @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1. 592 */ 593 undefined addToNumerator(optional long aAmount = 1); 594 595 /* 596 * Increases the denominator by `amount`. 597 * 598 * @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1. 599 */ 600 undefined addToDenominator(optional long aAmount = 1); 601 602 /** 603 * **Test-only API** 604 * 605 * Gets the currently stored value in the form {numerator: n, denominator: d} 606 * 607 * This function will attempt to await the last parent-process task (if any) 608 * writing to the the metric's storage engine before returning a value. 609 * This function will not wait for data from child processes. 610 * 611 * This doesn't clear the stored value. 612 * Parent process only. Panics in child processes. 613 * 614 * @param aPingName The (optional) name of the ping to retrieve the metric 615 * for. Defaults to the first value in `send_in_pings`. 616 * 617 * @return value of the stored metric, or null if there is no value. 618 */ 619 [Throws, ChromeOnly] 620 GleanRateData? testGetValue(optional UTF8String aPingName = ""); 621 }; 622 623 [Func="GleanWebidlEnabled", Exposed=Window] 624 interface GleanUrl : GleanMetric { 625 /** 626 * Set to the specified value. 627 * 628 * @param aValue The stringified URL to set the metric to. 629 */ 630 undefined set(UTF8String aValue); 631 632 /** 633 * **Test-only API** 634 * 635 * Gets the currently stored value. 636 * 637 * This function will attempt to await the last parent-process task (if any) 638 * writing to the the metric's storage engine before returning a value. 639 * This function will not wait for data from child processes. 640 * 641 * This doesn't clear the stored value. 642 * Parent process only. Panics in child processes. 643 * 644 * @param aPingName The (optional) name of the ping to retrieve the metric 645 * for. Defaults to the first value in `send_in_pings`. 646 * 647 * @return value of the stored metric, or null if there is no value. 648 */ 649 [Throws, ChromeOnly] 650 UTF8String? testGetValue(optional UTF8String aPingName = ""); 651 }; 652 653 [Func="GleanWebidlEnabled", Exposed=Window] 654 interface GleanText : GleanMetric { 655 /** 656 * Set to the provided value. 657 * 658 * @param aValue The text to set the metric to. 659 */ 660 undefined set(UTF8String aValue); 661 662 /** 663 * **Test-only API** 664 * 665 * Gets the currently stored value as a string. 666 * 667 * This function will attempt to await the last parent-process task (if any) 668 * writing to the the metric's storage engine before returning a value. 669 * This function will not wait for data from child processes. 670 * 671 * This doesn't clear the stored value. 672 * Parent process only. Panics in child processes. 673 * 674 * @param aPingName The (optional) name of the ping to retrieve the metric 675 * for. Defaults to the first value in `send_in_pings`. 676 * 677 * @return value of the stored metric, or null if there is no value. 678 */ 679 [Throws, ChromeOnly] 680 UTF8String? testGetValue(optional UTF8String aPingName = ""); 681 }; 682 683 [Func="GleanWebidlEnabled", Exposed=Window] 684 interface GleanObject : GleanMetric { 685 /** 686 * Set to the specified object. 687 * 688 * The structure of the metric is validated against the predefined structure. 689 * 690 * @param object The object to set the metric to. 691 */ 692 undefined set(object value); 693 694 /** 695 * **Test-only API** 696 * 697 * Gets the currently stored value as an object. 698 * 699 * This function will attempt to await the last parent-process task (if any) 700 * writing to the the metric's storage engine before returning a value. 701 * This function will not wait for data from child processes. 702 * 703 * This doesn't clear the stored value. 704 * Parent process only. Panics in child processes. 705 * 706 * @param aPingName The (optional) name of the ping to retrieve the metric 707 * for. Defaults to the first value in `send_in_pings`. 708 * 709 * @return value of the stored metric, or undefined if there is no value. 710 */ 711 [Throws, ChromeOnly] 712 object? testGetValue(optional UTF8String aPingName = ""); 713 }; 714 715 [Func="GleanWebidlEnabled", Exposed=Window] 716 interface GleanDualLabeledCounter : GleanMetric { 717 /** 718 * Gets a specific counter metric for a given key and category. 719 * 720 * If a set of acceptable labels were specified in the `metrics.yaml` file, 721 * and the given label is not in the set, it will be recorded under the 722 * special `__other__` label. 723 * 724 * If a set of acceptable labels was not specified in the `metrics.yaml` 725 * file, only the first 16 unique labels will be used. 726 * After that, any additional labels will be recorded under the special 727 * `__other__` label. 728 * 729 * This applies to both key labels and category labels. 730 * 731 * @param aKey - A label of at most 111 bytes of length when encoded as UTF-8 732 * @param aCategory - A label of at most 111 bytes of length when encoded as 733 * UTF-8. 734 */ 735 GleanCounter get(UTF8String aKey, UTF8String aCategory); 736 };