File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1973,6 +1973,23 @@ added: v11.10.0
19731973Enables the update interval timer. Returns ` true `  if the timer was
19741974started, ` false `  if it was already started.
19751975
1976+ ### ` histogram[Symbol.dispose]() `  
1977+ 
1978+ <!--  YAML
1979+ added: REPLACEME 
1980+ --> 
1981+ 
1982+ Disables the update interval timer when the histogram is disposed.
1983+ 
1984+ ``` js 
1985+ const  { monitorEventLoopDelay  } =  require (' node:perf_hooks'  );
1986+ {
1987+   using hist =  monitorEventLoopDelay ({ resolution:  20  });
1988+   hist .enable ();
1989+   //  The histogram will be disabled when the block is exited.
1990+ }
1991+ ``` 
1992+ 
19761993### Cloning an ` IntervalHistogram `   
19771994
19781995{IntervalHistogram} instances can be cloned via {MessagePort}. On the receiving
Original file line number Diff line number Diff line change 33  ReflectConstruct, 
44  SafeMap, 
55  Symbol, 
6+   SymbolDispose, 
67}  =  primordials ; 
78
89const  { 
@@ -38,7 +39,7 @@ const {
3839const  kEnabled  =  Symbol ( 'kEnabled' ) ; 
3940
4041class  ELDHistogram  extends  Histogram  { 
41-   constructor ( i )  { 
42+   constructor ( )  { 
4243    throw  new  ERR_ILLEGAL_CONSTRUCTOR ( ) ; 
4344  } 
4445
@@ -65,6 +66,10 @@ class ELDHistogram extends Histogram {
6566    this [ kHandle ] . stop ( ) ; 
6667    return  true ; 
6768  } 
69+ 
70+   [ SymbolDispose ] ( )  { 
71+     this . disable ( ) ; 
72+   } 
6873} 
6974
7075/** 
Original file line number Diff line number Diff line change @@ -97,6 +97,17 @@ const { inspect } = require('util');
9797  } ,  50 ) ; 
9898} 
9999
100+ { 
101+   // Tests that the ELD histogram is disposable 
102+   let  histogram ; 
103+   { 
104+     using  hi  =  monitorEventLoopDelay ( ) ; 
105+     histogram  =  hi ; 
106+   } 
107+   // The histogram should already be disabled. 
108+   strictEqual ( histogram . disable ( ) ,  false ) ; 
109+ } 
110+ 
100111{ 
101112  const  h  =  createHistogram ( ) ; 
102113  ok ( inspect ( h ,  {  depth : null  } ) . startsWith ( 'Histogram' ) ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments