阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js perf_hooks performanceObserver.observe

      Node.js perf_hooks performanceObserver.observe(options)

      新增于: v8.5.0

      • options < Object>
        • entryTypes < string[]> An array of strings identifying the types of PerformanceEntry instances the observer is interested in. If not provided an error will be thrown.
        • buffered < boolean> If true, the notification callback will be called using setImmediate() and multiple PerformanceEntry instance notifications will be buffered internally. If false, notifications will be immediate and synchronous. Default: false.

      Subscribes the PerformanceObserver instance to notifications of new PerformanceEntry instances identified by options.entryTypes.

      When options.buffered is false, the callback will be invoked once for every PerformanceEntry instance:

      const {
        performance,
        PerformanceObserver
      } = require('perf_hooks');
      
      const obs = new PerformanceObserver((list, observer) => {
        // called three times synchronously. list contains one item
      });
      obs.observe({ entryTypes: ['mark'] });
      
      for (let n = 0; n < 3; n++)
        performance.mark(`test${n}`);
      
      const {
        performance,
        PerformanceObserver
      } = require('perf_hooks');
      
      const obs = new PerformanceObserver((list, observer) => {
        // called once. list contains three items
      });
      obs.observe({ entryTypes: ['mark'], buffered: true });
      
      for (let n = 0; n < 3; n++)
        performance.mark(`test${n}`);
      

      更多内容请参考:Node.js perf_hooks 性能钩子,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录