Instrumentation Class — tailwindcss Architecture
Architecture documentation for the Instrumentation class in instrumentation.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 8a5a53c8_b056_fb86_4bf2_308f1ad171e8["Instrumentation"] bd16b7ea_bbf0_4269_b855_66ce2c516e3e["instrumentation.ts"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|defined in| bd16b7ea_bbf0_4269_b855_66ce2c516e3e 15f31333_4655_c061_f098_3c7c67db5664["constructor()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| 15f31333_4655_c061_f098_3c7c67db5664 ae81471a_9ad8_3dba_0118_926138942a5a["hit()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| ae81471a_9ad8_3dba_0118_926138942a5a 21ced873_9602_86e0_fb63_44277812c5a2["start()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| 21ced873_9602_86e0_fb63_44277812c5a2 e3047f9a_7449_3dfb_8bbb_cf79ddc89fc1["end()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| e3047f9a_7449_3dfb_8bbb_cf79ddc89fc1 da9e6e55_4880_00a0_8298_0004e29a718c["reset()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| da9e6e55_4880_00a0_8298_0004e29a718c 6964633c_136d_e731_7357_c395276476b3["report()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| 6964633c_136d_e731_7357_c395276476b3 b8e2c265_5a16_1719_f5fc_7d3331c4d64b["Symbol()"] 8a5a53c8_b056_fb86_4bf2_308f1ad171e8 -->|method| b8e2c265_5a16_1719_f5fc_7d3331c4d64b
Relationship Graph
Source Code
packages/@tailwindcss-node/src/instrumentation.ts lines 10–105
export class Instrumentation implements Disposable {
#hits = new DefaultMap(() => ({ value: 0 }))
#timers = new DefaultMap(() => ({ value: 0n }))
#timerStack: { id: string; label: string; namespace: string; value: bigint }[] = []
constructor(
private defaultFlush = (message: string) => void process.stderr.write(`${message}\n`),
) {}
hit(label: string) {
this.#hits.get(label).value++
}
start(label: string) {
let namespace = this.#timerStack.map((t) => t.label).join('//')
let id = `${namespace}${namespace.length === 0 ? '' : '//'}${label}`
this.#hits.get(id).value++
// Create the timer if it doesn't exist yet
this.#timers.get(id)
this.#timerStack.push({ id, label, namespace, value: process.hrtime.bigint() })
}
end(label: string) {
let end = process.hrtime.bigint()
if (this.#timerStack[this.#timerStack.length - 1].label !== label) {
throw new Error(
`Mismatched timer label: \`${label}\`, expected \`${
this.#timerStack[this.#timerStack.length - 1].label
}\``,
)
}
let parent = this.#timerStack.pop()!
let elapsed = end - parent.value
this.#timers.get(parent.id).value += elapsed
}
reset() {
this.#hits.clear()
this.#timers.clear()
this.#timerStack.splice(0)
}
report(flush = this.defaultFlush) {
let output: string[] = []
let hasHits = false
// Auto end any pending timers
for (let i = this.#timerStack.length - 1; i >= 0; i--) {
this.end(this.#timerStack[i].label)
}
for (let [label, { value: count }] of this.#hits.entries()) {
if (this.#timers.has(label)) continue
if (output.length === 0) {
hasHits = true
output.push('Hits:')
}
let depth = label.split('//').length
output.push(`${' '.repeat(depth)}${label} ${dim(blue(`× ${count}`))}`)
}
if (this.#timers.size > 0 && hasHits) {
output.push('\nTimers:')
}
let max = -Infinity
let computed = new Map<string, string>()
for (let [label, { value }] of this.#timers) {
let x = `${(Number(value) / 1e6).toFixed(2)}ms`
computed.set(label, x)
max = Math.max(max, x.length)
}
for (let label of this.#timers.keys()) {
let depth = label.split('//').length
Domain
Source
Frequently Asked Questions
What is the Instrumentation class?
Instrumentation is a class in the tailwindcss codebase, defined in packages/@tailwindcss-node/src/instrumentation.ts.
Where is Instrumentation defined?
Instrumentation is defined in packages/@tailwindcss-node/src/instrumentation.ts at line 10.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free