preactjs / preact-devtools

Browser extension for inspection Preact applications
https://preactjs.github.io/preact-devtools/
MIT License
315 stars 27 forks source link

Add interaction tracking #181

Open marvinhagemeister opened 4 years ago

marvinhagemeister commented 4 years ago

It's essentially a more powerful performance.measure() alternative that captures additional details that's exclusive to extensions like CPU load.

Links:

marvinhagemeister commented 4 years ago

Turns out this is much more useful, because it can be used to track application performance in Preact and have that sent to a Graphana/Splunk instanace.

Quoting a thread on our slack channel:

the idea is to use this on each click handler

import {unstable_trace as trace} from 'scheduler/tracing'
trace('click', performance.now(), () => setCount(c => c + 1))

function reportProfile(
  id, // the "id" prop of the Profiler tree that has just committed
  phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered)
  actualDuration, // time spent rendering the committed update
  baseDuration, // estimated time to render the entire subtree without memoization
  startTime, // when React began rendering this update
  commitTime, // when React committed this update
  interactions, // the Set of interactions belonging to this update
) {
  queue.push({
    id,
    phase,
    actualDuration,
    baseDuration,
    startTime,
    commitTime,
    interactions,
  })
  // this is a fire and forget, so we don't return anything.
}

and then each 5 seconds send the request to save the data in Splunk const queueToSend = [...queue]