@@ -1139,158 +1139,64 @@ namespace ts {
11391139 /** Performance measurements for the compiler. */
11401140 /*@internal */
11411141 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 ( ) ;
1142+ let counters : Map < number > = { } ;
1143+ let measures : Map < number > = { } ;
11661144 let enabled = false ;
11671145
1168- /** Gets the current timer for performance measurements. */
1169- export function now ( ) {
1170- return Date . now ( ) ;
1171- }
1172-
11731146 /**
1174- * Adds a performance mark with the specified name.
1147+ * Increments a counter with the specified name.
11751148 *
1176- * @param markName The name of the performance mark .
1149+ * @param counterName The name of the counter .
11771150 */
1178- export function mark ( markName : string ) {
1151+ export function increment ( counterName : string ) {
11791152 if ( enabled ) {
1180- markTimestamps [ markName ] = now ( ) ;
1181- markCounts [ markName ] = getCount ( markName ) + 1 ;
1153+ counters [ counterName ] = ( getProperty ( counters , counterName ) || 0 ) + 1 ;
11821154 }
11831155 }
11841156
11851157 /**
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.
1158+ * Gets the value of the counter with the specified name.
11941159 *
1195- * @param markName The name of the marks that should be counted .
1160+ * @param counterName The name of the counter .
11961161 */
1197- export function getCount ( markName : string ) {
1198- return enabled && getProperty ( markCounts , markName ) || 0 ;
1162+ export function getCount ( counterName : string ) {
1163+ return enabled && getProperty ( counters , counterName ) || 0 ;
11991164 }
12001165
12011166 /**
1202- * Gets the most recent timestamp for the marks with the specified name.
1203- *
1204- * @param markName The name of the mark.
1167+ * Marks the start of a performance measurement.
12051168 */
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- }
1169+ export function mark ( ) {
1170+ return enabled ? Date . now ( ) : 0 ;
12291171 }
12301172
12311173 /**
12321174 * Adds a performance measurement with the specified name.
12331175 *
12341176 * @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.
1177+ * @param marker The timestamp of the starting mark.
12421178 */
1243- export function measure ( measureName : string , startMarkName ?: string , endMarkName ?: string ) {
1179+ export function measure ( measureName : string , marker : number ) {
12441180 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 ;
1181+ measures [ measureName ] = ( getProperty ( measures , measureName ) || 0 ) + ( mark ( ) - marker ) ;
12491182 }
12501183 }
12511184
1252- /**
1253- * Gets the names of all recorded measures.
1254- */
1255- export function getMeasureNames ( ) {
1256- return getKeys ( measureDurations ) ;
1257- }
1258-
12591185 /**
12601186 * Gets the total duration of all measurements with the supplied name.
12611187 *
12621188 * @param measureName The name of the measure whose durations should be accumulated.
12631189 */
12641190 export function getDuration ( measureName : string ) {
1265- return enabled && getProperty ( measureDurations , measureName ) || 0 ;
1266- }
1267-
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 ] ;
1191+ return enabled && getProperty ( measures , measureName ) || 0 ;
12851192 }
12861193
12871194 /**
12881195 * Resets all marks and measurements in the performance service.
12891196 */
12901197 export function reset ( ) {
1291- clearMarks ( ) ;
1292- clearMeasures ( ) ;
1293- start = now ( ) ;
1198+ counters = { } ;
1199+ measures = { } ;
12941200 }
12951201
12961202 /** Enables performance measurements for the compiler. */
0 commit comments