devtools icon indicating copy to clipboard operation
devtools copied to clipboard

What feature does plugins framegraph want

Open CrabSAMA opened this issue 1 year ago • 9 comments

I saw TODO in this file: https://github.com/vitejs/devtools/blob/2a0b6b04348873596cf3052c18fdfe68886d0418/packages/devtools/src/app/pages/session/%5Bsession%5D/plugins.vue#L15-L20

And I saw this module flamegraph in module page:

Image

this graph show the module was handled by what hooks and plugins.

I guess the plugins framegraph should be presented from different perspectives, but I did not know what feature need in the plugins framegraph, anyone can give me some opinion?

IMO, if I am user, I want to see what plugin used in bundling, and each plugin uses which hooks, how much time is spent on each hook, and which files are processed.

I try to add a rpc function to group plugin details by plugin name

import { defineRpcFunction } from '../utils'

export const rolldownGetPluginDetails = defineRpcFunction({
  name: 'vite:rolldown:get-plugin-details',
  type: 'query',
  setup: ({ manager }) => {
    return {
      handler: async ({ session }: { session: string }) => {
        const reader = await manager.loadSession(session)
        const plugins = reader.meta?.plugins || []
        const events = reader.manager.events
        const map = new Map<string, any[]>()
        plugins.forEach(plugin => {
          map.set(plugin.name, [])
        })
        for (const event of events) {
          if (map.has(event.plugin_name)) {
            map.get(event.plugin_name)!.push(event)
          }
        }
        return map
      },
    }
  },
})
Image

and so on I can do some thing next on this map, if some thiing I can do, I will try to contribute in this project. Please let me know what feature does plugins framegraph want and what will do at the future.

CrabSAMA avatar Jul 15 '25 12:07 CrabSAMA

Hi, so glad to see you're interested in this. With the merging of #76, I think we can now start working on the plugins framegraph. Yes, as you mentioned, we need two framegraph views, one for modules and one for plugins. If you're still interested and have time to start it, please let me know.

webfansplz avatar Aug 12 '25 04:08 webfansplz

@webfansplz Of course, I want to start a small attempt. Anything I can do?

CrabSAMA avatar Aug 12 '25 11:08 CrabSAMA

@CrabSAMA Just follow what was said above, you can start trying to draw the plugins framegraph based on the data currently provided by the plugin detail. We can track and improve some details later in the PR review.

webfansplz avatar Aug 12 '25 13:08 webfansplz

@webfansplz What puzzles me is meaning of plugins framegraph, I try to search about the meaning of framegraph, but nothing result. I don't know what should this graph show, and I can not start to coding 😂

Can you give me some idea and I'd appreciate 🙌

CrabSAMA avatar Aug 13 '25 08:08 CrabSAMA

@CrabSAMA Oh, we have a typo here 😅, actually what we are discussing here is Flamegraph, which is similar to Module Flamegraph, you can refer to it.

Image

webfansplz avatar Aug 13 '25 10:08 webfansplz

https://github.com/vitejs/devtools/pull/79

first pr here

CrabSAMA avatar Aug 14 '25 06:08 CrabSAMA

Some ideas:

  • Add the time on top and to be able to zoom in a time frame
  • Being able to click on part to focus on them and their children
  • Some datas on hover about each part (time and percentage of the total for example)

I think you can see what codspeed does for its flamegraph, it's quite nice (if you need here's a link to one from the oxc project : https://codspeed.io/oxc-project/oxc/branches/lambda47%3Afix%2Farray-callback-return?uri=tasks%2Fbenchmark%2Fbenches%2Fminifier.rs%3A%3Aminifier%3A%3Abench_minifier%3A%3Aminifier%255Breact.development.js%255D)

GeoffreyParrier avatar Aug 14 '25 08:08 GeoffreyParrier

@GeoffreyParrier Thanks for your idea! The example of codspeed look very good, I try to find what library it used, but it seem like develop without opensource library by themself.

Now this feature use nanovis library to draw flamegraph, I will try to discover this library would match this feature, and maybe I will start to do something easy first, such as idea 2,3.

If we found nanovis can not match our target feature, would we use another flamegrpah draw library? I don't know.

Update: Idea 2 finished by nanovis itself, and I push new commit to make a initial completion of Idea3.

CrabSAMA avatar Aug 14 '25 09:08 CrabSAMA

Amazing, this is really great, thank you

GeoffreyParrier avatar Aug 15 '25 09:08 GeoffreyParrier