Instrumentation Class — tailwindcss Architecture
Architecture documentation for the Instrumentation class in instrumentation.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD f86cf69c_7c70_7a89_a666_593c4245917f["Instrumentation"] 5fc79c14_9f7d_c655_5020_3326a9635c4a["instrumentation.ts"] f86cf69c_7c70_7a89_a666_593c4245917f -->|defined in| 5fc79c14_9f7d_c655_5020_3326a9635c4a 666657d7_98fa_70df_afdd_2fbcbb471df3["constructor()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| 666657d7_98fa_70df_afdd_2fbcbb471df3 d1a75bfd_22e5_5724_d153_95a3d2e79bf9["hit()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| d1a75bfd_22e5_5724_d153_95a3d2e79bf9 623d82f8_1f44_f10c_5798_31968fd44fb2["start()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| 623d82f8_1f44_f10c_5798_31968fd44fb2 7f1a87a0_3ea8_7057_b711_5c7bdb1e0ce5["end()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| 7f1a87a0_3ea8_7057_b711_5c7bdb1e0ce5 c18b586a_a902_76e2_851b_7d243a526067["reset()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| c18b586a_a902_76e2_851b_7d243a526067 6dc1dd11_64c4_2049_6b20_5094d747fd15["report()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| 6dc1dd11_64c4_2049_6b20_5094d747fd15 82d81cf8_f820_6c9d_8013_780eae3e5739["Symbol()"] f86cf69c_7c70_7a89_a666_593c4245917f -->|method| 82d81cf8_f820_6c9d_8013_780eae3e5739
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