gecko-dev/tools/profiler/core/platform.h

128 строки
4.2 KiB
C
Исходник Обычный вид История

// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google, Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
#ifndef TOOLS_PLATFORM_H_
#define TOOLS_PLATFORM_H_
#include <stdint.h>
#include <math.h>
#include "MainThreadUtils.h"
#include "ThreadResponsiveness.h"
#include "mozilla/Logging.h"
#include "mozilla/MemoryReporting.h"
Bug 1342306 (part 3) - Properly synchronize the global state in platform*.cpp. r=mstange. This patch properly synchronizes all the global state in platform*.cpp, which gets us a long way towards implementing bug 1330184. - Most of the global state goes in a new class, ProfilerState, with a single instance, gPS. All accesses to gPS are protected by gPSMutex. All functions that access ProfilerState require a token proving that gPS is locked; this makes things much clearer. gRegisteredThreadsMutex is removed because it is subsumed by gPSMutex. - gVerbosity, however, does not go in ProfilerState. It stays separate, and gains its own mutex, gVerbosityMutex. Also, the tracking of the current profiler state is streamlined. Previously it was tracked via: - stack_key_initialized, gInitCount, gSampler, gIsProfiling, gIsActive, and gIsPaused. Now it is tracked via: - gPS, gPS->sActivity, and gPS->mIsPaused. This means that the Sampler class is no longer necessary, and the patch removes it. Other changes of note made by the patch are as follows. - It removes ThreadInfo::{mMutex,GetMutex}. This mutex was only used in two places, and both these are now protected by gPSMutex. - It tweaks the LOG calls. All the main functions (init(), shutdown(), start(), stop()) now do consistent BEGIN/END logging, and a couple of other low-value incidental LOG calls have been removed. - It adds a lot of release assertions requiring that gPS be initialized (e.g. profiler_init() has been called but profiler_shutdown() has not). - It uses alphabetical order for everything involving profiler feature names. - It removes Platform{Start,Stop}() and SamplerThread::{Start,Stop}Sampler(). These are no longer necessary now that SamplerThread::sInstance has been replaced with ProfilerState::mSamplerThread which allows more direct access to the current SamplerThread instance. - It removes PseudoStack::mPrivacyMode. This was derived from the "privacy" feature, and we now use gPS->mFeaturePrivacy directly, which is simpler. It also replaces profiler_in_privacy_mode() with profiler_is_active_and_not_in_privacy_mode(), which avoids an unnecessary lock/unlock of gPSMutex on a moderately hot path. Finally, the new code does more locking than the old one. A number of operation The following operations now lock a mutex when they previously didn't; the following are ones that are significant, according to some ad hoc profiling. - profiler_tracing() - profiler_is_active() - profiler_is_active_and_not_in_privacy_mode() - profiler_add_marker() - profiler_feature_active() - SamplerThread::Run() [when the profiler is paused] All up this roughly doubles the amount of mutex locking done by the profiler. It's probably possible to avoid this increase by allowing careful unlocked access to three of the fields in ProfilerState (mActivityGeneration, mFeaturePrivacy, mStartTime), but this should only be done as a follow-up if the extra locking is found to be a problem. --HG-- extra : rebase_source : c2e41231f131b3e9ccd23ddf43626b54ccc77b7b
2017-03-08 04:40:39 +03:00
#include "mozilla/StaticMutex.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "PlatformMacros.h"
#include <vector>
// We need a definition of gettid(), but glibc doesn't provide a
// wrapper for it.
#if defined(__GLIBC__)
Bug 1178892 - Split the profiler into Core & Gecko files and break apart monolithic headers. r=mstange --HG-- rename : tools/profiler/EHABIStackWalk.cpp => tools/profiler/core/EHABIStackWalk.cpp rename : tools/profiler/EHABIStackWalk.h => tools/profiler/core/EHABIStackWalk.h rename : tools/profiler/TableTicker.cpp => tools/profiler/core/GeckoSampler.cpp rename : tools/profiler/TableTicker.h => tools/profiler/core/GeckoSampler.h rename : tools/profiler/IntelPowerGadget.cpp => tools/profiler/core/IntelPowerGadget.cpp rename : tools/profiler/IntelPowerGadget.h => tools/profiler/core/IntelPowerGadget.h rename : tools/profiler/PlatformMacros.h => tools/profiler/core/PlatformMacros.h rename : tools/profiler/ProfileEntry.cpp => tools/profiler/core/ProfileEntry.cpp rename : tools/profiler/ProfileEntry.h => tools/profiler/core/ProfileEntry.h rename : tools/profiler/ProfileJSONWriter.cpp => tools/profiler/core/ProfileJSONWriter.cpp rename : tools/profiler/ProfileJSONWriter.h => tools/profiler/core/ProfileJSONWriter.h rename : tools/profiler/ProfilerBacktrace.cpp => tools/profiler/core/ProfilerBacktrace.cpp rename : tools/profiler/ProfilerMarkers.cpp => tools/profiler/core/ProfilerMarkers.cpp rename : tools/profiler/SyncProfile.cpp => tools/profiler/core/SyncProfile.cpp rename : tools/profiler/SyncProfile.h => tools/profiler/core/SyncProfile.h rename : tools/profiler/platform-linux.cc => tools/profiler/core/platform-linux.cc rename : tools/profiler/platform-macos.cc => tools/profiler/core/platform-macos.cc rename : tools/profiler/platform-win32.cc => tools/profiler/core/platform-win32.cc rename : tools/profiler/platform.cpp => tools/profiler/core/platform.cpp rename : tools/profiler/platform.h => tools/profiler/core/platform.h rename : tools/profiler/shared-libraries-linux.cc => tools/profiler/core/shared-libraries-linux.cc rename : tools/profiler/shared-libraries-macos.cc => tools/profiler/core/shared-libraries-macos.cc rename : tools/profiler/shared-libraries-win32.cc => tools/profiler/core/shared-libraries-win32.cc rename : tools/profiler/shim_mac_dump_syms.h => tools/profiler/core/shim_mac_dump_syms.h rename : tools/profiler/shim_mac_dump_syms.mm => tools/profiler/core/shim_mac_dump_syms.mm rename : tools/profiler/v8-support.h => tools/profiler/core/v8-support.h rename : tools/profiler/ProfileGatherer.cpp => tools/profiler/gecko/ProfileGatherer.cpp rename : tools/profiler/Profiler.jsm => tools/profiler/gecko/Profiler.jsm rename : tools/profiler/ProfilerIOInterposeObserver.cpp => tools/profiler/gecko/ProfilerIOInterposeObserver.cpp rename : tools/profiler/ProfilerIOInterposeObserver.h => tools/profiler/gecko/ProfilerIOInterposeObserver.h rename : tools/profiler/SaveProfileTask.cpp => tools/profiler/gecko/SaveProfileTask.cpp rename : tools/profiler/SaveProfileTask.h => tools/profiler/gecko/SaveProfileTask.h rename : tools/profiler/ThreadResponsiveness.cpp => tools/profiler/gecko/ThreadResponsiveness.cpp rename : tools/profiler/ThreadResponsiveness.h => tools/profiler/gecko/ThreadResponsiveness.h rename : tools/profiler/local_debug_info_symbolizer.cc => tools/profiler/gecko/local_debug_info_symbolizer.cc rename : tools/profiler/local_debug_info_symbolizer.h => tools/profiler/gecko/local_debug_info_symbolizer.h rename : tools/profiler/nsIProfileSaveEvent.idl => tools/profiler/gecko/nsIProfileSaveEvent.idl rename : tools/profiler/nsIProfiler.idl => tools/profiler/gecko/nsIProfiler.idl rename : tools/profiler/nsProfiler.cpp => tools/profiler/gecko/nsProfiler.cpp rename : tools/profiler/nsProfiler.h => tools/profiler/gecko/nsProfiler.h rename : tools/profiler/nsProfilerCIID.h => tools/profiler/gecko/nsProfilerCIID.h rename : tools/profiler/nsProfilerFactory.cpp => tools/profiler/gecko/nsProfilerFactory.cpp rename : tools/profiler/nsProfilerStartParams.cpp => tools/profiler/gecko/nsProfilerStartParams.cpp rename : tools/profiler/nsProfilerStartParams.h => tools/profiler/gecko/nsProfilerStartParams.h rename : tools/profiler/AutoObjectMapper.cpp => tools/profiler/lul/AutoObjectMapper.cpp rename : tools/profiler/AutoObjectMapper.h => tools/profiler/lul/AutoObjectMapper.h rename : tools/profiler/LulCommon.cpp => tools/profiler/lul/LulCommon.cpp rename : tools/profiler/LulCommonExt.h => tools/profiler/lul/LulCommonExt.h rename : tools/profiler/LulDwarf.cpp => tools/profiler/lul/LulDwarf.cpp rename : tools/profiler/LulDwarfExt.h => tools/profiler/lul/LulDwarfExt.h rename : tools/profiler/LulDwarfInt.h => tools/profiler/lul/LulDwarfInt.h rename : tools/profiler/LulDwarfSummariser.cpp => tools/profiler/lul/LulDwarfSummariser.cpp rename : tools/profiler/LulDwarfSummariser.h => tools/profiler/lul/LulDwarfSummariser.h rename : tools/profiler/LulElf.cpp => tools/profiler/lul/LulElf.cpp rename : tools/profiler/LulElfExt.h => tools/profiler/lul/LulElfExt.h rename : tools/profiler/LulElfInt.h => tools/profiler/lul/LulElfInt.h rename : tools/profiler/LulMain.cpp => tools/profiler/lul/LulMain.cpp rename : tools/profiler/LulMain.h => tools/profiler/lul/LulMain.h rename : tools/profiler/LulMainInt.h => tools/profiler/lul/LulMainInt.h rename : tools/profiler/LulPlatformMacros.h => tools/profiler/lul/LulPlatformMacros.h rename : tools/profiler/platform-linux-lul.cpp => tools/profiler/lul/platform-linux-lul.cpp rename : tools/profiler/platform-linux-lul.h => tools/profiler/lul/platform-linux-lul.h rename : tools/profiler/GeckoProfiler.h => tools/profiler/public/GeckoProfiler.h rename : tools/profiler/GeckoProfilerFunc.h => tools/profiler/public/GeckoProfilerFunc.h rename : tools/profiler/GeckoProfilerImpl.h => tools/profiler/public/GeckoProfilerImpl.h rename : tools/profiler/ProfileGatherer.h => tools/profiler/public/ProfileGatherer.h rename : tools/profiler/ProfilerBacktrace.h => tools/profiler/public/ProfilerBacktrace.h rename : tools/profiler/ProfilerMarkers.h => tools/profiler/public/ProfilerMarkers.h rename : tools/profiler/PseudoStack.h => tools/profiler/public/PseudoStack.h rename : tools/profiler/shared-libraries.h => tools/profiler/public/shared-libraries.h rename : tools/profiler/GeckoTaskTracer.cpp => tools/profiler/tasktracer/GeckoTaskTracer.cpp rename : tools/profiler/GeckoTaskTracer.h => tools/profiler/tasktracer/GeckoTaskTracer.h rename : tools/profiler/GeckoTaskTracerImpl.h => tools/profiler/tasktracer/GeckoTaskTracerImpl.h rename : tools/profiler/SourceEventTypeMap.h => tools/profiler/tasktracer/SourceEventTypeMap.h rename : tools/profiler/TracedTaskCommon.cpp => tools/profiler/tasktracer/TracedTaskCommon.cpp rename : tools/profiler/TracedTaskCommon.h => tools/profiler/tasktracer/TracedTaskCommon.h extra : commitid : EGgqHIgsN6z
2015-06-30 22:03:45 +03:00
#include <unistd.h>
#include <sys/syscall.h>
static inline pid_t gettid()
{
return (pid_t) syscall(SYS_gettid);
}
#elif defined(GP_OS_darwin)
#include <unistd.h>
#include <sys/syscall.h>
static inline pid_t gettid()
{
return (pid_t) syscall(SYS_thread_selfid);
}
#elif defined(GP_OS_android)
#include <unistd.h>
#elif defined(GP_OS_windows)
#include <windows.h>
#include <process.h>
#ifndef getpid
#define getpid _getpid
#endif
#endif
extern mozilla::LazyLogModule gProfilerLog;
// These are for MOZ_LOG="prof:3" or higher. It's the default logging level for
// the profiler, and should be used sparingly.
#define LOG_TEST \
MOZ_LOG_TEST(gProfilerLog, mozilla::LogLevel::Info)
#define LOG(arg, ...) \
MOZ_LOG(gProfilerLog, mozilla::LogLevel::Info, \
("[%d] " arg, getpid(), ##__VA_ARGS__))
// These are for MOZ_LOG="prof:4" or higher. It should be used for logging that
// is somewhat more verbose than LOG.
#define DEBUG_LOG_TEST \
MOZ_LOG_TEST(gProfilerLog, mozilla::LogLevel::Debug)
#define DEBUG_LOG(arg, ...) \
MOZ_LOG(gProfilerLog, mozilla::LogLevel::Debug, \
("[%d] " arg, getpid(), ##__VA_ARGS__))
typedef uint8_t* Address;
// ----------------------------------------------------------------------------
// Thread
//
// This class has static methods for the different platform specific
// functions. Add methods here to cope with differences between the
// supported platforms.
class Thread {
public:
static int GetCurrentId();
};
// ----------------------------------------------------------------------------
// Miscellaneous
Bug 1335595 (part 4) - Merge ThreadProfile into ThreadInfo. r=mstange. ThreadInfo and ThreadProfile are hopelessly intertwined. - ThreadInfo has an owning pointer to ThreadProfile. ThreadProfile has a raw back pointer to ThreadInfo. A reference to one is as good as a reference to the other, and references to one frequently reach into the other. - An exception is SyncProfile, a sub-class of ThreadProfile, which instead has an owning pointer to its ThreadInfo. (This makes the SyncProfile's destructor dubious, because it deletes the ThreadInfo, which could conceivably re-call into SyncProfile's destructor.) - ThreadProfile also has copies of five ThreadInfo fields (mThreadId, mIsMainThread, mPlatformData, mStackTop, mPseudoStack) even though it also has direct ThreadInfo access via the back pointer. The only good reason for having the two classes separate is that some ThreadInfo objects have a null ThreadProfile pointer. But this doesn't justify the entanglement. So this patch merges ThreadProfile into ThreadInfo. It visually separates the methods and fields related to profiles to partially preserve the original meaning of the split. The new ThreadInfo::hasProfile() method replaces ThreadInfo::Profile() as the indicator of whether a ThreadInfo has associated profile data. Notable points of simplification: - The five duplicated fields are no longer duplicated. - NewSyncProfile(), RegisterThread() no longer create ThreadProfile objects. - ~SyncProfile() becomes trivial. - ThreadInfo::SetPendingDelete() is simpler. - Overall it removes ~80 lines of code. Much of the rest is just plumbing changes. --HG-- extra : rebase_source : 2e8c4cc46aa15943ffdc1fa19d9c829587267ee9
2017-02-02 03:07:13 +03:00
class PlatformData;
// We can't new/delete the type safely without defining it
// (-Wdelete-incomplete). Use these to hide the details from clients.
struct PlatformDataDestructor {
void operator()(PlatformData*);
};
typedef mozilla::UniquePtr<PlatformData, PlatformDataDestructor>
UniquePlatformData;
UniquePlatformData AllocPlatformData(int aThreadId);
Bug 1329111 - Change the nsIProfiler shared library information API. r=njn API before this change: - nsIProfiler::getSharedLibraryInformation() returns a string containing a JSON array of libraries. - The profile format is at version 3. - Every profile has a "libs" field that contains the same JSON string as the return value of nsIProfiler::getSharedLibraryInformation. - The array of libraries is not sorted. - Each library has a "name" field that contains: - The module's debug name on Windows - The full path to the binary on Mac + Linux API after this change: - nsIProfiler::getSharedLibraryInformation() is removed. - nsIProfiler has a readonly property called sharedLibraries. - The profile format is at version 4. - Every profile has a "libs" field that contains the same array as nsIProfiler.sharedLibraries, no longer as a JSON string but as a regular array. - The array of libraries is sorted by start address. - Each library has a "name" field that contains the binary file's basename, on all platforms. - Each library has a "path" field that contains the full path to the binary, on all platforms. - Each library has a "debugName" field that contains the library's debug name, on all platforms. On Windows, the debug name is the filename (basename) of the pdb file for that binary. On other platforms, debugName is the same as |name|. - Each library has a "debugPath" field that contains the absolute path library's pdb file on Windows; on non-Windows, debugPath and path are the same. - Each library has an "arch" field that is either an empty string (Linux + Windows) or the library's architecture; it'll differentiate between the architectures "x86_64" and "x86_64h". (x86_64h is used for binaries that contain instructions that are specific to the Intel Haswell microarchitecture.) MozReview-Commit-ID: 8Nrs4dyHhDS --HG-- extra : rebase_source : 4039926ae4d776bf53ea71df5fe3f8200d3e2784 extra : source : 4e282aa03422de5b8d51e1aaeb3e53ee547293dd
2017-03-15 01:59:20 +03:00
namespace mozilla {
class JSONWriter;
}
void AppendSharedLibraries(mozilla::JSONWriter& aWriter);
// Convert the array of strings to a bitfield.
uint32_t ParseFeaturesFromStringArray(const char** aFeatures,
uint32_t aFeatureCount);
#endif /* ndef TOOLS_PLATFORM_H_ */