1.0.1 • Published 3 years ago

nv-inspector-basic v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

nv-inspector-basic

  • nv-inspector-basic
  • simple util for dev-tool protocol

install

  • npm install nv-inspector-basic

usage

 //node --expose-internals

 const {Session,cmd,showp} = require("nv-inspector-basic")

example

init

        var sess = new Session();
        sess.connect();
        var r = await cmd.Runtime.enable(sess);

        > r
        {
          method: 'Runtime.executionContextCreated',
          params: {
            context: {
              id: 1,
              origin: '',
              name: '/usr/local/bin/node[101016]',
              auxData: [Object]
            }
          },
          executionContextId: 1,
          executionContextName: '/usr/local/bin/node[101016]'
        }
        >

list global lexical-varname

    > let tstvar;
    > await cmd.Runtime.globalLexicalScopeNames(sess,1)
    { names: [ 'Session', 'cmd', 'showp', 'tstvar' ] }
    >

add function

   var pbox0 = await cmd.Runtime.addBinding(sess,'gfunc0',1)
   var pbox1 = await cmd.Runtime.addBinding(sess,'gfunc1',1)

        > pbox0
        { p: Promise { <pending> }, renew: [Function (anonymous)] }
        >
        > pbox1
        { p: Promise { <pending> }, renew: [Function (anonymous)] }
        >


        > gfunc0("msg-0")
        > pbox0
        { p: Promise { 'msg-0' }, renew: [Function (anonymous)] }
        >
        > gfunc1("msg-1")
        > pbox1
        { p: Promise { 'msg-1' }, renew: [Function (anonymous)] }
        >


        ////renew the promise,let it could be reused
        > pbox0.then(r=>r.renew())
        >
        > pbox0
        Promise { { p: Promise { <pending> }, renew: [Function (anonymous)] } }
        >
        gfunc0("msg-000")
        > pbox0
        Promise { { p: Promise { 'msg-000' }, renew: [Function (anonymous)] } }
        >

compile script

    >  var sid =  cmd.Runtime.compileScript(sess,`
    ...              function tst() {
    .....                  let a = 100;
    .....                  return(a*2)
    .....              }
    ...              tst()
    ...         `);
    >
    > sid
    Promise { '350' }

    var sid = await sid;


    var r = await cmd.Debugger.enable(sess);
    var r = await cmd.Debugger.setScriptSource(sess,sid,`;tst()`)

    > r
    { callFrames: [], stackChanged: false }
    >

        >  var r =  await cmd.Debugger.pause(sess);
        auto resumed!,check sess.call_center_['Debugger.resumed'].___auto
        
        > r.callFrames
        [
          {
            callFrameId: '{"ordinal":0,"injectedScriptId":1}',
            functionName: 'callbackTrampoline',
            functionLocation: { scriptId: '23', lineNumber: 119, columnNumber: 27 },
            location: { scriptId: '23', lineNumber: 119, columnNumber: 27 },
            url: 'node:internal/async_hooks',
            scopeChain: [ [Object], [Object], [Object], [Object] ],
            this: {
              type: 'object',
              className: 'Connection',
              description: 'Connection',
              objectId: '{"injectedScriptId":1,"id":172}'
            }
          },
          {
            callFrameId: '{"ordinal":1,"injectedScriptId":1}',
            functionName: 'post',
            functionLocation: { scriptId: '119', lineNumber: 95, columnNumber: 6 },
            location: { scriptId: '119', lineNumber: 119, columnNumber: 27 },
            url: 'node:inspector',
            scopeChain: [ [Object], [Object], [Object], [Object] ],
            this: {
              type: 'object',
              className: 'Session',
              description: 'Session',
              objectId: '{"injectedScriptId":1,"id":177}'
            }
          },
          ......
        ]

###call stats

    > var r = cmd.Profiler.enableRuntimeCallStats(sess)
    undefined
    > var r = await cmd.Profiler.getRuntimeCallStats(sess)
    undefined
    > r
    [
      { name: 'c:V8.TotalBaselineCompileCount', value: 3 },
      { name: 'c:V8.TotalBaselineCodeSize', value: 776 },
      { name: 'c:V8.NumberOfSymbols', value: 9365 },
      { name: 'c:V8.TotalParseSize', value: 4767 },
      { name: 'c:V8.TotalCompileSize', value: 128 },
      { name: 'c:V8.PcToCode', value: 52 },
      { name: 'c:V8.WasmRelocBytes', value: 0 },
      { name: 'c:V8.TotalLoadSize', value: 128 },
      { name: 'c:V8.ObjsSinceLastYoung', value: 0 },
      { name: 'c:V8.StringTableCapacity', value: 16384 },
      { name: 'c:V8.PcToCodeCached', value: 52 },
      { name: 'c:V8.TotalPreparseSkipped', value: 0 },
      { name: 'c:V8.LiftoffCompiledFunctions', value: 0 },
      { name: 'c:V8.MemoryNewSpaceBytesCommitted', value: 2097152 },
      { name: 'c:V8.RuntimeProfilerTicks', value: 1 },
      { name: 'c:V8.WasmGeneratedCodeBytes', value: 0 },
      { name: 'c:V8.CompilationCacheHits', value: 4 },
      { name: 'c:V8.StackInterrupts', value: 2 },
      { name: 'c:V8.ConstructedObjects', value: 12 },
      { name: 'c:V8.RegExpEntryRuntime', value: 46 },
      { name: 'c:V8.ConstructedObjectsRuntime', value: 12 },
      { name: 'c:V8.MemoryOldSpaceBytesCommitted', value: 7483392 },
      { name: 'c:V8.WasmLazilyCompiledFunctions', value: 0 },
      { name: 'c:V8.LiftoffUnsupportedFunctions', value: 0 },
      { name: 'c:V8.MemoryCodeSpaceBytesAvailable', value: 161248 },
      { name: 'c:V8.EnumCacheHits', value: 104 },
      { name: 'c:V8.MemoryNewSpaceBytesAvailable', value: 994416 },
      { name: 'c:V8.AliveAfterLastGC', value: 7858352 },
      { name: 'c:V8.MemoryOldSpaceBytesAvailable', value: 533152 },
      { name: 'c:V8.MemoryOldSpaceBytesUsed', value: 6807512 },
      { name: 'c:V8.MemoryMapSpaceBytesAvailable', value: 199456 },
      { name: 'c:V8.MemoryNewSpaceBytesUsed', value: 36656 },
      { name: 'c:V8.GlobalHandles', value: 4 },
      { name: 'c:V8.MemoryCodeSpaceBytesCommitted', value: 364544 },
      { name: 'c:V8.MemoryCodeSpaceBytesUsed', value: 170528 },
      { name: 'c:V8.MemoryMapSpaceBytesCommitted', value: 794624 },
      { name: 'c:V8.MemoryMapSpaceBytesUsed', value: 577656 },
      { name: 'c:V8.MemoryLoSpaceBytesAvailable', value: 0 },
      { name: 'c:V8.ObjectPropertiesToDictionary', value: 1 },
      { name: 'c:V8.MemoryLoSpaceBytesCommitted', value: 270336 },
      { name: 'c:V8.MemoryLoSpaceBytesUsed', value: 262160 }
    ]
    >

APIS

    {
      showp: [Function: showp],
      Session: [class Session extends Session],
      cmd: {
        Schema: { getDomains: [Function: getDomains] },
        Console: {
          clearMessages: [Function: clearMessages],
          disable: [Function: disable],
          enable: [Function: enable]
        },
        Debugger: {
          enable: [AsyncFunction: enable],
          disable: [AsyncFunction: disable],
          getScriptSource: [AsyncFunction: getScriptSource],
          getWasmBytecode: [AsyncFunction: getWasmBytecode],
          setScriptSource: [AsyncFunction: setScriptSource],
          pause: [AsyncFunction: pause],
          resume: [AsyncFunction: resume],
          enable_async_call_stack_tracking: [AsyncFunction: enable_async_call_stack_tracking],
          disable_async_call_stack_tracking: [AsyncFunction: disable_async_call_stack_tracking],
          searchInContent: [AsyncFunction],
          stepOver: [AsyncFunction: stepOver],
          stepInto: [AsyncFunction: stepInto],
          stepOut: [AsyncFunction: stepOut],
          continueToLocation: [AsyncFunction],
          setSkipAllPauses: [AsyncFunction: setSkipAllPauses],
          setPauseOnExceptions: [AsyncFunction],
          setReturnValue: [AsyncFunction: setReturnValue],
          setVariableValue: [AsyncFunction: setVariableValue],
          pauseOnAsyncCall: [AsyncFunction: pauseOnAsyncCall],
          setBreakpointsActive: [AsyncFunction: setBreakpointsActive],
          setBreakpointOnFunctionCall: [AsyncFunction: setBreakpointOnFunctionCall],
          setBreakpoint: [AsyncFunction: setBreakpoint],
          setInstrumentationBreakpoint: [AsyncFunction: setInstrumentationBreakpoint],
          setBreakpointByUrl: [AsyncFunction: setBreakpointByUrl],
          setBlackboxPatterns: [AsyncFunction: setBlackboxPatterns],
          setBlackboxedRanges: [AsyncFunction: setBlackboxedRanges],
          getPossibleBreakpoints: [AsyncFunction: getPossibleBreakpoints],
          removeBreakpoint: [AsyncFunction: removeBreakpoint],
          restartFrame: [AsyncFunction: restartFrame],
          getStackTrace: [AsyncFunction: getStackTrace],
          evaluateOnCallFrame: [AsyncFunction: evaluateOnCallFrame]
        },
        Runtime: {
          enable: [AsyncFunction: enable],
          disable: [AsyncFunction: disable],
          setAsyncCallStackDepth: [Function: setAsyncCallStackDepth],
          setCustomObjectFormatterEnabled: [Function: setCustomObjectFormatterEnabled],
          setCustomObjectFormatterDisabled: [Function: setCustomObjectFormatterDisabled],
          setMaxCallStackSizeToCapture: [Function: setMaxCallStackSizeToCapture],
          discardConsoleEntries: [Function: discardConsoleEntries],
          getIsolateId: [AsyncFunction: getIsolateId],
          getHeapUsage: [Function: getHeapUsage],
          compileScript: [AsyncFunction],
          evaluate: [AsyncFunction],
          runScript: [AsyncFunction],
          compileAndRunScript: [AsyncFunction],
          runIfWaitingForDebugger: [AsyncFunction: runIfWaitingForDebugger],
          globalLexicalScopeNames: [AsyncFunction: globalLexicalScopeNames],
          terminateExecution: [Function: terminateExecution],
          addBinding: [AsyncFunction: addBinding],
          removeBindingListen: [AsyncFunction: removeBindingListen],
          getProperties: [AsyncFunction],
          getOwnProperties: [AsyncFunction: getOwnProperties],
          getAccessorProperties: [AsyncFunction: getAccessorProperties],
          queryObjects: [AsyncFunction: queryObjects],
          releaseObject: [AsyncFunction: releaseObject],
          releaseObjectGroup: [AsyncFunction: releaseObjectGroup],
          awaitPromise: [AsyncFunction: awaitPromise]
        },
        Profiler: {
          enable: [AsyncFunction: enable],
          setSamplingInterval: [AsyncFunction: setSamplingInterval],
          start_profile: [AsyncFunction: start_profile],
          start_console_profile: [AsyncFunction: start_console_profile],
          enable_and_start: [AsyncFunction: enable_and_start],
          enable_and_start_console_profile: [AsyncFunction: enable_and_start_console_profile],
          stop_profile: [AsyncFunction: stop_profile],
          end_console_profile: [AsyncFunction: end_console_profile],
          stop_and_disable: [AsyncFunction: stop_and_disable],
          end_and_disable_console_profile: [AsyncFunction: end_and_disable_console_profile],
          disable: [AsyncFunction: disable],
          enableRuntimeCallStats: [AsyncFunction: enableRuntimeCallStats],
          disableRuntimeCallStats: [AsyncFunction: disableRuntimeCallStats],
          getRuntimeCallStats: [AsyncFunction: getRuntimeCallStats],
          enableCounters: [AsyncFunction: enableCounters],
          disableCounters: [AsyncFunction: disableCounters],
          getCounters: [AsyncFunction: getCounters],
          startTypeProfile: [AsyncFunction: startTypeProfile],
          takeTypeProfile: [AsyncFunction: takeTypeProfile],
          stopTypeProfile: [AsyncFunction: stopTypeProfile],
          getBestEffortCoverage: [AsyncFunction: getBestEffortCoverage],
          startPreciseCoverage: [AsyncFunction],
          takePreciseCoverage: [AsyncFunction: takePreciseCoverage],
          stopPreciseCoverage: [AsyncFunction: stopPreciseCoverage]
        },
        HeapProfiler: {
          enable: [AsyncFunction: enable],
          disable: [AsyncFunction: disable],
          collectGarbage: [AsyncFunction: collectGarbage],
          takeHeapSnapshot: [AsyncFunction: takeHeapSnapshot],
          startSampling: [AsyncFunction: startSampling],
          getSamplingProfile: [AsyncFunction: getSamplingProfile],
          stopSampling: [AsyncFunction: stopSampling],
          getHeapObjectId: [AsyncFunction: getHeapObjectId],
          getObjectByHeapObjectId: [AsyncFunction: getObjectByHeapObjectId],
          addInspectedHeapObject: [AsyncFunction: addInspectedHeapObject]
        }
      }
    }

profile

        var p = cmd.Profiler.enable_and_start(sess)

        > p
        Promise {
          {
            method: 'Profiler.consoleProfileStarted',
            params: { id: '1', location: [Object], title: '' },
            id: '1',
            location: { scriptId: '158', lineNumber: 32, columnNumber: 13 },
            title: ''
          }
        }
        >
        var p = cmd.Profiler.end_and_disable(sess)

        > p
        Promise {
          {
            id: '1',
            location: { scriptId: '158', lineNumber: 60, columnNumber: 13 },
            profile: {
              nodes: [Array],
              startTime: 1799450459243,
              endTime: 1799456455550,
              samples: [Array],
              timeDeltas: [Array]
            },
            title: ''
          }
        }
        > showp(p)
        Promise { <pending> }
        > {
          id: '1',
          location: { scriptId: '158', lineNumber: 60, columnNumber: 13 },
          profile: {
            nodes: [
              {
                id: 1,
                callFrame: {
                  functionName: '(root)',
                  scriptId: '0',
                  url: '',
                  lineNumber: -1,
                  columnNumber: -1
                },
                hitCount: 0,
                children: [ 2, 6, 7, 8 ]
              },
              {
                id: 2,
                callFrame: {
                  functionName: 'processTicksAndRejections',
                  scriptId: '24',
                  url: 'node:internal/process/task_queues',
                  lineNumber: 65,
                  columnNumber: 34
                },
              .....

LICENSE

  • ISC