clinicjs / node-clinic

Clinic.js diagnoses your Node.js performance issues
https://clinicjs.org
MIT License
5.69k stars 125 forks source link

Flame: incorrectly detects `category` and `type` for projects with type: module #446

Closed MrWaip closed 1 year ago

MrWaip commented 1 year ago

Hello. I was looking for bottlenecks in my svelte.kit project. The project uses esm modules by default. And I was confused that all my source code was marked as Node JS.

Expected Behavior

With esm module code have to be marked as { type: appName, category: 'app'}

Current Behavior

Now when I use esm modules my code marked as core.

# /analysis/frame-node.js
# at function getCoreOrV8Type

 getCoreOrV8Type (name, systemInfo) {
    // TODO: see if any subdivisions of core are useful
    const core = { type: 'core', category: 'core' }

    let type

    if (/\[CODE:RegExp]$/.test(name)) {
      type = 'regexp'
    } else if (!/(\.m?js)|(node:\w)/.test(name)) {
      if (/\[CODE:.*?]$/.test(name) || /v8::internal::.*\[CPP]$/.test(name)) {
        type = 'v8'
      } else /* istanbul ignore next */ if (/\.$/.test(name)) {
        return core
      } else if (/\[CPP]$/.test(name) || /\[SHARED_LIB]$/.test(name)) {
        type = 'cpp'
      } else if (/\[eval]/.test(name)) {
        // unless we create an eval checkbox
        // "native" is the next best label since
        // you cannot tell where the eval comes
        // from (app, deps, core)
        type = 'native'
      } else {
        type = 'v8'
      }
    } else if (/ native /.test(name)) {
      type = 'native'
    } else if (this.isNodeCore(systemInfo)) { # <------------------------------ here is bug
      return core 
    }

    return type
      ? { type, category: 'all-v8' }
      : null
  }

Steps to Reproduce (for bugs)

Just try node-clinic-flame-demo with "type":"module" and import some function.

Sample upload

image

Environment

MrWaip commented 1 year ago

I can assume that we can detect source code by using /file\:\/\//.test(name)

RafaelGSS commented 1 year ago

Which operating system are you using?

MrWaip commented 1 year ago

Which operating system are you using?

Mac OS: 12.6 (21G115) (Monterey)