class Sampler
Defined at line 59 of file ../../src/performance/cpu_profiler/sampler.h
Protected Members
async_dispatcher_t * dispatcher_
TargetTree targets_
vector sample_specs_
vector inspecting_durations_
function sample_cb_
unordered_map process_watchers_
unordered_map job_watchers_
map contexts_
unordered_set pending_module_caches_
Public Methods
void Sampler (async_dispatcher_t *dispatcher,TargetTreetargets,std::vector<fuchsia_cpu_profiler::SamplingConfig>sample_specs,SampleCallbacksample_cb)
Defined at line 61 of file ../../src/performance/cpu_profiler/sampler.h
fxl::WeakPtr<Sampler> GetWeakPtr ()
Defined at line 85 of file ../../src/performance/cpu_profiler/sampler.h
std::optional<std::string_view> GetProcessName (zx_koid_t pid)
Defined at line 87 of file ../../src/performance/cpu_profiler/sampler.h
std::optional<std::string_view> GetThreadName (zx_koid_t tid)
Defined at line 90 of file ../../src/performance/cpu_profiler/sampler.h
std::vector<zx::ticks> SamplingDurations ()
Defined at line 93 of file ../../src/performance/cpu_profiler/sampler.h
zx::result<> Start (size_t buffer_size_mb)
Defined at line 237 of file ../../src/performance/cpu_profiler/sampler.cc
zx::result<> Stop ()
Defined at line 248 of file ../../src/performance/cpu_profiler/sampler.cc
void GetContexts (fit::callback<void (zx::result<profiler::SymbolizationContext>)> callback)
Asynchronously gathers the information needed to symbolize the samples.
Process modules are read on a background thread so that `dispatcher_` keeps servicing the
process exception channels in the meantime: reading a process's memory may fault, and
resolving that fault may in turn require one of those exceptions to be handled.
`callback` is invoked on `dispatcher_` with the result, after every module scan scheduled
before this call has completed. If the sampler is destroyed first, `callback` is dropped
without being invoked. Only one call may be outstanding at a time.
Defined at line 296 of file ../../src/performance/cpu_profiler/sampler.cc
zx::result<> AddTarget (JobTarget && target)
Defined at line 108 of file ../../src/performance/cpu_profiler/sampler.cc
void ~Sampler ()
Defined at line 291 of file ../../src/performance/cpu_profiler/sampler.cc
Protected Methods
zx::result<> WatchTargets ()
Defined at line 181 of file ../../src/performance/cpu_profiler/sampler.cc
zx::result<> WatchTarget (const JobTarget & target)
Defined at line 117 of file ../../src/performance/cpu_profiler/sampler.cc
void AddThread (std::vector<zx_koid_t>job_path,zx_koid_tpid,zx_koid_ttid,zx::threadt)
Defined at line 369 of file ../../src/performance/cpu_profiler/sampler.cc
void RemoveThread (std::vector<zx_koid_t>job_path,zx_koid_tpid,zx_koid_ttid)
Defined at line 385 of file ../../src/performance/cpu_profiler/sampler.cc
void CollectSamples (async_dispatcher_t *dispatcher,async::TaskBase *task,zx_status_tstatus)
Defined at line 255 of file ../../src/performance/cpu_profiler/sampler.cc
void CacheModules (const ProcessTarget & p)
Defined at line 394 of file ../../src/performance/cpu_profiler/sampler.cc
void ScheduleCacheModules (std::vector<zx_koid_t> job_path, zx_koid_t pid)
Cache the modules of process `pid` on a dedicated background worker loop so that reading a
process's modules (e.g. for Starnix processes with large address spaces) never blocks
`dispatcher_`, which services process/thread exception channels.
Defined at line 443 of file ../../src/performance/cpu_profiler/sampler.cc
void RunUntilModuleCachesDoneForTesting (async::Loop & loop)
Runs `loop`, which must own `dispatcher_`, until every task already posted to the module cache
loop has run and the results it posted back to `dispatcher_` have been delivered.
`loop` keeps running in the meantime rather than blocking on the module cache loop: a module
cache task (or the module cache thread starting) can wait on an exception that only
`dispatcher_` handles.
Defined at line 423 of file ../../src/performance/cpu_profiler/sampler.cc
void AddProcessesStartedSinceConfigure ()
The target tree is populated when the session is configured, which can take a long time for
large targets (e.g. the whole system), and processes and threads keep starting in the meantime.
These add the ones that started since then, so that they aren't silently left out of the
session.
Call AddProcessesStartedSinceConfigure after watching the target jobs, and
AddThreadsStartedSinceConfigure after watching `process`, so that anything starting later is
reported by the watchers instead.
Defined at line 491 of file ../../src/performance/cpu_profiler/sampler.cc
void AddThreadsStartedSinceConfigure (std::span<const zx_koid_t> job_path, const ProcessTarget & process)
Defined at line 592 of file ../../src/performance/cpu_profiler/sampler.cc