| 172 | } |
| 173 | |
| 174 | function calculateStartDuration(startOrMeasureOptions, endMark) { |
| 175 | startOrMeasureOptions ??= 0; |
| 176 | let start; |
| 177 | let end; |
| 178 | let duration; |
| 179 | let optionsValid = false; |
| 180 | if (typeof startOrMeasureOptions === 'object') { |
| 181 | ({ start, end, duration } = startOrMeasureOptions); |
| 182 | optionsValid = start !== undefined || end !== undefined; |
| 183 | } |
| 184 | if (optionsValid) { |
| 185 | if (endMark !== undefined) { |
| 186 | throw new ERR_PERFORMANCE_MEASURE_INVALID_OPTIONS( |
| 187 | 'endMark must not be specified'); |
| 188 | } |
| 189 | |
| 190 | if (start === undefined && end === undefined) { |
| 191 | throw new ERR_PERFORMANCE_MEASURE_INVALID_OPTIONS( |
| 192 | 'One of options.start or options.end is required'); |
| 193 | } |
| 194 | if (start !== undefined && end !== undefined && duration !== undefined) { |
| 195 | throw new ERR_PERFORMANCE_MEASURE_INVALID_OPTIONS( |
| 196 | 'Must not have options.start, options.end, and ' + |
| 197 | 'options.duration specified'); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if (endMark !== undefined) { |
| 202 | end = getMark(endMark); |
| 203 | } else if (optionsValid && end !== undefined) { |
| 204 | end = getMark(end); |
| 205 | } else if (optionsValid && start !== undefined && duration !== undefined) { |
| 206 | end = getMark(start) + getMark(duration); |
| 207 | } else { |
| 208 | end = now(); |
| 209 | } |
| 210 | |
| 211 | if (typeof startOrMeasureOptions === 'string') { |
| 212 | start = getMark(startOrMeasureOptions); |
| 213 | } else if (optionsValid && start !== undefined) { |
| 214 | start = getMark(start); |
| 215 | } else if (optionsValid && duration !== undefined && end !== undefined) { |
| 216 | start = end - getMark(duration); |
| 217 | } else { |
| 218 | start = 0; |
| 219 | } |
| 220 | |
| 221 | duration = end - start; |
| 222 | return { start, duration }; |
| 223 | } |
| 224 | |
| 225 | function measure(name, startOrMeasureOptions, endMark) { |
| 226 | validateString(name, 'name'); |