Server IP : 85.214.239.14 / Your IP : 3.144.16.40 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/node_modules/npm/lib/utils/ |
Upload File : |
const EE = require('node:events') const fs = require('node:fs') const { log, time } = require('proc-log') const INITIAL_TIMER = 'npm' class Timers extends EE { #file #timing #unfinished = new Map() #finished = {} constructor () { super() this.on() time.start(INITIAL_TIMER) this.started = this.#unfinished.get(INITIAL_TIMER) } on () { process.on('time', this.#timeHandler) } off () { process.off('time', this.#timeHandler) } load ({ path, timing } = {}) { this.#timing = timing this.#file = `${path}timing.json` } finish (metadata) { time.end(INITIAL_TIMER) for (const [name, timer] of this.#unfinished) { log.silly('unfinished npm timer', name, timer) } if (!this.#timing) { // Not in timing mode, nothing else to do here return } try { this.#writeFile(metadata) log.info('timing', `Timing info written to: ${this.#file}`) } catch (e) { log.warn('timing', `could not write timing file: ${e}`) } } #writeFile (metadata) { const globalStart = this.started const globalEnd = this.#finished[INITIAL_TIMER] const content = { metadata, timers: this.#finished, // add any unfinished timers with their relative start/end unfinishedTimers: [...this.#unfinished.entries()].reduce((acc, [name, start]) => { acc[name] = [start - globalStart, globalEnd - globalStart] return acc }, {}), } fs.writeFileSync(this.#file, JSON.stringify(content) + '\n') } #timeHandler = (level, name) => { const now = Date.now() switch (level) { case time.KEYS.start: this.#unfinished.set(name, now) break case time.KEYS.end: { if (this.#unfinished.has(name)) { const ms = now - this.#unfinished.get(name) this.#finished[name] = ms this.#unfinished.delete(name) log.timing(name, `Completed in ${ms}ms`) } else { log.silly('timing', `Tried to end timer that doesn't exist: ${name}`) } } } } } module.exports = Timers