class ThreadSamplerDispatcher

Defined at line 54 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h

A ThreadSampler is really just an IOBuffer with some added control methods on top to start and

stop sampling.

Public Methods

void ~ThreadSamplerDispatcher ()

Defined at line 56 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h

SamplingState State ()

Defined at line 74 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h

void SetCurrCpuTimer ()

Set a timer based on the configured duration. When the timer expires, the currently running

thread will be marked to take a sample.

Defined at line 321 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

void OnPeerZeroHandlesLocked ()

When the user drops their end of the buffer/sampler, we need to stop sampling and clean up the

state.

Defined at line 292 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<size_t> ReadUser (user_out_ptr<void> ptr, uint32_t offset, size_t len)
zx::result<KernelHandle<ThreadSamplerDispatcher>> Create (const zx_sampler_config_t & config)

Defined at line 325 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> Start (const fbl::RefPtr<IoBufferDispatcher> & disp)

Defined at line 368 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> Stop (const fbl::RefPtr<IoBufferDispatcher> & disp)

Defined at line 357 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> AddThread (const fbl::RefPtr<IoBufferDispatcher> & disp, const fbl::RefPtr<ThreadDispatcher> & thread)
zx::result<> SampleThread (zx_koid_t pid, zx_koid_t tid, GeneralRegsSource source, void * gregs)

Given a thread's registers, pid, and tid, walk the thread's user stack and write each

pointer to the sampling buffers if sampling is enabled.

WARNING: SampleThread both

a) does a large number of user copies, and

b) allocates a large amount of stack space

It should only be called from Thread::Current::ProcessPendingSignals where we can be user that

the user copies are safe to do and where the current stack size should be relatively shallow.

Defined at line 379 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

ktl::pair<zx_status_t, size_t> ReadUser (const fbl::RefPtr<IoBufferDispatcher> & disp, user_out_ptr<void> ptr, size_t len)

Read out the data contained in the sampler buffers into `ptr` return the number of bytes

written. The Sampling state must be Stopped before calling this function.

`len` _must_ be at least equal to the total size of the sampler buffers, which can be queried

by passing a nullptr `ptr`. In this case, no data will be written and the return value will be

the required minimum size of the buffer to write to.

Defined at line 404 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

Protected Methods

internal::PerCpuState & GetPerCpuState (size_t i)

Defined at line 110 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h

void ThreadSamplerDispatcher (fbl::RefPtr<PeerHolder<IoBufferDispatcher>> holder, IobEndpointId endpoint_id, fbl::RefPtr<SharedIobState> shared_state)

Defined at line 112 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h

zx::result<> CreateImpl (const zx_sampler_config_t & config, KernelHandle<ThreadSamplerDispatcher> & read_handle_out, KernelHandle<ThreadSamplerDispatcher> & write_handle_out)

Create a ThreadSamplerDispatcher. The ThreadSamplerDispatcher is a peered object with one end

readable and one end writable. The write end is retained by the kernel to write samples to. The

user receives the read end of the buffer so that they may read the samples written.

Defined at line 25 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> SampleThreadImpl (zx_koid_t pid, zx_koid_t tid, GeneralRegsSource source, void * gregs)

Given information about a thread and its registers, walk its userstack and write out a sample

if sampling is enabled.

Defined at line 154 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> StartImpl ()

Defined at line 83 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

zx::result<> StopImpl ()

Defined at line 103 of file ../../zircon/kernel/lib/thread_sampler/thread_sampler.cc

Enumerations

enum SamplingState
Name Value
Configured 0
Running 1
Reading 2
Destroying 3
Destroyed 4

Defined at line 66 of file ../../zircon/kernel/lib/thread_sampler/include/lib/thread_sampler/thread_sampler.h