UNPKG

6.8 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../build/profiler/profiler.js"],"names":["maybeInspector","require","e","console","log","Profiler","constructor","inspector","session","undefined","hasSession","startProfiling","Promise","resolve","Session","connect","_","all","sendCommand","interval","method","params","reject","post","err","sessionParams","destroy","disconnect","stopProfiling","Tracer","createTrace","outputPath","trace","noStream","profiler","test","dirPath","path","dirname","fs","mkdirSync","recursive","fsStream","createWriteStream","counter","pipe","instantEvent","name","id","cat","args","data","sessionId","page","frames","frame","url","end","callback","on","push"],"mappings":"gEAAA,8CACA,kD,mFAEA,GAAIA,CAAAA,cAAJ,CACA,GAAI,CACFA,cAAc,CAAGC,OAAO,CAAC,WAAD,CAAxB,CACD,CAAC,MAAOC,CAAP,CAAU,CACVC,OAAO,CAACC,GAAR,CAAY,qCAAZ,EACD,CAED,KAAMC,CAAAA,QAAS,CACbC,WAAW,CAACC,SAAD,CAAY,CACrB,KAAKC,OAAL,CAAeC,SAAf,CACA,KAAKF,SAAL,CAAiBA,SAAjB,CACD,CAEDG,UAAU,EAAG,CACX,MAAO,MAAKF,OAAL,GAAiBC,SAAxB,CACD,CAEDE,cAAc,EAAG,CACf,GAAI,KAAKJ,SAAL,GAAmBE,SAAvB,CAAkC,CAChC,MAAOG,CAAAA,OAAO,CAACC,OAAR,EAAP,CACD,CAED,GAAI,CACF,KAAKL,OAAL,CAAe,GAAIR,CAAAA,cAAc,CAACc,OAAnB,EAAf,CACA,KAAKN,OAAL,CAAaO,OAAb,GACD,CAAC,MAAOC,CAAP,CAAU,CACV,KAAKR,OAAL,CAAeC,SAAf,CACA,MAAOG,CAAAA,OAAO,CAACC,OAAR,EAAP,CACD,CAED,MAAOD,CAAAA,OAAO,CAACK,GAAR,CAAY,CACjB,KAAKC,WAAL,CAAiB,8BAAjB,CAAiD,CAC/CC,QAAQ,CAAE,GADqC,CAAjD,CADiB,CAIjB,KAAKD,WAAL,CAAiB,iBAAjB,CAJiB,CAKjB,KAAKA,WAAL,CAAi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C,SAAH,CAAaJ,OAAb,CAAsB,CAAEK,SAAS,CAAE,IAAb,CAAtB,EACD,CACD,KAAMC,CAAAA,QAAQ,CAAGH,YAAGI,iBAAH,CAAqBZ,UAArB,CAAjB,CAEA,GAAIa,CAAAA,OAAO,CAAG,CAAd,CAEAZ,KAAK,CAACa,IAAN,CAAWH,QAAX,EACA;AACA;AACAV,KAAK,CAACc,YAAN,CAAmB,CACjBC,IAAI,CAAE,sBADW,CAEjBC,EAAE,CAAE,EAAEJ,OAFW,CAGjBK,GAAG,CAAE,CAAC,uCAAD,CAHY,CAIjBC,IAAI,CAAE,CACJC,IAAI,CAAE,CACJC,SAAS,CAAE,IADP,CAEJC,IAAI,CAAE,OAFF,CAGJC,MAAM,CAAE,CACN,CACEC,KAAK,CAAE,OADT,CAEEC,GAAG,CAAE,SAFP,CAGET,IAAI,CAAE,EAHR,CADM,CAHJ,CADF,CAJW,CAAnB,EAmBAf,KAAK,CAACc,YAAN,CAAmB,CACjBC,IAAI,CAAE,yBADW,CAEjBC,EAAE,CAAE,EAAEJ,OAFW,CAGjBK,GAAG,CAAE,CAAC,uCAAD,CAHY,CAIjBC,IAAI,CAAE,CACJC,IAAI,CAAE,CACJC,SAAS,CAAE,IADP,CADF,CAJW,CAAnB,EAWA,MAAO,CACLpB,KADK,CAELY,OAFK,CAGLV,QAHK,CAILuB,GAAG,CAAGC,QAAD,EAAc,CACjB;AACAhB,QAAQ,CAACiB,EAAT,CAAY,QAAZ,CAAsB,IAAM,CAC1BD,QAAQ,GACT,CAFD,EAGA;AACA1B,KAAK,CAAC4B,IAAN,CAAW,IAAX,EACD,CAXI,CAAP,CAaD,CA3DM,C","sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nlet maybeInspector\ntry {\n maybeInspector = require('inspector')\n} catch (e) {\n console.log('Unable to CPU profile in < node 8.0')\n}\n\nclass Profiler {\n constructor(inspector) {\n this.session = undefined\n this.inspector = inspector\n }\n\n hasSession() {\n return this.session !== undefined\n }\n\n startProfiling() {\n if (this.inspector === undefined) {\n return Promise.resolve()\n }\n\n try {\n this.session = new maybeInspector.Session()\n this.session.connect()\n } catch (_) {\n this.session = undefined\n return Promise.resolve()\n }\n\n return Promise.all([\n this.sendCommand('Profiler.setSamplingInterval', {\n interval: 100,\n }),\n this.sendCommand('Profiler.enable'),\n this.sendCommand('Profiler.start'),\n ])\n }\n\n sendCommand(method, params) {\n if (this.hasSession()) {\n return new Promise((resolve, reject) => {\n return this.session.post(method, params, (err, sessionParams) => {\n if (err !== null) {\n reject(err)\n } else {\n resolve(sessionParams)\n }\n })\n })\n } else {\n return Promise.resolve()\n }\n }\n\n destroy() {\n if (this.hasSession()) {\n this.session.disconnect()\n }\n\n return Promise.resolve()\n }\n\n stopProfiling() {\n return this.sendCommand('Profiler.stop')\n }\n}\n\n// eslint-disable-next-line import/no-extraneous-dependencies\nconst { Tracer } = require('chrome-trace-event')\n\n/**\n * an object that wraps Tracer and Profiler with a counter\n * @typedef {Object} Trace\n * @property {Tracer} trace instance of Tracer\n * @property {number} counter Counter\n * @property {Profiler} profiler instance of Profiler\n * @property {Function} end the end function\n */\n\n/**\n * @param {string} outputPath The location where to write the log.\n * @returns {Trace} The trace object\n */\nexport const createTrace = (outputPath) => {\n const trace = new Tracer({\n noStream: true,\n })\n const profiler = new Profiler(maybeInspector)\n if (/\\/|\\\\/.test(outputPath)) {\n const dirPath = path.dirname(outputPath)\n fs.mkdirSync(dirPath, { recursive: true })\n }\n const fsStream = fs.createWriteStream(outputPath)\n\n let counter = 0\n\n trace.pipe(fsStream)\n // These are critical events that need to be inserted so that tools like\n // chrome dev tools can load the profile.\n trace.instantEvent({\n name: 'TracingStartedInPage',\n id: ++counter,\n cat: ['disabled-by-default-devtools.timeline'],\n args: {\n data: {\n sessionId: '-1',\n page: '0xfff',\n frames: [\n {\n frame: '0xfff',\n url: 'webpack',\n name: '',\n },\n ],\n },\n },\n })\n\n trace.instantEvent({\n name: 'TracingStartedInBrowser',\n id: ++counter,\n cat: ['disabled-by-default-devtools.timeline'],\n args: {\n data: {\n sessionId: '-1',\n },\n },\n })\n\n return {\n trace,\n counter,\n profiler,\n end: (callback) => {\n // Wait until the write stream finishes.\n fsStream.on('finish', () => {\n callback()\n })\n // Tear down the readable trace stream.\n trace.push(null)\n },\n }\n}\n"]}
\No newline at end of file