This repository was archived by the owner on Sep 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +75
-2
lines changed
packages/devtools-modules/src Expand file tree Collapse file tree 2 files changed +75
-2
lines changed Original file line number Diff line number Diff line change @@ -498,6 +498,10 @@ PrefBranch.prototype = {
498498 } ,
499499} ;
500500
501+ window . telemetry = { }
502+ window . telemetry . histograms = { }
503+ window . telemetry . scalars = { }
504+
501505const Services = {
502506 _prefs : null ,
503507
@@ -563,15 +567,43 @@ const Services = {
563567 telemetry : {
564568 getHistogramById : function ( name ) {
565569 return {
566- add : ( ) => { }
570+ add : value => {
571+ if ( window . telemetry . histograms [ name ] ) {
572+ window . telemetry . histograms [ name ] . push ( value ) ;
573+ } else {
574+ window . telemetry . histograms [ name ] = [ value ] ;
575+ }
576+ }
567577 } ;
568578 } ,
569579
570580 getKeyedHistogramById : function ( name ) {
571581 return {
572- add : ( ) => { }
582+ add : ( id , value ) => {
583+ if ( ! window . telemetry . histograms [ name ] ) {
584+ window . telemetry . histograms [ name ] = { } ;
585+ }
586+
587+ if ( ! window . telemetry . histograms [ name ] [ id ] ) {
588+ window . telemetry . histograms [ name ] [ id ] = [ ] ;
589+ }
590+
591+ window . telemetry . histograms [ name ] [ id ] . push ( value ) ;
592+ }
573593 } ;
574594 } ,
595+
596+ scalarSet : function ( scalarId , value ) {
597+ window . telemetry . scalars [ scalarId ] = value ;
598+ } ,
599+
600+ scalarAdd : function ( scalarId , value ) {
601+ if ( scalarId in window . telemetry . scalars ) {
602+ window . telemetry . scalars [ scalarId ] += value ;
603+ } else {
604+ window . telemetry . scalars [ scalarId ] = value ;
605+ }
606+ }
575607 } ,
576608
577609 /**
Original file line number Diff line number Diff line change 1+ const Services = require ( "../Services" ) ;
2+
3+ // const pref = Services;
4+
5+ describe ( "services telemetry shim" , ( ) => {
6+ beforeEach ( ( ) => {
7+ telemetry . scalars = { } ;
8+ telemetry . histograms = { } ;
9+ } ) ;
10+
11+ it ( "getHistogramById" , ( ) => {
12+ const hist = Services . telemetry . getHistogramById ( "foo" ) ;
13+ hist . add ( 3 ) ;
14+ expect ( telemetry . histograms . foo ) . toEqual ( [ 3 ] ) ;
15+
16+ hist . add ( 3 ) ;
17+ expect ( telemetry . histograms . foo ) . toEqual ( [ 3 , 3 ] ) ;
18+ } ) ;
19+
20+ it ( "getKeyedHistogramById" , ( ) => {
21+ const hist = Services . telemetry . getKeyedHistogramById ( "foo" ) ;
22+ hist . add ( "a" , 3 ) ;
23+ expect ( telemetry . histograms . foo . a ) . toEqual ( [ 3 ] ) ;
24+
25+ hist . add ( "a" , 3 ) ;
26+ expect ( telemetry . histograms . foo . a ) . toEqual ( [ 3 , 3 ] ) ;
27+ } ) ;
28+
29+ it ( "scalarSet" , ( ) => {
30+ Services . telemetry . scalarSet ( "foo" , 3 ) ;
31+ expect ( telemetry . scalars . foo ) . toEqual ( 3 ) ;
32+ } ) ;
33+
34+ it ( "scalarAdd" , ( ) => {
35+ Services . telemetry . scalarAdd ( "foo" , 3 ) ;
36+ expect ( telemetry . scalars . foo ) . toEqual ( 3 ) ;
37+
38+ Services . telemetry . scalarAdd ( "foo" , 3 ) ;
39+ expect ( telemetry . scalars . foo ) . toEqual ( 6 ) ;
40+ } ) ;
41+ } ) ;
You can’t perform that action at this time.
0 commit comments