@@ -1120,6 +1120,18 @@ namespace ts {
11201120 }
11211121 }
11221122
1123+ export function getEnvironmentVariable ( name : string , host ?: CompilerHost ) {
1124+ if ( host && host . getEnvironmentVariable ) {
1125+ return host . getEnvironmentVariable ( name ) ;
1126+ }
1127+
1128+ if ( sys && sys . getEnvironmentVariable ) {
1129+ return sys . getEnvironmentVariable ( name ) ;
1130+ }
1131+
1132+ return "" ;
1133+ }
1134+
11231135 export function copyListRemovingItem < T > ( item : T , list : T [ ] ) {
11241136 const copiedList : T [ ] = [ ] ;
11251137 for ( const e of list ) {
@@ -1139,168 +1151,77 @@ namespace ts {
11391151 /** Performance measurements for the compiler. */
11401152 /*@internal */
11411153 export namespace performance {
1142- interface MarkData {
1143- markName : string ;
1144- timestamp : number ;
1145- }
1146-
1147- interface MeasureData {
1148- measureName : string ;
1149- startMarkName : string ;
1150- endMarkName : string ;
1151- timestamp : number ;
1152- marksOffset : number ;
1153- }
1154-
1155- export interface Measure {
1156- name : string ;
1157- startTime : number ;
1158- duration : number ;
1159- }
1160-
1161- const markTimestamps : Map < number > = { } ;
1162- const markCounts : Map < number > = { } ;
1163- const measureDurations : Map < number > = { } ;
1164-
1165- let start = now ( ) ;
1166- let enabled = false ;
1167-
1168- /** Gets the current timer for performance measurements. */
1169- export function now ( ) {
1170- return Date . now ( ) ;
1171- }
1154+ let counters : Map < number > ;
1155+ let measures : Map < number > ;
11721156
11731157 /**
1174- * Adds a performance mark with the specified name.
1158+ * Increments a counter with the specified name.
11751159 *
1176- * @param markName The name of the performance mark .
1160+ * @param counterName The name of the counter .
11771161 */
1178- export function mark ( markName : string ) {
1179- if ( enabled ) {
1180- markTimestamps [ markName ] = now ( ) ;
1181- markCounts [ markName ] = getCount ( markName ) + 1 ;
1162+ export function increment ( counterName : string ) {
1163+ if ( counters ) {
1164+ counters [ counterName ] = ( getProperty ( counters , counterName ) || 0 ) + 1 ;
11821165 }
11831166 }
11841167
11851168 /**
1186- * Gets the names of all marks.
1187- */
1188- export function getMarkNames ( ) {
1189- return getKeys ( markCounts ) ;
1190- }
1191-
1192- /**
1193- * Gets the number of marks with the specified name.
1169+ * Gets the value of the counter with the specified name.
11941170 *
1195- * @param markName The name of the marks that should be counted .
1171+ * @param counterName The name of the counter .
11961172 */
1197- export function getCount ( markName : string ) {
1198- return enabled && getProperty ( markCounts , markName ) || 0 ;
1173+ export function getCount ( counterName : string ) {
1174+ return counters && getProperty ( counters , counterName ) || 0 ;
11991175 }
12001176
12011177 /**
1202- * Gets the most recent timestamp for the marks with the specified name.
1203- *
1204- * @param markName The name of the mark.
1178+ * Marks the start of a performance measurement.
12051179 */
1206- export function getTimestamp ( markName : string ) {
1207- return enabled && getProperty ( markTimestamps , markName ) || 0 ;
1208- }
1209-
1210- /**
1211- * Clears performance marks.
1212- *
1213- * @param markName The name of the mark whose time values should be cleared. If not
1214- * specified, all marks will be cleared.
1215- */
1216- export function clearMarks ( markName ?: string ) {
1217- if ( markName === undefined ) {
1218- forEachKey ( markTimestamps , clearMark ) ;
1219- }
1220- else {
1221- clearMark ( markName ) ;
1222- }
1223- }
1224-
1225- function clearMark ( markName : string ) {
1226- if ( delete markTimestamps [ markName ] ) {
1227- delete markCounts [ markName ] ;
1228- }
1180+ export function mark ( ) {
1181+ return measures ? Date . now ( ) : 0 ;
12291182 }
12301183
12311184 /**
12321185 * Adds a performance measurement with the specified name.
12331186 *
12341187 * @param measureName The name of the performance measurement.
1235- * @param startMarkName The name of the starting mark.
1236- * If provided, the most recent time value of the start mark is used.
1237- * If not specified, the value is the time that the performance service was
1238- * initialized or the last time it was reset.
1239- * @param endMarkName The name of the ending mark.
1240- * If provided, the most recent time value of the end mark is used.
1241- * If not specified, the current time is used.
1188+ * @param marker The timestamp of the starting mark.
12421189 */
1243- export function measure ( measureName : string , startMarkName ?: string , endMarkName ?: string ) {
1244- if ( enabled ) {
1245- const startTime = startMarkName ? getTimestamp ( startMarkName ) : start ;
1246- const endTime = endMarkName ? getTimestamp ( endMarkName ) : now ( ) ;
1247- const duration = endTime - startTime ;
1248- measureDurations [ measureName ] = getDuration ( measureName ) + duration ;
1190+ export function measure ( measureName : string , marker : number ) {
1191+ if ( measures ) {
1192+ measures [ measureName ] = ( getProperty ( measures , measureName ) || 0 ) + ( mark ( ) - marker ) ;
12491193 }
12501194 }
12511195
1252- /**
1253- * Gets the names of all recorded measures.
1254- */
1255- export function getMeasureNames ( ) {
1256- return getKeys ( measureDurations ) ;
1257- }
1258-
12591196 /**
12601197 * Gets the total duration of all measurements with the supplied name.
12611198 *
12621199 * @param measureName The name of the measure whose durations should be accumulated.
12631200 */
12641201 export function getDuration ( measureName : string ) {
1265- return enabled && getProperty ( measureDurations , measureName ) || 0 ;
1202+ return measures && getProperty ( measures , measureName ) || 0 ;
12661203 }
12671204
1268- /**
1269- * Clears performance measures.
1270- *
1271- * @param measureName The name of the measure whose durations should be cleared. If not
1272- * specified, all measures will be cleared.
1273- */
1274- export function clearMeasures ( measureName ?: string ) {
1275- if ( measureName === undefined ) {
1276- forEachKey ( measureDurations , clearMeasure ) ;
1277- }
1278- else {
1279- clearMeasure ( measureName ) ;
1280- }
1281- }
1282-
1283- function clearMeasure ( measureName : string ) {
1284- delete measureDurations [ measureName ] ;
1285- }
1286-
1287- /**
1288- * Resets all marks and measurements in the performance service.
1289- */
1290- export function reset ( ) {
1291- clearMarks ( ) ;
1292- clearMeasures ( ) ;
1293- start = now ( ) ;
1294- }
1295-
1296- /** Enables performance measurements for the compiler. */
1205+ /** Enables (and resets) performance measurements for the compiler. */
12971206 export function enable ( ) {
1298- enabled = true ;
1299- }
1300-
1301- /** Disables performance measurements for the compiler. */
1207+ counters = { } ;
1208+ measures = {
1209+ programTime : 0 ,
1210+ parseTime : 0 ,
1211+ bindTime : 0 ,
1212+ emitTime : 0 ,
1213+ ioReadTime : 0 ,
1214+ ioWriteTime : 0 ,
1215+ printTime : 0 ,
1216+ commentTime : 0 ,
1217+ sourceMapTime : 0
1218+ } ;
1219+ }
1220+
1221+ /** Disables (and clears) performance measurements for the compiler. */
13021222 export function disable ( ) {
1303- enabled = false ;
1223+ counters = undefined ;
1224+ measures = undefined ;
13041225 }
13051226 }
13061227}
0 commit comments