2017-01-05 23:41:09 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-26 01:57:28 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-05-27 16:29:24 +04:00
|
|
|
#include <ostream>
|
2013-03-26 01:57:28 +04:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
#include "PlatformMacros.h"
|
2015-01-15 03:05:25 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2015-06-18 08:05:42 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2017-02-07 07:22:27 +03:00
|
|
|
#include "mozilla/Vector.h"
|
2015-06-18 08:05:42 +03:00
|
|
|
#include "GeckoProfiler.h"
|
|
|
|
#include "ProfilerIOInterposeObserver.h"
|
2013-09-12 18:47:37 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "mozilla/ThreadLocal.h"
|
2015-06-17 05:28:00 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2016-10-04 18:57:51 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2017-02-07 06:24:39 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "PseudoStack.h"
|
2017-02-07 08:09:39 +03:00
|
|
|
#include "ThreadInfo.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2015-06-18 08:05:42 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2014-11-18 20:50:25 +03:00
|
|
|
#include "nsProfilerStartParams.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "mozilla/Services.h"
|
2013-03-29 23:34:49 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2017-02-07 06:24:39 +03:00
|
|
|
#include "mozilla/ProfileGatherer.h"
|
2013-07-11 08:27:04 +04:00
|
|
|
#include "ProfilerMarkers.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2015-12-19 00:12:47 +03:00
|
|
|
#ifdef MOZ_TASK_TRACER
|
|
|
|
#include "GeckoTaskTracer.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-23 22:33:38 +04:00
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
2016-09-21 00:42:08 +03:00
|
|
|
#include "FennecJNIWrappers.h"
|
2013-04-23 21:10:29 +04:00
|
|
|
#endif
|
|
|
|
|
2015-09-18 00:17:26 +03:00
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
2016-09-21 00:42:08 +03:00
|
|
|
#include "FennecJNINatives.h"
|
2015-09-18 00:17:26 +03:00
|
|
|
#endif
|
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
#if defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux)
|
|
|
|
# define USE_LUL_STACKWALK
|
2015-06-30 22:03:45 +03:00
|
|
|
# include "lul/LulMain.h"
|
|
|
|
# include "lul/platform-linux-lul.h"
|
2015-04-15 13:24:38 +03:00
|
|
|
#endif
|
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-09-18 00:17:26 +03:00
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
2017-02-07 06:15:30 +03:00
|
|
|
class GeckoJavaSampler : public mozilla::java::GeckoJavaSampler::Natives<GeckoJavaSampler>
|
2015-09-18 00:17:26 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
GeckoJavaSampler();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static double GetProfilerTime() {
|
|
|
|
if (!profiler_is_active()) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
return profiler_time();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-11-23 22:11:22 +03:00
|
|
|
MOZ_THREAD_LOCAL(PseudoStack *) tlsPseudoStack;
|
2017-02-07 09:27:54 +03:00
|
|
|
|
|
|
|
static Sampler* gSampler;
|
2017-01-25 08:00:47 +03:00
|
|
|
|
2017-02-07 06:16:26 +03:00
|
|
|
static std::vector<ThreadInfo*>* sRegisteredThreads = nullptr;
|
|
|
|
static mozilla::StaticMutex sRegisteredThreadsMutex;
|
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
// All accesses to gGatherer are on the main thread, so no locking is needed.
|
|
|
|
static mozilla::StaticRefPtr<mozilla::ProfileGatherer> gGatherer;
|
|
|
|
|
2017-02-07 07:22:27 +03:00
|
|
|
// gThreadNameFilters is accessed from multiple threads. All accesses to it
|
|
|
|
// must be guarded by gThreadNameFiltersMutex.
|
|
|
|
static Vector<std::string> gThreadNameFilters;
|
|
|
|
static mozilla::StaticMutex gThreadNameFiltersMutex;
|
|
|
|
|
|
|
|
// All accesses to gFeatures are on the main thread, so no locking is needed.
|
|
|
|
static Vector<std::string> gFeatures;
|
|
|
|
|
2017-02-07 07:22:52 +03:00
|
|
|
// All accesses to gEntrySize are on the main thread, so no locking is needed.
|
|
|
|
static int gEntrySize = 0;
|
|
|
|
|
2017-02-08 01:06:16 +03:00
|
|
|
// This variable is set on the main thread in profiler_{start,stop}(), and
|
|
|
|
// mostly read on the main thread. There is one read off the main thread in
|
|
|
|
// SignalSender() in platform-linux.cc which is safe because there is implicit
|
|
|
|
// synchronization between that function and the set points in
|
|
|
|
// profiler_{start,stop}().
|
|
|
|
static double gInterval = 0;
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// We need to track whether we've been initialized otherwise
|
|
|
|
// we end up using tlsStack without initializing it.
|
|
|
|
// Because tlsStack is totally opaque to us we can't reuse
|
|
|
|
// it as the flag itself.
|
|
|
|
bool stack_key_initialized;
|
|
|
|
|
2017-02-06 06:30:33 +03:00
|
|
|
// XXX: This is set by profiler_init() and profiler_start() on the main thread.
|
|
|
|
// It is read off the main thread, e.g. by InplaceTick(). It might require more
|
|
|
|
// inter-thread synchronization than it currently has.
|
|
|
|
mozilla::TimeStamp sStartTime;
|
|
|
|
|
2017-02-07 07:56:48 +03:00
|
|
|
// XXX: These are accessed by multiple threads and might require more
|
|
|
|
// inter-thread synchronization than they currently have.
|
|
|
|
static int gFrameNumber = 0;
|
|
|
|
static int gLastFrameNumber = 0;
|
|
|
|
|
|
|
|
int sInitCount = 0; // Each init must have a matched shutdown.
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
static bool sIsProfiling = false; // is raced on
|
2014-05-24 20:14:14 +04:00
|
|
|
static bool sIsGPUProfiling = false; // is raced on
|
2014-12-13 00:11:57 +03:00
|
|
|
static bool sIsLayersDump = false; // is raced on
|
2014-12-13 23:40:18 +03:00
|
|
|
static bool sIsDisplayListDump = false; // is raced on
|
2015-03-19 04:19:00 +03:00
|
|
|
static bool sIsRestyleProfiling = false; // is raced on
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
// Environment variables to control the profiler
|
|
|
|
const char* PROFILER_HELP = "MOZ_PROFILER_HELP";
|
2013-10-25 04:09:33 +04:00
|
|
|
const char* PROFILER_INTERVAL = "MOZ_PROFILER_INTERVAL";
|
|
|
|
const char* PROFILER_ENTRIES = "MOZ_PROFILER_ENTRIES";
|
|
|
|
const char* PROFILER_STACK = "MOZ_PROFILER_STACK_SCAN";
|
|
|
|
const char* PROFILER_FEATURES = "MOZ_PROFILING_FEATURES";
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
/* we don't need to worry about overflow because we only treat the
|
|
|
|
* case of them being the same as special. i.e. we only run into
|
|
|
|
* a problem if 2^32 events happen between samples that we need
|
|
|
|
* to know are associated with different events */
|
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
// Values harvested from env vars, that control the profiler.
|
|
|
|
static int sUnwindInterval; /* in milliseconds */
|
|
|
|
static int sUnwindStackScan; /* max # of dubious frames allowed */
|
|
|
|
static int sProfileEntries; /* how many entries do we store? */
|
|
|
|
|
2013-09-12 18:47:37 +04:00
|
|
|
static mozilla::StaticAutoPtr<mozilla::ProfilerIOInterposeObserver>
|
|
|
|
sInterposeObserver;
|
2013-06-14 22:01:02 +04:00
|
|
|
|
2013-10-22 17:30:06 +04:00
|
|
|
// The name that identifies the gecko thread for calls to
|
2015-04-23 22:10:30 +03:00
|
|
|
// profiler_register_thread.
|
2013-10-22 17:30:06 +04:00
|
|
|
static const char * gGeckoThreadName = "GeckoMain";
|
|
|
|
|
2013-07-11 08:27:04 +04:00
|
|
|
ProfilerMarker::ProfilerMarker(const char* aMarkerName,
|
2015-06-17 05:28:00 +03:00
|
|
|
ProfilerMarkerPayload* aPayload,
|
|
|
|
double aTime)
|
2013-07-11 08:27:04 +04:00
|
|
|
: mMarkerName(strdup(aMarkerName))
|
|
|
|
, mPayload(aPayload)
|
2014-02-25 19:40:45 +04:00
|
|
|
, mTime(aTime)
|
2013-07-11 08:27:04 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfilerMarker::~ProfilerMarker() {
|
|
|
|
free(mMarkerName);
|
|
|
|
delete mPayload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-28 11:21:04 +03:00
|
|
|
ProfilerMarker::SetGeneration(uint32_t aGenID) {
|
2013-07-11 08:27:04 +04:00
|
|
|
mGenID = aGenID;
|
|
|
|
}
|
|
|
|
|
2015-06-17 05:28:00 +03:00
|
|
|
double
|
2015-04-26 01:56:03 +03:00
|
|
|
ProfilerMarker::GetTime() const {
|
2014-02-25 19:40:45 +04:00
|
|
|
return mTime;
|
|
|
|
}
|
|
|
|
|
2015-05-12 00:16:44 +03:00
|
|
|
void ProfilerMarker::StreamJSON(SpliceableJSONWriter& aWriter,
|
|
|
|
UniqueStacks& aUniqueStacks) const
|
|
|
|
{
|
|
|
|
// Schema:
|
|
|
|
// [name, time, data]
|
|
|
|
|
|
|
|
aWriter.StartArrayElement();
|
|
|
|
{
|
|
|
|
aUniqueStacks.mUniqueStrings.WriteElement(aWriter, GetMarkerName());
|
|
|
|
aWriter.DoubleElement(mTime);
|
2014-04-22 00:48:47 +04:00
|
|
|
// TODO: Store the callsite for this marker if available:
|
|
|
|
// if have location data
|
|
|
|
// b.NameValue(marker, "location", ...);
|
|
|
|
if (mPayload) {
|
2015-05-12 00:16:44 +03:00
|
|
|
aWriter.StartObjectElement();
|
|
|
|
{
|
|
|
|
mPayload->StreamPayload(aWriter, aUniqueStacks);
|
|
|
|
}
|
|
|
|
aWriter.EndObject();
|
2014-04-22 00:48:47 +04:00
|
|
|
}
|
2015-05-12 00:16:44 +03:00
|
|
|
}
|
|
|
|
aWriter.EndArray();
|
2013-07-11 08:27:04 +04:00
|
|
|
}
|
|
|
|
|
2013-04-06 12:45:30 +04:00
|
|
|
/* Has MOZ_PROFILER_VERBOSE been set? */
|
2015-04-15 13:24:38 +03:00
|
|
|
|
|
|
|
// Verbosity control for the profiler. The aim is to check env var
|
|
|
|
// MOZ_PROFILER_VERBOSE only once. However, we may need to temporarily
|
|
|
|
// override that so as to print the profiler's help message. That's
|
2017-01-21 00:45:49 +03:00
|
|
|
// what profiler_set_verbosity is for.
|
2015-04-15 13:24:38 +03:00
|
|
|
|
|
|
|
enum class ProfilerVerbosity : int8_t { UNCHECKED, NOTVERBOSE, VERBOSE };
|
|
|
|
|
|
|
|
// Raced on, potentially
|
|
|
|
static ProfilerVerbosity profiler_verbosity = ProfilerVerbosity::UNCHECKED;
|
|
|
|
|
2017-01-21 00:45:49 +03:00
|
|
|
bool profiler_verbose()
|
2013-04-06 12:45:30 +04:00
|
|
|
{
|
2015-04-15 13:24:38 +03:00
|
|
|
if (profiler_verbosity == ProfilerVerbosity::UNCHECKED) {
|
2015-06-18 08:05:42 +03:00
|
|
|
if (getenv("MOZ_PROFILER_VERBOSE") != nullptr)
|
2015-04-15 13:24:38 +03:00
|
|
|
profiler_verbosity = ProfilerVerbosity::VERBOSE;
|
2013-04-06 12:45:30 +04:00
|
|
|
else
|
2015-04-15 13:24:38 +03:00
|
|
|
profiler_verbosity = ProfilerVerbosity::NOTVERBOSE;
|
2013-04-06 12:45:30 +04:00
|
|
|
}
|
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
return profiler_verbosity == ProfilerVerbosity::VERBOSE;
|
2013-04-06 12:45:30 +04:00
|
|
|
}
|
|
|
|
|
2017-01-21 00:45:49 +03:00
|
|
|
void profiler_set_verbosity(ProfilerVerbosity pv)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2015-04-15 13:24:38 +03:00
|
|
|
MOZ_ASSERT(pv == ProfilerVerbosity::UNCHECKED ||
|
|
|
|
pv == ProfilerVerbosity::VERBOSE);
|
|
|
|
profiler_verbosity = pv;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 04:09:33 +04:00
|
|
|
|
|
|
|
bool set_profiler_interval(const char* interval) {
|
|
|
|
if (interval) {
|
2013-03-26 01:57:28 +04:00
|
|
|
errno = 0;
|
2013-11-11 23:16:31 +04:00
|
|
|
long int n = strtol(interval, (char**)nullptr, 10);
|
2013-03-26 01:57:28 +04:00
|
|
|
if (errno == 0 && n >= 1 && n <= 1000) {
|
|
|
|
sUnwindInterval = n;
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
2013-10-25 04:09:33 +04:00
|
|
|
return false;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_profiler_entries(const char* entries) {
|
|
|
|
if (entries) {
|
2013-08-05 20:03:22 +04:00
|
|
|
errno = 0;
|
2013-11-11 23:16:31 +04:00
|
|
|
long int n = strtol(entries, (char**)nullptr, 10);
|
2013-08-05 20:03:22 +04:00
|
|
|
if (errno == 0 && n > 0) {
|
|
|
|
sProfileEntries = n;
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
2013-08-05 20:03:22 +04:00
|
|
|
}
|
2013-10-25 04:09:33 +04:00
|
|
|
return false;
|
2013-08-05 20:03:22 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_profiler_scan(const char* scanCount) {
|
|
|
|
if (scanCount) {
|
2013-04-06 12:49:11 +04:00
|
|
|
errno = 0;
|
2013-11-11 23:16:31 +04:00
|
|
|
long int n = strtol(scanCount, (char**)nullptr, 10);
|
2013-04-06 12:49:11 +04:00
|
|
|
if (errno == 0 && n >= 0 && n <= 100) {
|
|
|
|
sUnwindStackScan = n;
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
2013-04-06 12:49:11 +04:00
|
|
|
}
|
2013-10-25 04:09:33 +04:00
|
|
|
return false;
|
2013-04-06 12:49:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 04:09:33 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_native_unwinding_avail() {
|
|
|
|
# if defined(HAVE_NATIVE_UNWIND)
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
// Read env vars at startup, so as to set:
|
|
|
|
// sUnwindInterval, sProfileEntries, sUnwindStackScan.
|
2013-10-25 04:09:33 +04:00
|
|
|
void read_profiler_env_vars()
|
|
|
|
{
|
|
|
|
/* Set defaults */
|
|
|
|
sUnwindInterval = 0; /* We'll have to look elsewhere */
|
|
|
|
sProfileEntries = 0;
|
|
|
|
|
2015-06-18 08:05:42 +03:00
|
|
|
const char* interval = getenv(PROFILER_INTERVAL);
|
|
|
|
const char* entries = getenv(PROFILER_ENTRIES);
|
|
|
|
const char* scanCount = getenv(PROFILER_STACK);
|
2013-10-25 04:09:33 +04:00
|
|
|
|
2015-06-18 08:05:42 +03:00
|
|
|
if (getenv(PROFILER_HELP)) {
|
2015-04-15 13:24:38 +03:00
|
|
|
// Enable verbose output
|
2017-01-21 00:45:49 +03:00
|
|
|
profiler_set_verbosity(ProfilerVerbosity::VERBOSE);
|
2015-04-15 13:24:38 +03:00
|
|
|
profiler_usage();
|
2017-01-21 00:45:49 +03:00
|
|
|
// Now force the next enquiry of profiler_verbose to re-query
|
2015-04-15 13:24:38 +03:00
|
|
|
// env var MOZ_PROFILER_VERBOSE.
|
2017-01-21 00:45:49 +03:00
|
|
|
profiler_set_verbosity(ProfilerVerbosity::UNCHECKED);
|
2015-04-15 13:24:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_profiler_interval(interval) ||
|
2013-10-25 04:09:33 +04:00
|
|
|
!set_profiler_entries(entries) ||
|
|
|
|
!set_profiler_scan(scanCount)) {
|
|
|
|
profiler_usage();
|
|
|
|
} else {
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler:");
|
|
|
|
LOGF("Profiler: Sampling interval = %d ms (zero means \"platform default\")",
|
2013-10-25 04:09:33 +04:00
|
|
|
(int)sUnwindInterval);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOGF("Profiler: Entry store size = %d (zero means \"platform default\")",
|
2013-10-25 04:09:33 +04:00
|
|
|
(int)sProfileEntries);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOGF("Profiler: UnwindStackScan = %d (max dubious frames per unwind).",
|
2013-10-25 04:09:33 +04:00
|
|
|
(int)sUnwindStackScan);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler:");
|
2013-10-25 04:09:33 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2013-10-25 04:09:33 +04:00
|
|
|
void profiler_usage() {
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: Environment variable usage:");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_HELP");
|
|
|
|
LOG( "Profiler: If set to any value, prints this message.");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_INTERVAL=<number> (milliseconds, 1 to 1000)");
|
|
|
|
LOG( "Profiler: If unset, platform default is used.");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_ENTRIES=<number> (count, minimum of 1)");
|
|
|
|
LOG( "Profiler: If unset, platform default is used.");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_VERBOSE");
|
|
|
|
LOG( "Profiler: If set to any value, increases verbosity (recommended).");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_STACK_SCAN=<number> (default is zero)");
|
|
|
|
LOG( "Profiler: The number of dubious (stack-scanned) frames allowed");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOG( "Profiler: MOZ_PROFILER_LUL_TEST");
|
|
|
|
LOG( "Profiler: If set to any value, runs LUL unit tests at startup of");
|
|
|
|
LOG( "Profiler: the unwinder thread, and prints a short summary of results.");
|
|
|
|
LOG( "Profiler: ");
|
|
|
|
LOGF("Profiler: This platform %s native unwinding.",
|
2013-10-25 04:09:33 +04:00
|
|
|
is_native_unwinding_avail() ? "supports" : "does not support");
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler: ");
|
2013-10-25 04:09:33 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
/* Re-set defaults */
|
|
|
|
sUnwindInterval = 0; /* We'll have to look elsewhere */
|
2013-08-05 20:03:22 +04:00
|
|
|
sProfileEntries = 0;
|
2013-04-06 12:49:11 +04:00
|
|
|
sUnwindStackScan = 0;
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler:");
|
|
|
|
LOGF("Profiler: Sampling interval = %d ms (zero means \"platform default\")",
|
2013-03-26 01:57:28 +04:00
|
|
|
(int)sUnwindInterval);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOGF("Profiler: Entry store size = %d (zero means \"platform default\")",
|
2013-08-05 20:03:22 +04:00
|
|
|
(int)sProfileEntries);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOGF("Profiler: UnwindStackScan = %d (max dubious frames per unwind).",
|
2013-04-06 12:49:11 +04:00
|
|
|
(int)sUnwindStackScan);
|
2017-01-24 06:17:13 +03:00
|
|
|
LOG( "Profiler:");
|
2013-03-26 01:57:28 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-22 17:30:06 +04:00
|
|
|
bool is_main_thread_name(const char* aName) {
|
2013-11-04 22:27:40 +04:00
|
|
|
if (!aName) {
|
2013-10-22 17:30:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return strcmp(aName, gGeckoThreadName) == 0;
|
|
|
|
}
|
|
|
|
|
2014-05-02 06:05:49 +04:00
|
|
|
#ifdef HAVE_VA_COPY
|
|
|
|
#define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar)
|
|
|
|
#elif defined(HAVE_VA_LIST_AS_ARRAY)
|
|
|
|
#define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0]
|
|
|
|
#else
|
|
|
|
#define VARARGS_ASSIGN(foo, bar) (foo) = (bar)
|
|
|
|
#endif
|
|
|
|
|
2014-12-18 21:32:53 +03:00
|
|
|
void
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
profiler_log(const char* str)
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
profiler_tracing("log", str, TRACING_EVENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
profiler_log(const char* fmt, va_list args)
|
2014-05-02 06:05:49 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2014-05-02 06:05:49 +04:00
|
|
|
if (profiler_is_active()) {
|
|
|
|
// nsAutoCString AppendPrintf would be nicer but
|
|
|
|
// this is mozilla external code
|
|
|
|
char buf[2048];
|
|
|
|
va_list argsCpy;
|
|
|
|
VARARGS_ASSIGN(argsCpy, args);
|
2016-10-04 18:57:51 +03:00
|
|
|
int required = VsprintfLiteral(buf, fmt, argsCpy);
|
2014-05-02 06:05:49 +04:00
|
|
|
va_end(argsCpy);
|
|
|
|
|
|
|
|
if (required < 0) {
|
|
|
|
return; // silently drop for now
|
|
|
|
} else if (required < 2048) {
|
|
|
|
profiler_tracing("log", buf, TRACING_EVENT);
|
|
|
|
} else {
|
|
|
|
char* heapBuf = new char[required+1];
|
|
|
|
va_list argsCpy;
|
|
|
|
VARARGS_ASSIGN(argsCpy, args);
|
|
|
|
vsnprintf(heapBuf, required+1, fmt, argsCpy);
|
|
|
|
va_end(argsCpy);
|
|
|
|
// EVENT_BACKTRACE could be used to get a source
|
|
|
|
// for all log events. This could be a runtime
|
|
|
|
// flag later.
|
|
|
|
profiler_tracing("log", heapBuf, TRACING_EVENT);
|
|
|
|
delete[] heapBuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// BEGIN externally visible functions
|
|
|
|
|
2017-01-30 04:37:26 +03:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(GeckoProfilerMallocSizeOf);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GeckoProfilerReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (gSampler) {
|
|
|
|
size_t n = gSampler->SizeOfIncludingThis(GeckoProfilerMallocSizeOf);
|
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/profiler/sampler", KIND_HEAP, UNITS_BYTES, n,
|
|
|
|
"Memory used by the Gecko Profiler's Sampler object.");
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(USE_LUL_STACKWALK)
|
|
|
|
{
|
|
|
|
size_t n = sLUL ? sLUL->SizeOfIncludingThis(GeckoProfilerMallocSizeOf) : 0;
|
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/profiler/lul", KIND_HEAP, UNITS_BYTES, n,
|
|
|
|
"Memory used by LUL, a stack unwinder used by the Gecko Profiler.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(GeckoProfilerReporter, nsIMemoryReporter)
|
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
static void
|
|
|
|
RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack,
|
|
|
|
bool aIsMainThread, void* stackTop)
|
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
if (!sRegisteredThreads) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread::tid_t id = Thread::GetCurrentId();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = sRegisteredThreads->at(i);
|
|
|
|
if (info->ThreadId() == id && !info->IsPendingDelete()) {
|
|
|
|
// Thread already registered. This means the first unregister will be
|
|
|
|
// too early.
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadInfo* info =
|
|
|
|
new ThreadInfo(aName, id, aIsMainThread, aPseudoStack, stackTop);
|
|
|
|
|
|
|
|
// XXX: this is an off-main-thread use of gSampler
|
|
|
|
if (gSampler) {
|
|
|
|
gSampler->RegisterThread(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
sRegisteredThreads->push_back(info);
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_init(void* stackTop)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-04-18 19:34:49 +04:00
|
|
|
sInitCount++;
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
if (stack_key_initialized)
|
|
|
|
return;
|
|
|
|
|
2015-12-19 00:12:47 +03:00
|
|
|
#ifdef MOZ_TASK_TRACER
|
|
|
|
mozilla::tasktracer::InitTaskTracer();
|
|
|
|
#endif
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("BEGIN profiler_init");
|
2017-01-25 08:00:47 +03:00
|
|
|
if (!tlsPseudoStack.init()) {
|
2013-03-26 01:57:28 +04:00
|
|
|
LOG("Failed to init.");
|
|
|
|
return;
|
|
|
|
}
|
2015-06-17 05:28:00 +03:00
|
|
|
bool ignore;
|
|
|
|
sStartTime = mozilla::TimeStamp::ProcessCreation(ignore);
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
stack_key_initialized = true;
|
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
sRegisteredThreads = new std::vector<ThreadInfo*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// (Linux-only) We could create the sLUL object and read unwind info into it
|
|
|
|
// at this point. That would match the lifetime implied by destruction of it
|
|
|
|
// in profiler_shutdown() just below. However, that gives a big delay on
|
|
|
|
// startup, even if no profiling is actually to be done. So, instead, sLUL is
|
|
|
|
// created on demand at the first call to Sampler::Start.
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2017-02-03 02:34:35 +03:00
|
|
|
PseudoStack* stack = new PseudoStack();
|
2013-03-26 01:57:28 +04:00
|
|
|
tlsPseudoStack.set(stack);
|
|
|
|
|
2013-10-22 17:30:06 +04:00
|
|
|
bool isMainThread = true;
|
2017-02-07 06:24:33 +03:00
|
|
|
RegisterCurrentThread(gGeckoThreadName, stack, isMainThread, stackTop);
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2015-04-15 13:24:38 +03:00
|
|
|
// Read interval settings from MOZ_PROFILER_INTERVAL and stack-scan
|
|
|
|
// threshhold from MOZ_PROFILER_STACK_SCAN.
|
2013-04-01 23:45:03 +04:00
|
|
|
read_profiler_env_vars();
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2014-03-13 00:32:40 +04:00
|
|
|
// platform specific initialization
|
|
|
|
OS::Startup();
|
2013-03-26 01:57:28 +04:00
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
set_stderr_callback(profiler_log);
|
2014-05-02 06:05:49 +04:00
|
|
|
|
2015-09-18 00:17:26 +03:00
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
2016-09-29 06:49:25 +03:00
|
|
|
if (mozilla::jni::IsFennec()) {
|
2015-09-18 00:17:26 +03:00
|
|
|
GeckoJavaSampler::Init();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// We can't open pref so we use an environment variable
|
|
|
|
// to know if we should trigger the profiler on startup
|
|
|
|
// NOTE: Default
|
2015-06-18 08:05:42 +03:00
|
|
|
const char *val = getenv("MOZ_PROFILER_STARTUP");
|
2013-03-26 01:57:28 +04:00
|
|
|
if (!val || !*val) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* features[] = {"js"
|
|
|
|
, "leaf"
|
2015-01-15 03:05:25 +03:00
|
|
|
, "threads"
|
2015-04-15 13:24:38 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) \
|
|
|
|
|| (defined(SPS_ARCH_arm) && defined(linux)) \
|
|
|
|
|| defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux)
|
2013-03-26 01:57:28 +04:00
|
|
|
, "stackwalk"
|
2013-07-10 00:34:44 +04:00
|
|
|
#endif
|
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
|
|
|
, "java"
|
2013-03-26 01:57:28 +04:00
|
|
|
#endif
|
|
|
|
};
|
2015-01-15 03:05:25 +03:00
|
|
|
|
|
|
|
const char* threadFilters[] = { "GeckoMain", "Compositor" };
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL,
|
2015-01-15 03:05:25 +03:00
|
|
|
features, MOZ_ARRAY_LENGTH(features),
|
|
|
|
threadFilters, MOZ_ARRAY_LENGTH(threadFilters));
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("END profiler_init");
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_shutdown()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-04-18 19:34:49 +04:00
|
|
|
sInitCount--;
|
|
|
|
|
|
|
|
if (sInitCount > 0)
|
|
|
|
return;
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// Save the profile on shutdown if requested.
|
2017-01-25 08:00:47 +03:00
|
|
|
if (gSampler) {
|
2015-06-18 08:05:42 +03:00
|
|
|
const char *val = getenv("MOZ_PROFILER_SHUTDOWN");
|
2013-03-26 01:57:28 +04:00
|
|
|
if (val) {
|
|
|
|
std::ofstream stream;
|
|
|
|
stream.open(val);
|
|
|
|
if (stream.is_open()) {
|
2017-01-25 08:00:47 +03:00
|
|
|
gSampler->ToStreamAsJSON(stream);
|
2013-03-26 01:57:28 +04:00
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler_stop();
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2014-05-02 06:05:49 +04:00
|
|
|
set_stderr_callback(nullptr);
|
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
while (sRegisteredThreads->size() > 0) {
|
|
|
|
delete sRegisteredThreads->back();
|
|
|
|
sRegisteredThreads->pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnregisterThread can be called after shutdown in XPCShell. Thus we need
|
|
|
|
// to point to null to ignore such a call after shutdown.
|
|
|
|
delete sRegisteredThreads;
|
|
|
|
sRegisteredThreads = nullptr;
|
|
|
|
}
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
#if defined(USE_LUL_STACKWALK)
|
|
|
|
// Delete the sLUL object, if it actually got created.
|
|
|
|
if (sLUL) {
|
|
|
|
delete sLUL;
|
|
|
|
sLUL = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We just destroyed all the ThreadInfos in sRegisteredThreads, so it is safe
|
|
|
|
// the delete the PseudoStack.
|
2017-02-03 02:34:35 +03:00
|
|
|
delete tlsPseudoStack.get();
|
2014-12-11 17:41:00 +03:00
|
|
|
tlsPseudoStack.set(nullptr);
|
2015-12-19 00:12:47 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_TASK_TRACER
|
|
|
|
mozilla::tasktracer::ShutdownTaskTracer();
|
|
|
|
#endif
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
mozilla::UniquePtr<char[]>
|
|
|
|
profiler_get_profile(double aSinceTime)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
2013-11-11 23:16:31 +04:00
|
|
|
return nullptr;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
return gSampler->ToJSON(aSinceTime);
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
JSObject*
|
|
|
|
profiler_get_profile_jsobject(JSContext *aCx, double aSinceTime)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
2013-11-11 23:16:31 +04:00
|
|
|
return nullptr;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
return gSampler->ToJSObject(aCx, aSinceTime);
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_get_profile_jsobject_async(double aSinceTime,
|
|
|
|
mozilla::dom::Promise* aPromise)
|
2015-06-11 00:58:30 +03:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
if (!gGatherer) {
|
2015-06-11 00:58:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
gGatherer->Start(aSinceTime, aPromise);
|
2015-06-11 00:58:30 +03:00
|
|
|
}
|
2015-08-11 21:26:09 +03:00
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_save_profile_to_file_async(double aSinceTime, const char* aFileName)
|
2016-11-18 21:48:00 +03:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-11-18 21:48:00 +03:00
|
|
|
nsCString filename(aFileName);
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction([=] () {
|
2017-02-07 06:24:39 +03:00
|
|
|
if (!gGatherer) {
|
2017-01-20 06:20:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-11-18 21:48:00 +03:00
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
gGatherer->Start(aSinceTime, filename);
|
2017-01-20 06:20:11 +03:00
|
|
|
}));
|
2016-11-18 21:48:00 +03:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_get_start_params(int* aEntrySize,
|
|
|
|
double* aInterval,
|
|
|
|
mozilla::Vector<const char*>* aFilters,
|
|
|
|
mozilla::Vector<const char*>* aFeatures)
|
2015-08-11 21:26:09 +03:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-08-11 21:26:09 +03:00
|
|
|
if (NS_WARN_IF(!aEntrySize) || NS_WARN_IF(!aInterval) ||
|
|
|
|
NS_WARN_IF(!aFilters) || NS_WARN_IF(!aFeatures)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-07 07:22:52 +03:00
|
|
|
*aEntrySize = gEntrySize;
|
2017-02-08 01:06:16 +03:00
|
|
|
*aInterval = gInterval;
|
2015-08-11 21:26:09 +03:00
|
|
|
|
2017-02-07 07:22:27 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(gThreadNameFiltersMutex);
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(aFilters->resize(gThreadNameFilters.length()));
|
|
|
|
for (uint32_t i = 0; i < gThreadNameFilters.length(); ++i) {
|
|
|
|
(*aFilters)[i] = gThreadNameFilters[i].c_str();
|
|
|
|
}
|
2015-08-11 21:26:09 +03:00
|
|
|
}
|
|
|
|
|
2017-02-07 07:22:27 +03:00
|
|
|
MOZ_ALWAYS_TRUE(aFeatures->resize(gFeatures.length()));
|
|
|
|
for (size_t i = 0; i < gFeatures.length(); ++i) {
|
|
|
|
(*aFeatures)[i] = gFeatures[i].c_str();
|
2015-08-11 21:26:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_get_gatherer(nsISupports** aRetVal)
|
2015-08-12 21:20:26 +03:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-08-12 21:20:26 +03:00
|
|
|
if (!aRetVal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!profiler_is_active())) {
|
|
|
|
*aRetVal = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
if (NS_WARN_IF(!gGatherer)) {
|
2015-08-12 21:20:26 +03:00
|
|
|
*aRetVal = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
NS_ADDREF(*aRetVal = gGatherer);
|
2015-08-12 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_save_profile_to_file(const char* aFilename)
|
2014-04-22 00:48:47 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
2014-04-22 00:48:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ofstream stream;
|
|
|
|
stream.open(aFilename);
|
|
|
|
if (stream.is_open()) {
|
2017-01-25 08:00:47 +03:00
|
|
|
gSampler->ToStreamAsJSON(stream);
|
2014-04-22 00:48:47 +04:00
|
|
|
stream.close();
|
|
|
|
LOGF("Saved to %s", aFilename);
|
|
|
|
} else {
|
|
|
|
LOG("Fail to open profile log file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
const char**
|
|
|
|
profiler_get_features()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function currently only used on the main thread, but that restriction
|
|
|
|
// (and this assertion) could be removed trivially because it doesn't touch
|
|
|
|
// data that requires locking.
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
static const char* features[] = {
|
|
|
|
#if defined(MOZ_PROFILING) && defined(HAVE_NATIVE_UNWIND)
|
2013-04-01 23:45:03 +04:00
|
|
|
// Walk the C++ stack.
|
2013-03-26 01:57:28 +04:00
|
|
|
"stackwalk",
|
|
|
|
#endif
|
2017-01-24 06:18:50 +03:00
|
|
|
#if defined(ENABLE_LEAF_DATA)
|
2013-04-01 23:45:03 +04:00
|
|
|
// Include the C++ leaf node if not stackwalking. DevTools
|
|
|
|
// profiler doesn't want the native addresses.
|
2013-03-26 01:57:28 +04:00
|
|
|
"leaf",
|
|
|
|
#endif
|
2013-04-01 23:45:03 +04:00
|
|
|
#if !defined(SPS_OS_windows)
|
|
|
|
// Use a seperate thread of walking the stack.
|
|
|
|
"unwinder",
|
|
|
|
#endif
|
2013-04-23 21:10:29 +04:00
|
|
|
"java",
|
2013-04-01 23:45:03 +04:00
|
|
|
// Only record samples during periods of bad responsiveness
|
2013-03-26 01:57:28 +04:00
|
|
|
"jank",
|
2013-04-01 23:45:03 +04:00
|
|
|
// Tell the JS engine to emmit pseudostack entries in the
|
|
|
|
// pro/epilogue.
|
2013-03-26 01:57:28 +04:00
|
|
|
"js",
|
2014-05-24 20:14:14 +04:00
|
|
|
// GPU Profiling (may not be supported by the GL)
|
|
|
|
"gpu",
|
2013-04-01 23:45:03 +04:00
|
|
|
// Profile the registered secondary threads.
|
2013-04-04 02:59:17 +04:00
|
|
|
"threads",
|
2013-06-14 20:42:10 +04:00
|
|
|
// Do not include user-identifiable information
|
|
|
|
"privacy",
|
2014-12-13 00:11:57 +03:00
|
|
|
// Dump the layer tree with the textures.
|
|
|
|
"layersdump",
|
2014-12-13 23:40:18 +03:00
|
|
|
// Dump the display list with the textures.
|
|
|
|
"displaylistdump",
|
2013-06-14 22:01:02 +04:00
|
|
|
// Add main thread I/O to the profile
|
|
|
|
"mainthreadio",
|
2014-05-19 22:31:31 +04:00
|
|
|
// Add RSS collection
|
|
|
|
"memory",
|
2014-10-14 06:56:44 +04:00
|
|
|
#ifdef MOZ_TASK_TRACER
|
|
|
|
// Start profiling with feature TaskTracer.
|
|
|
|
"tasktracer",
|
2013-10-08 18:05:25 +04:00
|
|
|
#endif
|
2013-11-11 23:16:31 +04:00
|
|
|
nullptr
|
2013-03-26 01:57:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_get_buffer_info_helper(uint32_t *aCurrentPosition,
|
|
|
|
uint32_t *aTotalSize,
|
|
|
|
uint32_t *aGeneration)
|
2015-04-22 22:36:43 +03:00
|
|
|
{
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
// This function is called by profiler_get_buffer_info(), which has already
|
|
|
|
// zeroed the outparams.
|
2015-04-22 22:36:43 +03:00
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-04-22 22:36:43 +03:00
|
|
|
if (!stack_key_initialized)
|
|
|
|
return;
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
if (!gSampler) {
|
2015-04-22 22:36:43 +03:00
|
|
|
return;
|
2017-01-25 08:00:47 +03:00
|
|
|
}
|
2015-04-22 22:36:43 +03:00
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
gSampler->GetBufferInfo(aCurrentPosition, aTotalSize, aGeneration);
|
2015-04-22 22:36:43 +03:00
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// Values are only honored on the first start
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_start(int aProfileEntries, double aInterval,
|
|
|
|
const char** aFeatures, uint32_t aFeatureCount,
|
|
|
|
const char** aThreadNameFilters, uint32_t aFilterCount)
|
2013-05-17 00:31:50 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("BEGIN profiler_start");
|
2013-12-18 16:02:34 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
if (!stack_key_initialized)
|
2013-11-11 23:16:31 +04:00
|
|
|
profiler_init(nullptr);
|
2013-03-26 01:57:28 +04:00
|
|
|
|
|
|
|
/* If the sampling interval was set using env vars, use that
|
|
|
|
in preference to anything else. */
|
|
|
|
if (sUnwindInterval > 0)
|
|
|
|
aInterval = sUnwindInterval;
|
|
|
|
|
2013-08-05 20:03:22 +04:00
|
|
|
/* If the entry count was set using env vars, use that, too: */
|
|
|
|
if (sProfileEntries > 0)
|
|
|
|
aProfileEntries = sProfileEntries;
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// Reset the current state if the profiler is running
|
|
|
|
profiler_stop();
|
|
|
|
|
2017-02-07 07:22:27 +03:00
|
|
|
// Deep copy aThreadNameFilters. Must happen before Sampler's constructor
|
|
|
|
// calls RegisterThread().
|
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(gThreadNameFiltersMutex);
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(gThreadNameFilters.resize(aFilterCount));
|
|
|
|
for (uint32_t i = 0; i < aFilterCount; ++i) {
|
|
|
|
gThreadNameFilters[i] = aThreadNameFilters[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deep copy aFeatures.
|
|
|
|
MOZ_ALWAYS_TRUE(gFeatures.resize(aFeatureCount));
|
|
|
|
for (uint32_t i = 0; i < aFeatureCount; ++i) {
|
|
|
|
gFeatures[i] = aFeatures[i];
|
|
|
|
}
|
|
|
|
|
2017-02-07 07:22:52 +03:00
|
|
|
gEntrySize = aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY;
|
2017-02-08 01:06:16 +03:00
|
|
|
gInterval = aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL;
|
|
|
|
gSampler = new Sampler(gEntrySize, aFeatures, aFeatureCount, aFilterCount);
|
2017-02-07 06:24:39 +03:00
|
|
|
gGatherer = new mozilla::ProfileGatherer(gSampler);
|
2013-04-01 23:45:03 +04:00
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
gSampler->Start();
|
|
|
|
if (gSampler->ProfileJS() || gSampler->InPrivacyMode()) {
|
2017-02-07 06:16:26 +03:00
|
|
|
mozilla::StaticMutexAutoLock lock(sRegisteredThreadsMutex);
|
2017-01-20 06:20:11 +03:00
|
|
|
|
2017-02-07 06:16:26 +03:00
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = (*sRegisteredThreads)[i];
|
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
|
|
|
if (info->IsPendingDelete() || !info->hasProfile()) {
|
2017-01-20 06:20:11 +03:00
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
info->Stack()->reinitializeOnResume();
|
2017-01-25 08:00:47 +03:00
|
|
|
if (gSampler->ProfileJS()) {
|
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
|
|
|
info->Stack()->enableJSSampling();
|
2017-01-20 06:20:11 +03:00
|
|
|
}
|
2017-01-25 08:00:47 +03:00
|
|
|
if (gSampler->InPrivacyMode()) {
|
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
|
|
|
info->Stack()->mPrivacyMode = true;
|
2017-01-20 06:20:11 +03:00
|
|
|
}
|
|
|
|
}
|
2013-04-04 02:59:17 +04:00
|
|
|
}
|
|
|
|
|
2013-04-23 22:33:38 +04:00
|
|
|
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
|
2017-01-25 08:00:47 +03:00
|
|
|
if (gSampler->ProfileJava()) {
|
2013-04-23 21:10:29 +04:00
|
|
|
int javaInterval = aInterval;
|
|
|
|
// Java sampling doesn't accuratly keep up with 1ms sampling
|
|
|
|
if (javaInterval < 10) {
|
|
|
|
aInterval = 10;
|
|
|
|
}
|
2017-02-07 06:15:30 +03:00
|
|
|
mozilla::java::GeckoJavaSampler::Start(javaInterval, 1000);
|
2013-04-23 21:10:29 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
if (gSampler->AddMainThreadIO()) {
|
2013-09-12 18:47:37 +04:00
|
|
|
if (!sInterposeObserver) {
|
|
|
|
// Lazily create IO interposer observer
|
|
|
|
sInterposeObserver = new mozilla::ProfilerIOInterposeObserver();
|
|
|
|
}
|
|
|
|
mozilla::IOInterposer::Register(mozilla::IOInterposeObserver::OpAll,
|
|
|
|
sInterposeObserver);
|
2013-06-14 22:01:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
sIsProfiling = true;
|
2017-01-25 08:00:47 +03:00
|
|
|
sIsGPUProfiling = gSampler->ProfileGPU();
|
|
|
|
sIsLayersDump = gSampler->LayersDump();
|
|
|
|
sIsDisplayListDump = gSampler->DisplayListDump();
|
|
|
|
sIsRestyleProfiling = gSampler->ProfileRestyle();
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2014-04-29 06:20:51 +04:00
|
|
|
if (Sampler::CanNotifyObservers()) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2014-11-18 20:50:25 +03:00
|
|
|
if (os) {
|
|
|
|
nsTArray<nsCString> featuresArray;
|
|
|
|
nsTArray<nsCString> threadNameFiltersArray;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aFeatureCount; ++i) {
|
|
|
|
featuresArray.AppendElement(aFeatures[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aFilterCount; ++i) {
|
|
|
|
threadNameFiltersArray.AppendElement(aThreadNameFilters[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProfilerStartParams> params =
|
|
|
|
new nsProfilerStartParams(aProfileEntries, aInterval, featuresArray,
|
|
|
|
threadNameFiltersArray);
|
|
|
|
|
|
|
|
os->NotifyObservers(params, "profiler-started", nullptr);
|
|
|
|
}
|
2014-04-29 06:20:51 +04:00
|
|
|
}
|
2013-12-18 16:02:34 +04:00
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("END profiler_start");
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_stop()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("BEGIN profiler_stop");
|
2013-12-18 16:02:34 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
if (!stack_key_initialized)
|
2014-12-11 17:41:00 +03:00
|
|
|
return;
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
if (!gSampler) {
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("END profiler_stop-early");
|
2013-03-26 01:57:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
bool disableJS = gSampler->ProfileJS();
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2017-02-07 07:22:27 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(gThreadNameFiltersMutex);
|
|
|
|
gThreadNameFilters.clear();
|
|
|
|
}
|
|
|
|
gFeatures.clear();
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
gSampler->Stop();
|
|
|
|
delete gSampler;
|
|
|
|
gSampler = nullptr;
|
2017-02-07 07:22:52 +03:00
|
|
|
gEntrySize = 0;
|
2017-02-08 01:06:16 +03:00
|
|
|
gInterval = 0;
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2017-02-07 06:24:39 +03:00
|
|
|
// Cancel any in-flight async profile gatherering requests.
|
|
|
|
gGatherer->Cancel();
|
|
|
|
gGatherer = nullptr;
|
|
|
|
|
2013-06-14 20:42:10 +04:00
|
|
|
if (disableJS) {
|
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
2017-02-01 07:40:55 +03:00
|
|
|
MOZ_ASSERT(stack != nullptr);
|
2013-03-26 01:57:28 +04:00
|
|
|
stack->disableJSSampling();
|
2013-06-14 20:42:10 +04:00
|
|
|
}
|
2013-03-26 01:57:28 +04:00
|
|
|
|
2013-09-12 18:47:37 +04:00
|
|
|
mozilla::IOInterposer::Unregister(mozilla::IOInterposeObserver::OpAll,
|
|
|
|
sInterposeObserver);
|
2014-03-15 02:35:01 +04:00
|
|
|
sInterposeObserver = nullptr;
|
2013-06-14 22:01:02 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
sIsProfiling = false;
|
2014-12-13 00:11:57 +03:00
|
|
|
sIsGPUProfiling = false;
|
|
|
|
sIsLayersDump = false;
|
2014-12-13 23:40:18 +03:00
|
|
|
sIsDisplayListDump = false;
|
2015-03-19 04:19:00 +03:00
|
|
|
sIsRestyleProfiling = false;
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2014-04-29 06:20:51 +04:00
|
|
|
if (Sampler::CanNotifyObservers()) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os)
|
|
|
|
os->NotifyObservers(nullptr, "profiler-stopped", nullptr);
|
|
|
|
}
|
2013-12-18 16:02:34 +04:00
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
LOG("END profiler_stop");
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
bool
|
|
|
|
profiler_is_paused()
|
|
|
|
{
|
2017-01-27 08:25:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
2014-03-01 00:16:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-27 08:25:23 +03:00
|
|
|
|
|
|
|
return gSampler->IsPaused();
|
2014-03-01 00:16:38 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_pause()
|
|
|
|
{
|
2017-01-27 08:25:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gSampler->SetPaused(true);
|
|
|
|
if (Sampler::CanNotifyObservers()) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(nullptr, "profiler-paused", nullptr);
|
2017-01-19 00:06:59 +03:00
|
|
|
}
|
2014-03-01 00:16:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_resume()
|
|
|
|
{
|
2017-01-27 08:25:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!gSampler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gSampler->SetPaused(false);
|
|
|
|
if (Sampler::CanNotifyObservers()) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(nullptr, "profiler-resumed", nullptr);
|
2017-01-19 00:06:59 +03:00
|
|
|
}
|
2014-03-01 00:16:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
bool
|
|
|
|
profiler_feature_active(const char* aName)
|
2014-05-24 20:14:14 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2014-05-24 20:14:14 +04:00
|
|
|
if (!profiler_is_active()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(aName, "gpu") == 0) {
|
|
|
|
return sIsGPUProfiling;
|
|
|
|
}
|
|
|
|
|
2014-12-13 00:11:57 +03:00
|
|
|
if (strcmp(aName, "layersdump") == 0) {
|
|
|
|
return sIsLayersDump;
|
|
|
|
}
|
|
|
|
|
2014-12-13 23:40:18 +03:00
|
|
|
if (strcmp(aName, "displaylistdump") == 0) {
|
|
|
|
return sIsDisplayListDump;
|
|
|
|
}
|
|
|
|
|
2015-03-19 04:19:00 +03:00
|
|
|
if (strcmp(aName, "restyle") == 0) {
|
|
|
|
return sIsRestyleProfiling;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:14:14 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
bool
|
|
|
|
profiler_is_active()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
return sIsProfiling;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_set_frame_number(int frameNumber)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-02-07 07:56:48 +03:00
|
|
|
gFrameNumber = frameNumber;
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_lock()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
profiler_stop();
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os)
|
|
|
|
os->NotifyObservers(nullptr, "profiler-locked", nullptr);
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_unlock()
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os)
|
|
|
|
os->NotifyObservers(nullptr, "profiler-unlocked", nullptr);
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_register_thread(const char* aName, void* aGuessStackTop)
|
2013-03-29 23:34:49 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2014-07-26 04:52:00 +04:00
|
|
|
if (sInitCount == 0) {
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
return;
|
2014-07-26 04:52:00 +04:00
|
|
|
}
|
|
|
|
|
2013-09-24 23:23:36 +04:00
|
|
|
#if defined(MOZ_WIDGET_GONK) && !defined(MOZ_PROFILING)
|
|
|
|
// The only way to profile secondary threads on b2g
|
|
|
|
// is to build with profiling OR have the profiler
|
|
|
|
// running on startup.
|
|
|
|
if (!profiler_is_active()) {
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
return;
|
2013-09-24 23:23:36 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-11 17:41:00 +03:00
|
|
|
MOZ_ASSERT(tlsPseudoStack.get() == nullptr);
|
2017-02-03 02:34:35 +03:00
|
|
|
PseudoStack* stack = new PseudoStack();
|
2013-03-29 23:34:49 +04:00
|
|
|
tlsPseudoStack.set(stack);
|
2013-10-22 17:30:06 +04:00
|
|
|
bool isMainThread = is_main_thread_name(aName);
|
2014-03-29 00:18:24 +04:00
|
|
|
void* stackTop = GetStackTop(aGuessStackTop);
|
2017-02-07 06:24:33 +03:00
|
|
|
RegisterCurrentThread(aName, stack, isMainThread, stackTop);
|
2013-03-29 23:34:49 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_unregister_thread()
|
2013-03-29 23:34:49 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2014-12-11 17:41:00 +03:00
|
|
|
// Don't check sInitCount count here -- we may be unregistering the
|
|
|
|
// thread after the sampler was shut down.
|
|
|
|
if (!stack_key_initialized) {
|
2014-07-26 04:52:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
if (sRegisteredThreads) {
|
|
|
|
Thread::tid_t id = Thread::GetCurrentId();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = sRegisteredThreads->at(i);
|
|
|
|
if (info->ThreadId() == id && !info->IsPendingDelete()) {
|
|
|
|
if (profiler_is_active()) {
|
|
|
|
// We still want to show the results of this thread if you
|
|
|
|
// save the profile shortly after a thread is terminated.
|
|
|
|
// For now we will defer the delete to profile stop.
|
|
|
|
info->SetPendingDelete();
|
|
|
|
} else {
|
|
|
|
delete info;
|
|
|
|
sRegisteredThreads->erase(sRegisteredThreads->begin() + i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 02:34:35 +03:00
|
|
|
|
2017-02-07 06:24:33 +03:00
|
|
|
// We just cut the ThreadInfo's PseudoStack pointer (either nulling it via
|
|
|
|
// SetPendingDelete() or by deleting the ThreadInfo altogether), so it is
|
|
|
|
// safe to delete the PseudoStack.
|
2017-02-03 02:34:35 +03:00
|
|
|
delete tlsPseudoStack.get();
|
|
|
|
tlsPseudoStack.set(nullptr);
|
2013-03-29 23:34:49 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_sleep_start()
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2017-01-20 06:20:11 +03:00
|
|
|
if (sInitCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-26 04:52:00 +04:00
|
|
|
|
2017-01-20 06:20:11 +03:00
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (stack == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stack->setSleeping(1);
|
2014-03-29 00:08:22 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_sleep_end()
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2017-01-20 06:20:11 +03:00
|
|
|
if (sInitCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-26 04:52:00 +04:00
|
|
|
|
2017-01-20 06:20:11 +03:00
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (stack == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stack->setSleeping(0);
|
2014-03-29 00:08:22 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
bool
|
|
|
|
profiler_is_sleeping()
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function currently only used on the main thread, but that restriction
|
|
|
|
// (and this assertion) could be removed without too much difficulty.
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-09-07 23:28:50 +03:00
|
|
|
if (sInitCount == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (stack == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return stack->isSleeping();
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_js_operation_callback()
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (!stack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack->jsOperationCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
profiler_time(const mozilla::TimeStamp& aTime)
|
2013-04-23 21:10:29 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-06-25 09:38:00 +04:00
|
|
|
mozilla::TimeDuration delta = aTime - sStartTime;
|
2013-04-23 21:10:29 +04:00
|
|
|
return delta.ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
double
|
|
|
|
profiler_time()
|
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
return profiler_time(mozilla::TimeStamp::Now());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
profiler_in_privacy_mode()
|
2013-09-25 19:28:34 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (!stack) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return stack->mPrivacyMode;
|
2013-09-25 19:28:34 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
UniqueProfilerBacktrace
|
|
|
|
profiler_get_backtrace()
|
2013-09-25 19:28:34 +04:00
|
|
|
{
|
2017-01-25 08:00:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-25 19:28:34 +04:00
|
|
|
if (!stack_key_initialized)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Don't capture a stack if we're not profiling
|
|
|
|
if (!profiler_is_active()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't capture a stack if we don't want to include personal information
|
|
|
|
if (profiler_in_privacy_mode()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
if (!gSampler) {
|
2013-09-25 19:28:34 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 08:00:47 +03:00
|
|
|
return UniqueProfilerBacktrace(
|
|
|
|
new ProfilerBacktrace(gSampler->GetBacktrace()));
|
2013-09-25 19:28:34 +04:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:21:01 +03:00
|
|
|
void
|
|
|
|
ProfilerBacktraceDestructor::operator()(ProfilerBacktrace* aBacktrace)
|
2013-09-25 19:28:34 +04:00
|
|
|
{
|
|
|
|
delete aBacktrace;
|
|
|
|
}
|
|
|
|
|
2015-05-08 06:21:21 +03:00
|
|
|
// Fill the output buffer with the following pattern:
|
|
|
|
// "Lable 1" "\0" "Label 2" "\0" ... "Label N" "\0" "\0"
|
|
|
|
// TODO: use the unwinder instead of pseudo stack.
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_get_backtrace_noalloc(char *output, size_t outputSize)
|
2015-05-08 06:21:21 +03:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-08 06:21:21 +03:00
|
|
|
MOZ_ASSERT(outputSize >= 2);
|
|
|
|
char *bound = output + outputSize - 2;
|
|
|
|
output[0] = output[1] = '\0';
|
|
|
|
PseudoStack *pseudoStack = tlsPseudoStack.get();
|
|
|
|
if (!pseudoStack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
volatile StackEntry *pseudoFrames = pseudoStack->mStack;
|
|
|
|
uint32_t pseudoCount = pseudoStack->stackSize();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pseudoCount; i++) {
|
|
|
|
size_t len = strlen(pseudoFrames[i].label());
|
|
|
|
if (output + len >= bound)
|
|
|
|
break;
|
|
|
|
strcpy(output, pseudoFrames[i].label());
|
|
|
|
output += len;
|
|
|
|
*output++ = '\0';
|
|
|
|
*output = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_tracing(const char* aCategory, const char* aInfo,
|
|
|
|
TracingMetadata aMetaData)
|
2013-09-27 20:08:45 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
// Don't insert a marker if we're not profiling, to avoid the heap copy
|
|
|
|
// (malloc).
|
|
|
|
if (!stack_key_initialized || !profiler_is_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler_add_marker(aInfo, new ProfilerMarkerTracing(aCategory, aMetaData));
|
2013-09-27 20:08:45 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_tracing(const char* aCategory, const char* aInfo,
|
|
|
|
UniqueProfilerBacktrace aCause, TracingMetadata aMetaData)
|
2014-04-22 22:13:00 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
// Don't insert a marker if we're not profiling, to avoid the heap copy
|
|
|
|
// (malloc).
|
|
|
|
if (!stack_key_initialized || !profiler_is_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler_add_marker(aInfo, new ProfilerMarkerTracing(aCategory, aMetaData,
|
|
|
|
mozilla::Move(aCause)));
|
2014-04-22 22:13:00 +04:00
|
|
|
}
|
|
|
|
|
Bug 1332577 (part 9) - Remove all mozilla_sampler_*() functions. r=mstange.
There are lots of profiler_*() functions that simply call onto equivalent or
nearly-equivalent mozilla_sampler_*() functions. This patch removes the
unnecessary indirection by removing the mozilla_sampler_*() functions.
The most important changes:
- In platform.cpp, all the mozilla_sampler_*() definitions are renamed as
profiler_*().
- In GeckoProfiler.h, the new PROFILER_FUNC{,_VOID} macros provide a neat way
to declare the functions that must be present whether the profiler is enabled
or not.
- In GeckoProfiler.h, all the mozilla_sampler_*() declarations are removed, as
are all the profiler_*() definitions that corresponded to a
mozilla_sampler_*() function.
Other things of note:
- profiler_log(const char* str) is now defined in platform.cpp, instead of in
GeckoProfiler.h, for consistency with all the other profiler_*() functions.
Likewise with profiler_js_operation_callback() and
profiler_in_privacy_mode().
- ProfilerBacktraceDestructor::operator() is treated slightly different to all
the profiler_*() functions.
- Both variants of profiler_tracing() got some early-return conditions moved
into them from GeckoProfiler.h.
- There were some cases where the profiler_*() and mozilla_sampler_*() name
didn't quite match. Specifically:
* mozilla_sampler_get_profile_data() and profiler_get_profiler_jsobject():
name mismatch. Kept the latter.
* mozilla_sampler_get_profile_data_async() and
profiler_get_profile_jsobject_async(): name mismatch. Kept the latter.
* mozilla_sampler_register_thread() and profiler_register_thread(): return
type mismatch. Changed to void.
* mozilla_sampler_frame_number() and profiler_set_frame_number(): name
mismatch. Kept the latter.
* mozilla_sampler_save_profile_to_file() and
profile_sampler_save_profile_to_file(): the former was 'extern "C"' so it
could be called from a debugger easily. The latter now is 'extern "C"'.
- profiler_get_buffer_info() didn't fit the patterns handled by
PROFILER_FUNC{,VOID}, so the patch makes it call onto the new function
profiler_get_buffer_info_helper(), which does fit the pattern.
--HG--
extra : rebase_source : fa1817854ade81e8a3027907d1476ff2563f1cc2
2017-01-20 07:05:16 +03:00
|
|
|
void
|
|
|
|
profiler_add_marker(const char *aMarker, ProfilerMarkerPayload *aPayload)
|
2013-12-11 01:34:19 +04:00
|
|
|
{
|
2017-02-06 06:31:38 +03:00
|
|
|
// This function runs both on and off the main thread.
|
|
|
|
|
2013-12-11 01:34:19 +04:00
|
|
|
// Note that aPayload may be allocated by the caller, so we need to make sure
|
|
|
|
// that we free it at some point.
|
2015-06-18 08:05:42 +03:00
|
|
|
mozilla::UniquePtr<ProfilerMarkerPayload> payload(aPayload);
|
2013-12-11 01:34:19 +04:00
|
|
|
|
|
|
|
if (!stack_key_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't insert a marker if we're not profiling to avoid
|
|
|
|
// the heap copy (malloc).
|
|
|
|
if (!profiler_is_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't add a marker if we don't want to include personal information
|
|
|
|
if (profiler_in_privacy_mode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PseudoStack *stack = tlsPseudoStack.get();
|
|
|
|
if (!stack) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-24 20:14:14 +04:00
|
|
|
|
|
|
|
mozilla::TimeStamp origin = (aPayload && !aPayload->GetStartTime().IsNull()) ?
|
|
|
|
aPayload->GetStartTime() : mozilla::TimeStamp::Now();
|
|
|
|
mozilla::TimeDuration delta = origin - sStartTime;
|
2015-06-18 08:05:42 +03:00
|
|
|
stack->addMarker(aMarker, payload.release(), delta.ToMilliseconds());
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
// END externally visible functions
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2017-02-07 08:09:39 +03:00
|
|
|
|
2017-02-07 06:15:30 +03:00
|
|
|
// XXX: Sampler will eventually be merged with this file. In the meantime,
|
|
|
|
// we #include it directly so that declarations can be shared between the files
|
|
|
|
// without having to copy all the code from that file into this one.
|
|
|
|
#include "Sampler.cpp"
|
|
|
|
|
2017-02-07 08:09:39 +03:00
|
|
|
// We #include these files directly because it means those files can use
|
|
|
|
// declarations from this file trivially.
|
|
|
|
#if defined(SPS_OS_windows)
|
|
|
|
# include "platform-win32.cc"
|
|
|
|
#elif defined(SPS_OS_darwin)
|
|
|
|
# include "platform-macos.cc"
|
|
|
|
#elif defined(SPS_OS_linux) || defined(SPS_OS_android)
|
|
|
|
# include "platform-linux.cc"
|
|
|
|
#else
|
|
|
|
# error "bad platform"
|
|
|
|
#endif
|
|
|
|
|