This increases naming consistency. The remaining aStartTime parameters within
the profiler refer to a different start time than the process start time.
--HG--
extra : rebase_source : 0a07c54288f31af5a15518180b00fe59b587f784
None of the accesses to these fields occur in hot operations, so it's
reasonable to do them with gPSMutex held. As a result, mJSSampling doesn't need
to be Atomic<>, and mContext's lack of Atomic-ness is no longer a cause for
concern.
This required adding an extra field, mJSContext, to TickSample.
--HG--
extra : rebase_source : 1485de5e493cef655233507248006574d0ab6ebd
PseudoStack is misnamed: it contains the pseudo-stack plus other stuff that is
accessed via TLS.
This patch moves the non-pseudo-stack parts of PseudoStack into a new type
called RacyThreadInfo, which is a subclass of PseudoStack. The patch also
capitalizes the first letter of the names of methods that it moves.
This means that PseudoStack is now accurately named. Also non-pseudo-stack
parts are now no longer visible outside the profiler, which is nice.
--HG--
extra : rebase_source : c110acfb6d2a1527ed33cc073fab3fb188851b22
This option turns on a frame counter that is shown in the top left corner via a
QR code. It was designed to be used in video recordings of B2G phones.
It no longer seems useful, so this patch removes it.
* * *
Bug 1357298 - Remove all traces of frame numbers and power from the profiler output. r=mstange.
--HG--
extra : rebase_source : 0ce87963ce375df64bb8d80ef2b5d40ea507bc7c
This also renames HasProfile() to IsBeingProfiled().
MozReview-Commit-ID: 70RGHNbyZG3
--HG--
extra : rebase_source : 64f1df6985f41ae52d2385edcfd7822d16fd1e00
This also renames HasProfile() to IsBeingProfiled().
MozReview-Commit-ID: 70RGHNbyZG3
--HG--
extra : rebase_source : fbe6faf0ed9ee7273e77f1f81b79915800772212
Currently, ThreadInfos for live and dead threads are stored in a single vector.
This patch separates them into two separate vectors.
This ensures that the two kinds of ThreadInfos can't be mixed up. It also means
ThreadInfo::mPendingDelete can be removed.
Now that ThreadResponsiveness is only used on the main thread, we can refactor
ThreadInfo a bit. This patch does the following.
- Removes ThreadInfo::mThread, which is unused.
- Changes ThreadInfo::mRespInfo to a Maybe<>, and moves the is-main-thread
checking outside of ThreadInfo and ThreadResponsiveness.
- Renames {ThreadInfo,TickSample}::mRespInfo as mResponsiveness, to better
match the class name.
Currently each live thread has a PseudoStack that is owned by tlsPseudoStack,
and a ThreadInfo that has a non-owning pointer to the same PseudoStack.
Then, if the profile is active when the thread dies, ownership of the
PseudoStack is transferred to the ThreadInfo.
This patch simplifies the ownership rules. Every ThreadInfo now always owns its
PseudoStack and is responsible for destroying it. tlsPseudoStack is a
non-owning pointer, and so must be cleared when a PseudoStack is destroyed.
This simplifies the code in a few places.
--HG--
extra : rebase_source : 1012b6590380091d60eff98b4e0c5b1ba946cc7e
LastSample only makes sense for periodic samples, which are written to the
global ProfileBuffer. It doesn't make sense for synchronous samples which are
written to their own unshared buffer. At the moment it doesn't hurt to use
them in this nonsensical way, but the ThreadInfo profiler_get_backtrace()
will be removed soon, and we won't even have a LastSample to use nonsensically.
So this patch makes the LastSample argument to addTagThreadId() optional. Which
means we have to pass in a ThreadId, so there's no longer much point
duplicating the ThreadId in LastSample, so the patch removes that field too.
This avoids the possibility of the duplicate ThreadId failing to match, which
is nice.
--HG--
extra : rebase_source : dad76ff8b33663398e6f45f85da500b0fd7a598f
StreamSamplesAndMarkers() is the only ThreadInfo method called on
ProfilerBacktrace::mThreadInfo. Furthermore, it doesn't use all that much stuff
from ThreadInfo, and what stuff it does use we can instead pass in as
arguments.
This patch moves StreamSamplesAndMarkers() out of the class. It's a little
ugly, but a necessary precursor for removing ProfilerBacktrace::mThreadInfo and
all the subsequent improvements.
--HG--
extra : rebase_source : 417bda4f29a27c525f7240d3427494dd86b9a868
ProfileBuffer::FindLastSampleOfThread currently involves a linear search
backwards through the sample buffer. Profiling showed that to be the largest
profiler cost by far, at least on Linux. Bugs 1344118 and 1344258
significantly improve the situation, collectively reducing the cost by a
factor of at least 5 and often much more. But the linear search is still
present and still dominant. The worst of it is that it's unnecessary: we
could achieve the same by recording the start point of the most recent sample
for each thread in that thread's ThreadInfo record.
This patch does exactly that, adding the type ProfileBuffer::LastSample to
store the start points. LastSample also includes the ID of the thread it
pertains to as a read-only field, as that is needed in various places.
addTag doesn't check whether we're overwriting buffer entries containing start
points. Instead, FindLastSample checks whether the entry pointed to the
LastSample it is given still contains a marker.
--HG--
extra : rebase_source : 2987ec744a5c16e8b6814abe7efb507fc7280605
I also tweaked the int type of the JSON writer to match the IntProperty
method.
MozReview-Commit-ID: rtxLDKtJQZ
--HG--
extra : rebase_source : fa924479926cad6e07755d10c049a40ad896c3cd
This patch properly synchronizes all the global state in platform*.cpp, which
gets us a long way towards implementing bug 1330184.
- Most of the global state goes in a new class, ProfilerState, with a single
instance, gPS. All accesses to gPS are protected by gPSMutex. All functions
that access ProfilerState require a token proving that gPS is locked; this
makes things much clearer.
gRegisteredThreadsMutex is removed because it is subsumed by gPSMutex.
- gVerbosity, however, does not go in ProfilerState. It stays separate, and
gains its own mutex, gVerbosityMutex.
Also, the tracking of the current profiler state is streamlined. Previously it
was tracked via:
- stack_key_initialized, gInitCount, gSampler, gIsProfiling, gIsActive, and
gIsPaused.
Now it is tracked via:
- gPS, gPS->sActivity, and gPS->mIsPaused.
This means that the Sampler class is no longer necessary, and the patch removes
it.
Other changes of note made by the patch are as follows.
- It removes ThreadInfo::{mMutex,GetMutex}. This mutex was only used in two
places, and both these are now protected by gPSMutex.
- It tweaks the LOG calls. All the main functions (init(), shutdown(), start(),
stop()) now do consistent BEGIN/END logging, and a couple of other low-value
incidental LOG calls have been removed.
- It adds a lot of release assertions requiring that gPS be initialized (e.g.
profiler_init() has been called but profiler_shutdown() has not).
- It uses alphabetical order for everything involving profiler feature names.
- It removes Platform{Start,Stop}() and SamplerThread::{Start,Stop}Sampler().
These are no longer necessary now that SamplerThread::sInstance has been
replaced with ProfilerState::mSamplerThread which allows more direct access
to the current SamplerThread instance.
- It removes PseudoStack::mPrivacyMode. This was derived from the "privacy"
feature, and we now use gPS->mFeaturePrivacy directly, which is simpler.
It also replaces profiler_in_privacy_mode() with
profiler_is_active_and_not_in_privacy_mode(), which avoids an unnecessary
lock/unlock of gPSMutex on a moderately hot path.
Finally, the new code does more locking than the old one. A number of operation
The following operations now lock a mutex when they previously didn't; the
following are ones that are significant, according to some ad hoc profiling.
- profiler_tracing()
- profiler_is_active()
- profiler_is_active_and_not_in_privacy_mode()
- profiler_add_marker()
- profiler_feature_active()
- SamplerThread::Run() [when the profiler is paused]
All up this roughly doubles the amount of mutex locking done by the profiler.
It's probably possible to avoid this increase by allowing careful unlocked
access to three of the fields in ProfilerState (mActivityGeneration,
mFeaturePrivacy, mStartTime), but this should only be done as a follow-up if
the extra locking is found to be a problem.
--HG--
extra : rebase_source : c2e41231f131b3e9ccd23ddf43626b54ccc77b7b
Instead of nulling ThreadInfo::mPseudoStack, the patch changes things so that
ownership of the PseudoStack is transferred to the ThreadInfo. This avoids
crashes in some cases.
The patch also makes ThreadInfo::mPseudoStack a NotNull<>.
--HG--
extra : rebase_source : 95ace8886092ebe17ac0f4431c8c0936946c1f44
Because profiler_time() is going to need the global lock when I add it, and the
lock will already be held when streaming is happening, so it'll cause the
thread to deadlock itself.
Unfortunately this requires adding an |aStartTime| parameter to a lot of
functions, but this is the least worst way I can think of handling it.
This also removes the need for one of the profiler_time() functions, which the
patch removes.
When ProfilerBuffer::reset() is called, DuplicateLastSample() will start
failing for all sleeping threads because there will be no prior thread data in
the buffer to duplicate. But the sampling loop doesn't detect such failure.
This causes two problems:
- Missing samples.
- CPU usage goes through the roof, because each time around the sampling loop
the length of the failing search increases.
The fix is simple: detect failure in the sampling loop and do a normal sample
in that case.
The patch also removes ThreadInfo::DuplicateLastSample(), because it just calls
onto ProfileBuffer::DuplicateLastSample().
--HG--
extra : rebase_source : d51709994e701fdd63c292df5f723a2d43c4d754
Currently ThreadInfo objects all share gBuffer, while SyncProfile objects each
get their own ProfileBuffer.
This patch removes ThreadInfo::mBuffer to reduce this difference, taking us a
step towards eliminating SyncProfile.
To support this, the patch:
- passes in a buffer as an additional argument in a bunch of places where the
buffer used to be obtained from a ThreadInfo;
- adds an mBuffer field to ProfilerBacktrace;
- changes ThreadInfo::SetProfile() to SetHasProfile();
- removes ThreadInfo::{addTag,StoredMarker,bufferGeneration}(), all of which
just redirected to ThreadInfo anyway;
- changes ProfileBuffer so it's no longer refcounted, which is unnecessary now
that gBuffer and ProfilerBacktrace::mBuffer don't have multiple references,
which makes their lifetimes obvious.
The patch also removes some ThreadInfo& args in functions in platform.cpp, in
places where that ThreadInfo is available within the accompanying TickSampler*
arg.
--HG--
extra : rebase_source : 7e6cb370866d3f3fd657c6aa66d3c3eb3d83a4b1
Both of these functions are now trivial and identical in both ThreadInfo and
SyncProfile. This patch inlines and removes them.
--HG--
extra : rebase_source : 15fb7c1d4df9fbc80d8e671761b4aa1508845cac
This removes the one use of gStartTime outside of platform*.cpp, which lets us
restrict its visibility to just that compilation unit.
--HG--
extra : rebase_source : bf7207572cba5c1a31b544ea73e783ecd559978a
This change means that all the relevant code is now within
platform-linux-android.cpp, which is nice.
--HG--
extra : rebase_source : 886a31005fdb67fae65e6f4209796973f1391244
Currently we use the SPS_* macros in some places, but also use other ones like
__arm__ and ANDROID and XP_{WIN,MAC,LINUX}. This patch makes the profiler
consistently use the SPS_* macros and removes the V8_HOST_ARCH_* macros.
The patch also does the following.
- Cleans up some header inclusions, e.g. including pthread.h directly in the
files that use it, and removing some unneeded android/log.h inclusions.
- Removes an unused branch in SetSampleContext() -- we don't support ARM on
anything other than Android, and glibc 2.3 is ancient.
- Doesn't use SPS_* in PseudoStack.h because that would require exporting
PlatformMacros.h, which doesn't seem worthwhile.
Some things that aid the understanding of this patch.
- XP_LINUX and LINUX are both defined for Linux *and* Android.
- x86/Android is the only supported platform that doesn't define
HAVE_NATIVE_UNWIND.
- Every platform that defines USE_LUL_STACKWALK also defines
HAVE_NATIVE_UNWIND.
--HG--
extra : rebase_source : 561b708f9434cabd9c0e00d4f4bfdd53f7008670
I am planning to merge Sampler into platform.cpp, so Sampler.cpp will
disappear. This change will make that easier, because things that temporarily
need to be visible in both files won't need to be declared in a header.
--HG--
extra : rebase_source : f0fa4751f6ead945c1a00a17dbc9a7d3dc870e4b
It's fairly straightforward, and measures the important parts of:
- Sampler, PseudoStack, ProfileBuffer, ThreadInfo.
- LUL, PriMap, SecMap
Coverage isn't perfect, but it gets the major things I found via DMD on Linux.
Example output in about:memory:
├──151.21 MB (49.73%) -- profiler
│ ├──141.49 MB (46.53%) ── lul
│ └────9.72 MB (03.20%) ── sampler
--HG--
extra : rebase_source : 67d2ada42aead43f68f5100a08204a1d1f1cfceb
ThreadInfo contains a ThreadResponsiveness, and then ThreadResponsiveness has a
pointer back to its containing ThreadInfo, which is gross.
The back pointer is only needed for Update(), and it's easy to pass in the
necessary info instead via a new method UpdateThreadResponsiveness().
This change also means ThreadInfo::GetThread() can be removed.
--HG--
extra : rebase_source : 46ebeb142e8c678be204b106713147738bcbc4a4
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
Smart pointers are better than raw pointers, and this makes clients of
PlatformData slightly simpler because they don't have to manage
destruction themselves: the new UniquePtr-derived type handles all of
that for us.
Smart pointers are better than raw pointers. This change also has the
benefit of removing the manual memory management in ~GeckoSampler and
locating all the memory management in ThreadInfo, where it belongs.