@@ -32,13 +32,13 @@ import {
3232export class NodeEnvironmentInfoPlugin implements IEventPlugin {
3333 public priority : number = 80 ;
3434 public name : string = "NodeEnvironmentInfoPlugin" ;
35+ private _environmentInfo : EnvironmentInfo = null ;
3536
3637 public run ( context : EventPluginContext ) : Promise < void > {
37- // PERF: Ensure module info is cached and rework below statement.
3838 if ( ! context . event . data [ KnownEventDataKeys . EnvironmentInfo ] ) {
39- const environmentInfo : EnvironmentInfo = this . getEnvironmentInfo ( context ) ;
40- if ( environmentInfo ) {
41- context . event . data [ KnownEventDataKeys . EnvironmentInfo ] = environmentInfo ;
39+ const info : EnvironmentInfo = this . getEnvironmentInfo ( context ) ;
40+ if ( info ) {
41+ context . event . data [ KnownEventDataKeys . EnvironmentInfo ] = info ;
4242 }
4343 }
4444
@@ -60,14 +60,25 @@ export class NodeEnvironmentInfoPlugin implements IEventPlugin {
6060 return ips . join ( ", " ) ;
6161 }
6262
63+ function populateMemoryAndUptimeInfo ( ei : EnvironmentInfo ) {
64+ ei . process_memory_size = memoryUsage ( ) . heapTotal ;
65+ ei . total_physical_memory = totalmem ( ) ;
66+ ei . available_physical_memory = freemem ( ) ;
67+ ei . data . loadavg = loadavg ( ) ;
68+ ei . data . uptime = uptime ( ) ;
69+ }
70+
6371 if ( ! cpus ) {
6472 return null ;
6573 }
6674
67- const environmentInfo : EnvironmentInfo = {
75+ if ( this . _environmentInfo ) {
76+ populateMemoryAndUptimeInfo ( this . _environmentInfo ) ;
77+ return this . _environmentInfo ;
78+ }
79+
80+ const info : EnvironmentInfo = {
6881 processor_count : cpus ( ) . length ,
69- total_physical_memory : totalmem ( ) ,
70- available_physical_memory : freemem ( ) ,
7182 command_line : argv . join ( " " ) ,
7283 process_name : ( title || "" ) . replace ( / [ \uE000 - \uF8FF ] / g, "" ) ,
7384 process_id : pid + "" ,
@@ -79,26 +90,27 @@ export class NodeEnvironmentInfoPlugin implements IEventPlugin {
7990 // install_id: "",
8091 runtime_version : version ,
8192 data : {
82- loadavg : loadavg ( ) ,
8393 platform : platform ( ) ,
84- tmpdir : tmpdir ( ) ,
85- uptime : uptime ( ) ,
94+ tmpdir : tmpdir ( )
8695 } ,
8796 } ;
8897
8998 const config = context . client . config ;
9099 if ( config . includeMachineName ) {
91- environmentInfo . machine_name = hostname ( ) ;
100+ info . machine_name = hostname ( ) ;
92101 }
93102
94103 if ( config . includeIpAddress ) {
95- environmentInfo . ip_address = getIpAddresses ( ) ;
104+ info . ip_address = getIpAddresses ( ) ;
96105 }
97106
98107 if ( endianness ) {
99- environmentInfo . data . endianness = endianness ( ) ;
108+ info . data . endianness = endianness ( ) ;
100109 }
101110
102- return environmentInfo ;
111+ populateMemoryAndUptimeInfo ( info ) ;
112+
113+ this . _environmentInfo = info ;
114+ return this . _environmentInfo ;
103115 }
104116}
0 commit comments