tools/profiler/UnwinderThread2.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/UnwinderThread2.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZ_UNWINDER_THREAD_2_H
    1.10 +#define MOZ_UNWINDER_THREAD_2_H
    1.11 +
    1.12 +#include "GeckoProfilerImpl.h"
    1.13 +#include "ProfileEntry.h"
    1.14 +
    1.15 +#include "PlatformMacros.h"
    1.16 +#if defined(SPS_OS_android) || defined(SPS_OS_linux)
    1.17 +# include "LulMain.h"
    1.18 +#endif
    1.19 +
    1.20 +/* Top level exports of UnwinderThread.cpp. */
    1.21 +
    1.22 +// Abstract type.  A buffer which is used to transfer information between
    1.23 +// the sampled thread(s) and the unwinder thread(s).
    1.24 +typedef
    1.25 +  struct _UnwinderThreadBuffer 
    1.26 +  UnwinderThreadBuffer;
    1.27 +
    1.28 +// RUNS IN SIGHANDLER CONTEXT
    1.29 +// Called in the sampled thread (signal) context.  Adds a ProfileEntry
    1.30 +// into an UnwinderThreadBuffer that the thread has previously obtained
    1.31 +// by a call to utb__acquire_empty_buffer.
    1.32 +void utb__addEntry(/*MOD*/UnwinderThreadBuffer* utb,
    1.33 +                   ProfileEntry ent);
    1.34 +
    1.35 +// Create the unwinder thread.  At the moment there can be only one.
    1.36 +void uwt__init();
    1.37 +
    1.38 +// Request the unwinder thread to exit, and wait until it has done so.
    1.39 +// This must be called before stopping the profiler because we hold a
    1.40 +// reference to the profile which is owned by the profiler.
    1.41 +void uwt__stop();
    1.42 +
    1.43 +// Release the unwinder resources. This must be called after profiling
    1.44 +// has stop. At this point we know the profiler doesn't hold any buffer
    1.45 +// and can safely release any resources.
    1.46 +void uwt__deinit();
    1.47 +
    1.48 +// Registers a sampler thread for profiling.  Threads must be
    1.49 +// registered before calls to call utb__acquire_empty_buffer or
    1.50 +// utb__release_full_buffer have any effect.  If stackTop is
    1.51 +// nullptr, the call is ignored.
    1.52 +void uwt__register_thread_for_profiling(void* stackTop);
    1.53 +
    1.54 +// Deregister a sampler thread for profiling.
    1.55 +void uwt__unregister_thread_for_profiling();
    1.56 +
    1.57 +// RUNS IN SIGHANDLER CONTEXT 
    1.58 +// Called in the sampled thread (signal) context.  Get an empty buffer
    1.59 +// into which ProfileEntries can be put.  It may return nullptr if no
    1.60 +// empty buffers can be found, which will be the case if the unwinder
    1.61 +// thread(s) have fallen behind for some reason.  In this case the
    1.62 +// sampled thread must simply give up and return from the signal
    1.63 +// handler immediately, else it risks deadlock.
    1.64 +//
    1.65 +// If the calling thread has not previously registered itself for
    1.66 +// profiling via uwt__register_thread_for_profiling, this routine
    1.67 +// returns nullptr.
    1.68 +UnwinderThreadBuffer* uwt__acquire_empty_buffer();
    1.69 +
    1.70 +// RUNS IN SIGHANDLER CONTEXT
    1.71 +// Called in the sampled thread (signal) context.  Release a buffer
    1.72 +// that the sampled thread has acquired, handing the contents to
    1.73 +// the unwinder thread, and, if necessary, passing sufficient
    1.74 +// information (stack top chunk, + registers) to also do a native
    1.75 +// unwind.  If 'ucV' is nullptr, no native unwind is done.  If non-nullptr,
    1.76 +// it is assumed to point to a ucontext_t* that holds the initial 
    1.77 +// register state for the unwind.  The results of all of this are
    1.78 +// dumped into |aProfile| (by the unwinder thread, not the calling thread).
    1.79 +void uwt__release_full_buffer(ThreadProfile* aProfile,
    1.80 +                              UnwinderThreadBuffer* utb,
    1.81 +                              void* /* ucontext_t*, really */ ucV);
    1.82 +
    1.83 +struct LinkedUWTBuffer;
    1.84 +
    1.85 +// Get an empty buffer for synchronous unwinding.
    1.86 +// This function is NOT signal-safe.
    1.87 +LinkedUWTBuffer* utb__acquire_sync_buffer(void* stackTop);
    1.88 +
    1.89 +void utb__finish_sync_buffer(ThreadProfile* aProfile,
    1.90 +                             UnwinderThreadBuffer* utb,
    1.91 +                             void* /* ucontext_t*, really */ ucV);
    1.92 +
    1.93 +// Free an empty buffer that was previously allocated by
    1.94 +// utb__acquire_sync_buffer.
    1.95 +void utb__release_sync_buffer(LinkedUWTBuffer* utb);
    1.96 +
    1.97 +// This typedef must match uwt__release_full_buffer and uwt__finish_sync_buffer
    1.98 +typedef void (*UTB_RELEASE_FUNC)(ThreadProfile*,UnwinderThreadBuffer*,void*);
    1.99 +
   1.100 +#if defined(SPS_OS_android) || defined(SPS_OS_linux)
   1.101 +// Notify |aLUL| of the objects in the current process, so as to get
   1.102 +// it to read unwind data for them.  This has to be externally visible
   1.103 +// so it can be used in LUL unit tests, tools/profiler/tests/gtest/LulTest.cpp.
   1.104 +void read_procmaps(lul::LUL* aLUL);
   1.105 +#endif
   1.106 +
   1.107 +#endif /* ndef MOZ_UNWINDER_THREAD_2_H */

mercurial