unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.78k stars 270 forks source link

Idea: add metrics to the codebase interface #1954

Open pchiusano opened 3 years ago

pchiusano commented 3 years ago

The codebase implementation is a complex thing with a lot of moving pieces, and we often find ourselves wanting to get diagnostic information about how it's doing its thing. A recent example: we added some caching for terms/type signatures/decls and wanted to see the cache hit rate and how much time it saves.

Another example: how much time is being spent by various operations in the codebase? Ideally, we could add these diagnostics without it turning into a big refactoring each time, and without hacks like using Debug.Trace that spam the console.

My idea is to add a new function on Codebase, called metrics:

metrics :: m Metrics 

Where Metrics is a thing with an interface like:

Metrics.new :: IO Metrics

-- returns a function to increment the counter
Metrics.counter :: Metrics -> Text -> IO (Int -> IO ())

-- returns a functions for get and modify
Metrics.gauge :: Metrics -> Text -> a -> IO (IO a, (a -> a) -> IO a)

Metrics.display :: Metrics -> IO String
Metrics.displayOnly :: Text -> IO String

We could add ucm commands for getting at these metrics.

Created via Raycast

aryairani commented 3 years ago

I've gotta try out Raycast.