| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
GHC.Stack.Profiler
Synopsis
- data Profiler = MkProfiler {}
- withProfiler :: (Profiler -> IO a) -> IO a
- withProfilerWith :: Options -> (Profiler -> IO a) -> IO a
- withProfilerFromEnv :: (Maybe Profiler -> IO a) -> IO a
- startProfiler :: IO Profiler
- startProfilerWith :: Options -> IO Profiler
- startProfilerFromEnv :: IO (Maybe Profiler)
- stopProfiler :: Profiler -> IO ()
- data Options
- defaultOptions :: Options
- newtype Interval = MkIntervalMillis {}
- type ThreadFilter = ThreadId -> Maybe ThreadLabel -> ShouldSample
- type ThreadLabel = String
- data ShouldSample
- data Glob
- matches :: Glob -> String -> Bool
- sampleInclude :: Glob -> ThreadFilter
- sampleExclude :: Glob -> ThreadFilter
- sampleIncludeExclude :: Glob -> Glob -> ThreadFilter
- fromEnv :: IO (Maybe Options)
- data Manager
- withManager :: Bool -> (Manager -> IO a) -> IO a
- startManager :: Bool -> IO Manager
- stopManager :: Manager -> IO ()
- startProfiling :: Manager -> IO ()
- stopProfiling :: Manager -> IO ()
- data Sampler
- withSamplerForMe :: Manager -> Interval -> (Sampler -> IO a) -> IO a
- startSamplerFor :: Manager -> ThreadId -> Interval -> IO Sampler
- startSamplerWith :: Manager -> Options -> IO Sampler
- stopSampler :: Manager -> Sampler -> IO ()
High-Level API
Profiler
A profiler handle, which can be used to stop the profiler with stopProfiler.
Since: 0.5.0.0
Constructors
| MkProfiler | |
Fields
| |
withProfilerWith :: Options -> (Profiler -> IO a) -> IO a Source #
Variant of withProfiler that accepts Options.
Since: 0.5.0.0
withProfilerFromEnv :: (Maybe Profiler -> IO a) -> IO a Source #
Variant of withProfiler that reads Options from the environment.
If GHC_STACK_PROFILER is unset or empty, no Profiler is started.
Since: 0.5.0.0
startProfiler :: IO Profiler Source #
Start a Profiler with the default Options.
This function returns a Profiler handle, which can be used to stop
the profiler with stopProfiler.
Warning: This function spawns a Manager thread.
Having multiple concurrent Manager threads is unsupported and unsafe.
Warning: If the Profiler is not stopped before the program exits,
some messages may not be written to the eventlog.
Since: 0.5.0.0
startProfilerWith :: Options -> IO Profiler Source #
Variant of startProfiler that accepts Options.
Since: 0.5.0.0
startProfilerFromEnv :: IO (Maybe Profiler) Source #
Variant of startProfiler that accepts Options.
If GHC_STACK_PROFILER is unset or empty, no Profiler is started.
Since: 0.5.0.0
Options
The options for withProfilerWith and startProfilerWith.
To construct options, modify defaultOptions using the fields:
wait::Bool- Determines if sampler threads are started on creation or wait for a
"start profiling" command on the eventlog socket. If you are using
ghc-stack-profilerwitheventlog-socket's control commands, this should be set toTrue. Otherwise, this should beFalse. The default isFalse. shouldSample::ThreadId->MaybeThreadLabel->ShouldSample- Determines if the thread idenfied by the
ThreadIdshould be sampled. The currentThreadLabel, returned bythreadLabel, is passed as the second argument. If this function returnsNever, the thread will never be sampled, even if itsThreadLabelchanges. The default predicate always returnsYes. This function is not used for RTS threads or threads spawned byghc-stack-profiler. sampleRtsThreads::Bool- Determines if builtin RTS threads should be sampled. The builtin RTS
threads are the TimerManager and IOManager threads, and do not usually
have an interesting call-stack profile. The default is
False. sampleProfilerThreads::Bool- Determines if the threads spawned by
ghc-stack-profilershould be sampled. The default isFalse. sampleInterval::Interval- Determines the sampling interval.
The default is
10milliseconds.
Since: 0.5.0.0
The sampling interval.
Since: 0.5.0.0
Constructors
| MkIntervalMillis | |
Fields | |
Thread Filters and Glob Patterns
type ThreadFilter = ThreadId -> Maybe ThreadLabel -> ShouldSample Source #
A thread filter, used to determine which threads should be sampled.
Used in the shouldSample field of Options.
Since: 0.5.0.0
type ThreadLabel = String Source #
A thread label, as set by labelThread.
Since: 0.5.0.0
data ShouldSample Source #
The result type of a ThreadFilter.
Since: 0.5.0.0
A glob pattern.
Use fromString to construct glob patterns from strings.
A * matches any string, including the empty string.
One can remove the special meaning of * by preceding it with a backslash.
Since: 0.5.0.0
Arguments
| :: Glob | The include pattern. |
| -> ThreadFilter |
Arguments
| :: Glob | The exclude pattern. |
| -> ThreadFilter |
Arguments
| :: Glob | The include pattern. |
| -> Glob | The exclude pattern. |
| -> ThreadFilter |
Environment Variables
fromEnv :: IO (Maybe Options) Source #
Read the Options from the environment.
GHC_STACK_PROFILER- If set to any non-empty value, read and return the options.
Otherwise, return
Nothing, which indicates theProfilershould not be started. GHC_STACK_PROFILER_WAIT- If set to any non-empty value,
waitis set toTrue. GHC_STACK_PROFILER_SAMPLE_INCLUDE- If set,
shouldSampleis set to theThreadFilterconstructed usingsampleIncludeusing the value as aGlobpattern. IfGHC_STACK_PROFILER_SAMPLE_EXCLUDEis also set,sampleIncludeExcludeis used. GHC_STACK_PROFILER_SAMPLE_EXCLUDE- If set,
shouldSampleis set to theThreadFilterconstructed usingsampleExcludeusing the value as aGlobpattern. IfGHC_STACK_PROFILER_SAMPLE_INCLUDEis also set,sampleIncludeExcludeis used. GHC_STACK_PROFILER_SAMPLE_RTS_THREADS- If set to any non-empty value,
sampleRtsThreadsis set toTrue. GHC_STACK_PROFILER_SAMPLE_PROFILER_THREADS- If set to any non-empty value,
sampleProfilerThreadsis set toTrue. GHC_STACK_PROFILER_SAMPLE_INTERVAL- If set to any numeric value,
sampleIntervalis set to theIntervalconstructed using the value as milliseconds. If set to any non-numeric value, a warning is printed tostderrand the defaultsampleIntervalis used.
Warning: This function reads environment variables, which is not thread-safe.
See getenv.
Since: 0.5.0.0
Low-Level API
Manager
A Manager handle, which can be used to stop the manager with stopManager.
Since: 0.5.0.0
Arguments
| :: Bool | Flag that determines if sampler threads should wait. |
| -> (Manager -> IO a) | The action that runs with the |
| -> IO a |
Run an action with a new Manager.
The first argument indicates if sampler threads should wait for a call to
startProfiling or a "start profiling" command on the eventlog socket.
If you are using ghc-stack-profiler with eventlog-socket's control
commands, this should be set to True.
The Manager is stopped when the action finishes.
Warning: This function spawns a Manager thread.
Having multiple concurrent Manager threads is unsupported and unsafe.
Since: 0.5.0.0
startManager :: Bool -> IO Manager Source #
Start a Manager.
The first argument indicates if sampler threads should wait for a call to
startProfiling or a "start profiling" command on the eventlog socket.
If you are using ghc-stack-profiler with eventlog-socket's control
commands, this should be set to True.
Warning: This function spawns a Manager thread.
Having multiple concurrent Manager threads is unsupported and unsafe.
Warning: The manager should be stopped with stopManager.
Since: 0.5.0.0
stopManager :: Manager -> IO () Source #
Commands
startProfiling :: Manager -> IO () Source #
stopProfiling :: Manager -> IO () Source #
Samplers
A Sampler handle, which can be used to stop the sampler with stopSampler.
Since: 0.5.0.0
startSamplerFor :: Manager -> ThreadId -> Interval -> IO Sampler Source #
Start a sampler for the given ThreadId.
Warning: The sampler should be stopped using stopSampler or stopManager.
Since: 0.5.0.0
startSamplerWith :: Manager -> Options -> IO Sampler Source #
Start a sampler with the given Options.
This function ignores the wait field and uses the value that was
passed to the Manager on creation.
Warning: The sampler should be stopped using stopSampler or stopManager.
Since: 0.5.0.0