@@ -32,13 +32,13 @@ import {
32
32
export class NodeEnvironmentInfoPlugin implements IEventPlugin {
33
33
public priority : number = 80 ;
34
34
public name : string = "NodeEnvironmentInfoPlugin" ;
35
+ private _environmentInfo : EnvironmentInfo = null ;
35
36
36
37
public run ( context : EventPluginContext ) : Promise < void > {
37
- // PERF: Ensure module info is cached and rework below statement.
38
38
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 ;
42
42
}
43
43
}
44
44
@@ -60,14 +60,25 @@ export class NodeEnvironmentInfoPlugin implements IEventPlugin {
60
60
return ips . join ( ", " ) ;
61
61
}
62
62
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
+
63
71
if ( ! cpus ) {
64
72
return null ;
65
73
}
66
74
67
- const environmentInfo : EnvironmentInfo = {
75
+ if ( this . _environmentInfo ) {
76
+ populateMemoryAndUptimeInfo ( this . _environmentInfo ) ;
77
+ return this . _environmentInfo ;
78
+ }
79
+
80
+ const info : EnvironmentInfo = {
68
81
processor_count : cpus ( ) . length ,
69
- total_physical_memory : totalmem ( ) ,
70
- available_physical_memory : freemem ( ) ,
71
82
command_line : argv . join ( " " ) ,
72
83
process_name : ( title || "" ) . replace ( / [ \uE000 - \uF8FF ] / g, "" ) ,
73
84
process_id : pid + "" ,
@@ -79,26 +90,27 @@ export class NodeEnvironmentInfoPlugin implements IEventPlugin {
79
90
// install_id: "",
80
91
runtime_version : version ,
81
92
data : {
82
- loadavg : loadavg ( ) ,
83
93
platform : platform ( ) ,
84
- tmpdir : tmpdir ( ) ,
85
- uptime : uptime ( ) ,
94
+ tmpdir : tmpdir ( )
86
95
} ,
87
96
} ;
88
97
89
98
const config = context . client . config ;
90
99
if ( config . includeMachineName ) {
91
- environmentInfo . machine_name = hostname ( ) ;
100
+ info . machine_name = hostname ( ) ;
92
101
}
93
102
94
103
if ( config . includeIpAddress ) {
95
- environmentInfo . ip_address = getIpAddresses ( ) ;
104
+ info . ip_address = getIpAddresses ( ) ;
96
105
}
97
106
98
107
if ( endianness ) {
99
- environmentInfo . data . endianness = endianness ( ) ;
108
+ info . data . endianness = endianness ( ) ;
100
109
}
101
110
102
- return environmentInfo ;
111
+ populateMemoryAndUptimeInfo ( info ) ;
112
+
113
+ this . _environmentInfo = info ;
114
+ return this . _environmentInfo ;
103
115
}
104
116
}
0 commit comments