npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-transform-slow-func-detecter

v2.2.10

Published

分析js运行过程中是否存在慢方法

Downloads

42

Readme

babel-plugin-transform-slow-func-detecter

这个插件用于分析js运行过程中是否存在慢方法。

已实现功能

  • 目前支持 react-native, web, node 平台
  • 分析同步方法运行时长
  • 分析 async 方法运行时长
  • 设置报警
    • 限制最大执行时长
    • 限制最大调用次数

1. 安装

yarn add  babel-plugin-transform-slow-func-detecter --save --dev

babel 配置

module.exports = {
  plugins: [
    [
      'babel-plugin-transform-slow-func-detecter',
      {
        printTransformInfo: false, // 是否打印编译阶段的日志
        productionEnvValue: 'production' // 如果 NODE_ENV === ${productionEnvValue} 则跳过此插件,方便在生产环境中使用
      },
    ],
  ],
};

2. 初始化(可选)

import sdf from 'babel-plugin-transform-slow-func-detecter/lib/eventCollecter';

// 参数一(必选):最大执行时长,范围 >= 0
// 参数二(必选):最大调用次数,范围 >= 0
// 参数三(可选):报警事件回调
sdf.init(1, 2, (e) => {
  // 建议先不填写第三个参数,使用默认输出
  console.info(e);
});

3. 通过日志查看慢函数

通过在 init 方法中设置过滤参数,超出阈值的函数调用会在控制台输出日志

4. 报警事件参数说明

type SfdEvent = {
  fileName: String;           // 文件地址
  row: number;                // 方法所在行
  column: number;             // 方法所在列
  isAsync: Boolean;           // 是否是异步方法
  isGenerator: Boolean;       // Generator方法
  funcName: String;           // 方法名称
  time: number;               // 开始时间
  endTime: number;            // 结束时间
  duration: number;           // 时长
  timeFromInitTime: number;   // 方法开始时间 - 应用启动时间
  endTimeFromInitTime: number;// 方法结束时间 - 应用启动时间
  count: number;              // 方法调用次数
  startSeq: number;           // 开始次序
  endSeq: number;             // 结束次序
};