tools/profiler/UnwinderThread2.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZ_UNWINDER_THREAD_2_H
michael@0 7 #define MOZ_UNWINDER_THREAD_2_H
michael@0 8
michael@0 9 #include "GeckoProfilerImpl.h"
michael@0 10 #include "ProfileEntry.h"
michael@0 11
michael@0 12 #include "PlatformMacros.h"
michael@0 13 #if defined(SPS_OS_android) || defined(SPS_OS_linux)
michael@0 14 # include "LulMain.h"
michael@0 15 #endif
michael@0 16
michael@0 17 /* Top level exports of UnwinderThread.cpp. */
michael@0 18
michael@0 19 // Abstract type. A buffer which is used to transfer information between
michael@0 20 // the sampled thread(s) and the unwinder thread(s).
michael@0 21 typedef
michael@0 22 struct _UnwinderThreadBuffer
michael@0 23 UnwinderThreadBuffer;
michael@0 24
michael@0 25 // RUNS IN SIGHANDLER CONTEXT
michael@0 26 // Called in the sampled thread (signal) context. Adds a ProfileEntry
michael@0 27 // into an UnwinderThreadBuffer that the thread has previously obtained
michael@0 28 // by a call to utb__acquire_empty_buffer.
michael@0 29 void utb__addEntry(/*MOD*/UnwinderThreadBuffer* utb,
michael@0 30 ProfileEntry ent);
michael@0 31
michael@0 32 // Create the unwinder thread. At the moment there can be only one.
michael@0 33 void uwt__init();
michael@0 34
michael@0 35 // Request the unwinder thread to exit, and wait until it has done so.
michael@0 36 // This must be called before stopping the profiler because we hold a
michael@0 37 // reference to the profile which is owned by the profiler.
michael@0 38 void uwt__stop();
michael@0 39
michael@0 40 // Release the unwinder resources. This must be called after profiling
michael@0 41 // has stop. At this point we know the profiler doesn't hold any buffer
michael@0 42 // and can safely release any resources.
michael@0 43 void uwt__deinit();
michael@0 44
michael@0 45 // Registers a sampler thread for profiling. Threads must be
michael@0 46 // registered before calls to call utb__acquire_empty_buffer or
michael@0 47 // utb__release_full_buffer have any effect. If stackTop is
michael@0 48 // nullptr, the call is ignored.
michael@0 49 void uwt__register_thread_for_profiling(void* stackTop);
michael@0 50
michael@0 51 // Deregister a sampler thread for profiling.
michael@0 52 void uwt__unregister_thread_for_profiling();
michael@0 53
michael@0 54 // RUNS IN SIGHANDLER CONTEXT
michael@0 55 // Called in the sampled thread (signal) context. Get an empty buffer
michael@0 56 // into which ProfileEntries can be put. It may return nullptr if no
michael@0 57 // empty buffers can be found, which will be the case if the unwinder
michael@0 58 // thread(s) have fallen behind for some reason. In this case the
michael@0 59 // sampled thread must simply give up and return from the signal
michael@0 60 // handler immediately, else it risks deadlock.
michael@0 61 //
michael@0 62 // If the calling thread has not previously registered itself for
michael@0 63 // profiling via uwt__register_thread_for_profiling, this routine
michael@0 64 // returns nullptr.
michael@0 65 UnwinderThreadBuffer* uwt__acquire_empty_buffer();
michael@0 66
michael@0 67 // RUNS IN SIGHANDLER CONTEXT
michael@0 68 // Called in the sampled thread (signal) context. Release a buffer
michael@0 69 // that the sampled thread has acquired, handing the contents to
michael@0 70 // the unwinder thread, and, if necessary, passing sufficient
michael@0 71 // information (stack top chunk, + registers) to also do a native
michael@0 72 // unwind. If 'ucV' is nullptr, no native unwind is done. If non-nullptr,
michael@0 73 // it is assumed to point to a ucontext_t* that holds the initial
michael@0 74 // register state for the unwind. The results of all of this are
michael@0 75 // dumped into |aProfile| (by the unwinder thread, not the calling thread).
michael@0 76 void uwt__release_full_buffer(ThreadProfile* aProfile,
michael@0 77 UnwinderThreadBuffer* utb,
michael@0 78 void* /* ucontext_t*, really */ ucV);
michael@0 79
michael@0 80 struct LinkedUWTBuffer;
michael@0 81
michael@0 82 // Get an empty buffer for synchronous unwinding.
michael@0 83 // This function is NOT signal-safe.
michael@0 84 LinkedUWTBuffer* utb__acquire_sync_buffer(void* stackTop);
michael@0 85
michael@0 86 void utb__finish_sync_buffer(ThreadProfile* aProfile,
michael@0 87 UnwinderThreadBuffer* utb,
michael@0 88 void* /* ucontext_t*, really */ ucV);
michael@0 89
michael@0 90 // Free an empty buffer that was previously allocated by
michael@0 91 // utb__acquire_sync_buffer.
michael@0 92 void utb__release_sync_buffer(LinkedUWTBuffer* utb);
michael@0 93
michael@0 94 // This typedef must match uwt__release_full_buffer and uwt__finish_sync_buffer
michael@0 95 typedef void (*UTB_RELEASE_FUNC)(ThreadProfile*,UnwinderThreadBuffer*,void*);
michael@0 96
michael@0 97 #if defined(SPS_OS_android) || defined(SPS_OS_linux)
michael@0 98 // Notify |aLUL| of the objects in the current process, so as to get
michael@0 99 // it to read unwind data for them. This has to be externally visible
michael@0 100 // so it can be used in LUL unit tests, tools/profiler/tests/gtest/LulTest.cpp.
michael@0 101 void read_procmaps(lul::LUL* aLUL);
michael@0 102 #endif
michael@0 103
michael@0 104 #endif /* ndef MOZ_UNWINDER_THREAD_2_H */

mercurial