Skip to content

Commit

Permalink
Bug 1492121 - MOZ_BASE_PROFILER may be defined in BaseProfiler.h to e…
Browse files Browse the repository at this point in the history
…nable Base Profiler - r=njn

Added baseprofiler to mozglue/moz.build, so it will be built.
However all cpp files are dependent on `MOZ_BASE_PROFILER`, which is currently
not #defined by default (in public/BaseProfiler.h).

Added mozglue/mozprofiler to js/src/make-source-package.sh, because
mozglue/moz.build now refers to it.

Differential Revision: https://phabricator.services.mozilla.com/D33258

--HG--
extra : moz-landing-system : lando
  • Loading branch information
squelart committed Jun 5, 2019
1 parent f12ec86 commit e1051b2
Show file tree
Hide file tree
Showing 30 changed files with 1,005 additions and 825 deletions.
92 changes: 49 additions & 43 deletions mozglue/baseprofiler/core/EHABIStackWalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,38 @@
* standard-layout rules in the former.
*/

#include "EHABIStackWalk.h"
#include "BaseProfiler.h"

#include "BaseProfilerSharedLibraries.h"
#include "platform.h"
#ifdef MOZ_BASE_PROFILER

#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/EndianUtils.h"
# include "EHABIStackWalk.h"

#include <algorithm>
#include <elf.h>
#include <stdint.h>
#include <vector>
#include <string>
# include "BaseProfilerSharedLibraries.h"
# include "platform.h"

#ifndef PT_ARM_EXIDX
# define PT_ARM_EXIDX 0x70000001
#endif
# include "mozilla/Atomics.h"
# include "mozilla/Attributes.h"
# include "mozilla/DebugOnly.h"
# include "mozilla/EndianUtils.h"

# include <algorithm>
# include <elf.h>
# include <stdint.h>
# include <vector>
# include <string>

# ifndef PT_ARM_EXIDX
# define PT_ARM_EXIDX 0x70000001
# endif

// Bug 1082817: ICS B2G has a buggy linker that doesn't always ensure
// that the EXIDX is sorted by address, as the spec requires. So in
// that case we build and sort an array of pointers into the index,
// and binary-search that; otherwise, we search the index in place
// (avoiding the time and space overhead of the indirection).
#if defined(ANDROID_VERSION) && ANDROID_VERSION < 16
# define HAVE_UNSORTED_EXIDX
#endif
# if defined(ANDROID_VERSION) && ANDROID_VERSION < 16
# define HAVE_UNSORTED_EXIDX
# endif

namespace mozilla {

Expand Down Expand Up @@ -90,7 +94,7 @@ class EHState {

enum { R_SP = 13, R_LR = 14, R_PC = 15 };

#ifdef HAVE_UNSORTED_EXIDX
# ifdef HAVE_UNSORTED_EXIDX
class EHEntryHandle {
const EHEntry* mValue;

Expand All @@ -102,13 +106,13 @@ class EHEntryHandle {
bool operator<(const EHEntryHandle& lhs, const EHEntryHandle& rhs) {
return lhs.value()->startPC.compute() < rhs.value()->startPC.compute();
}
#endif
# endif

class EHTable {
uint32_t mStartPC;
uint32_t mEndPC;
uint32_t mBaseAddress;
#ifdef HAVE_UNSORTED_EXIDX
# ifdef HAVE_UNSORTED_EXIDX
// In principle we should be able to binary-search the index section in
// place, but the ICS toolchain's linker is noncompliant and produces
// indices that aren't entirely sorted (e.g., libc). So we have this:
Expand All @@ -119,13 +123,13 @@ class EHTable {
static const EHEntry* entryGet(EntryIterator aEntry) {
return aEntry->value();
}
#else
# else
typedef const EHEntry* EntryIterator;
EntryIterator mEntriesBegin, mEntriesEnd;
EntryIterator entriesBegin() const { return mEntriesBegin; }
EntryIterator entriesEnd() const { return mEntriesEnd; }
static const EHEntry* entryGet(EntryIterator aEntry) { return aEntry; }
#endif
# endif
std::string mName;

public:
Expand Down Expand Up @@ -330,9 +334,9 @@ bool EHInterp::unwind() {
checkStack();
while (!mFailed) {
uint8_t insn = next();
#if DEBUG_EHABI_UNWIND
# if DEBUG_EHABI_UNWIND
LOG("unwind insn = %02x", (unsigned)insn);
#endif
# endif
// Try to put the common cases first.

// 00xxxxxx: vsp = vsp + (xxxxxx << 2) + 4
Expand Down Expand Up @@ -456,9 +460,9 @@ bool EHInterp::unwind() {
}

// unhandled instruction
#ifdef DEBUG_EHABI_UNWIND
# ifdef DEBUG_EHABI_UNWIND
LOG("Unhandled EHABI instruction 0x%02x", insn);
#endif
# endif
mFailed = true;
}
return false;
Expand Down Expand Up @@ -501,12 +505,12 @@ const EHEntry* EHTable::lookup(uint32_t aPC) const {
return nullptr;

while (end - begin > 1) {
#ifdef EHABI_UNWIND_MORE_ASSERTS
# ifdef EHABI_UNWIND_MORE_ASSERTS
if (entryGet(end - 1)->startPC.compute() <
entryGet(begin)->startPC.compute()) {
MOZ_CRASH("unsorted exidx");
}
#endif
# endif
EntryIterator mid = begin + (end - begin) / 2;
if (aPC < reinterpret_cast<uint32_t>(entryGet(mid)->startPC.compute()))
end = mid;
Expand All @@ -516,22 +520,22 @@ const EHEntry* EHTable::lookup(uint32_t aPC) const {
return entryGet(begin);
}

#if MOZ_LITTLE_ENDIAN
# if MOZ_LITTLE_ENDIAN
static const unsigned char hostEndian = ELFDATA2LSB;
#elif MOZ_BIG_ENDIAN
# elif MOZ_BIG_ENDIAN
static const unsigned char hostEndian = ELFDATA2MSB;
#else
# error "No endian?"
#endif
# else
# error "No endian?"
# endif

// Async signal unsafe: std::vector::reserve, std::string copy ctor.
EHTable::EHTable(const void* aELF, size_t aSize, const std::string& aName)
: mStartPC(~0), // largest uint32_t
mEndPC(0),
#ifndef HAVE_UNSORTED_EXIDX
# ifndef HAVE_UNSORTED_EXIDX
mEntriesBegin(nullptr),
mEntriesEnd(nullptr),
#endif
# endif
mName(aName) {
const uint32_t fileHeaderAddr = reinterpret_cast<uint32_t>(aELF);

Expand Down Expand Up @@ -574,14 +578,14 @@ EHTable::EHTable(const void* aELF, size_t aSize, const std::string& aName)
reinterpret_cast<const EHEntry*>(mBaseAddress + exidxHdr->p_vaddr);
const EHEntry* endTable = reinterpret_cast<const EHEntry*>(
mBaseAddress + exidxHdr->p_vaddr + exidxHdr->p_memsz);
#ifdef HAVE_UNSORTED_EXIDX
# ifdef HAVE_UNSORTED_EXIDX
mEntries.reserve(endTable - startTable);
for (const EHEntry* i = startTable; i < endTable; ++i) mEntries.push_back(i);
std::sort(mEntries.begin(), mEntries.end());
#else
# else
mEntriesBegin = startTable;
mEntriesEnd = endTable;
#endif
# endif
}

mozilla::Atomic<const EHAddrSpace*> EHAddrSpace::sCurrent(nullptr);
Expand Down Expand Up @@ -616,7 +620,7 @@ void EHAddrSpace::Update() {
}

EHState::EHState(const mcontext_t& context) {
#ifdef linux
# ifdef linux
mRegs[0] = context.arm_r0;
mRegs[1] = context.arm_r1;
mRegs[2] = context.arm_r2;
Expand All @@ -633,9 +637,11 @@ EHState::EHState(const mcontext_t& context) {
mRegs[13] = context.arm_sp;
mRegs[14] = context.arm_lr;
mRegs[15] = context.arm_pc;
#else
# error "Unhandled OS for ARM EHABI unwinding"
#endif
# else
# error "Unhandled OS for ARM EHABI unwinding"
# endif
}

} // namespace mozilla

#endif // MOZ_BASE_PROFILER
10 changes: 8 additions & 2 deletions mozglue/baseprofiler/core/PageInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
* 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/. */

#include "PageInformation.h"
#include "BaseProfiler.h"

#include "BaseProfileJSONWriter.h"
#ifdef MOZ_BASE_PROFILER

# include "PageInformation.h"

# include "BaseProfileJSONWriter.h"

PageInformation::PageInformation(const nsID& aDocShellId,
uint32_t aDocShellHistoryId,
Expand Down Expand Up @@ -35,3 +39,5 @@ size_t PageInformation::SizeOfIncludingThis(
mozilla::MallocSizeOf aMallocSizeOf) const {
return aMallocSizeOf(this);
}

#endif // MOZ_BASE_PROFILER
18 changes: 12 additions & 6 deletions mozglue/baseprofiler/core/ProfileBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
* 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/. */

#include "ProfileBuffer.h"
#include "BaseProfiler.h"

#include "ProfilerMarker.h"
#ifdef MOZ_BASE_PROFILER

#include "jsfriendapi.h"
#include "mozilla/MathAlgorithms.h"
#include "nsJSPrincipals.h"
#include "nsScriptSecurityManager.h"
# include "ProfileBuffer.h"

# include "ProfilerMarker.h"

# include "jsfriendapi.h"
# include "mozilla/MathAlgorithms.h"
# include "nsJSPrincipals.h"
# include "nsScriptSecurityManager.h"

using namespace mozilla;

Expand Down Expand Up @@ -188,3 +192,5 @@ void ProfileBufferCollector::CollectProfilingStackFrame(
mBuf.CollectCodeLocation(label, dynamicString, aFrame.flags(), line, column,
Some(aFrame.categoryPair()));
}

#endif // MOZ_BASE_PROFILER
54 changes: 30 additions & 24 deletions mozglue/baseprofiler/core/ProfileBufferEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
* 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/. */

#include "ProfileBufferEntry.h"
#include "BaseProfiler.h"

#include "platform.h"
#include "ProfileBuffer.h"
#ifdef MOZ_BASE_PROFILER

#include "js/TrackedOptimizationInfo.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "mozilla/Logging.h"
#include "mozilla/Sprintf.h"
#include "mozilla/StackWalk.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
# include "ProfileBufferEntry.h"

#include <ostream>
# include "platform.h"
# include "ProfileBuffer.h"

# include "js/TrackedOptimizationInfo.h"
# include "jsapi.h"
# include "jsfriendapi.h"
# include "mozilla/Logging.h"
# include "mozilla/Sprintf.h"
# include "mozilla/StackWalk.h"
# include "nsThreadUtils.h"
# include "nsXULAppAPI.h"

# include <ostream>

using namespace mozilla;

Expand Down Expand Up @@ -887,12 +891,12 @@ class EntryGetter {
// Because this is a format entirely internal to the Profiler, any parsing
// error indicates a bug in the ProfileBuffer writing or the parser itself,
// or possibly flaky hardware.
#define ERROR_AND_CONTINUE(msg) \
{ \
fprintf(stderr, "ProfileBuffer parse error: %s", msg); \
MOZ_ASSERT(false, msg); \
continue; \
}
# define ERROR_AND_CONTINUE(msg) \
{ \
fprintf(stderr, "ProfileBuffer parse error: %s", msg); \
MOZ_ASSERT(false, msg); \
continue; \
}

void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter,
int aThreadId, double aSinceTime,
Expand Down Expand Up @@ -1317,17 +1321,17 @@ void ProfileBuffer::StreamProfilerOverheadToJSON(
aWriter.DoubleProperty("overheadDurations", overheads.sum);
aWriter.DoubleProperty("overheadPercentage",
overheads.sum / (lastTime - firstTime));
#define PROFILER_STATS(name, var) \
aWriter.DoubleProperty("mean" name, (var).sum / (var).n); \
aWriter.DoubleProperty("min" name, (var).min); \
aWriter.DoubleProperty("max" name, (var).max);
# define PROFILER_STATS(name, var) \
aWriter.DoubleProperty("mean" name, (var).sum / (var).n); \
aWriter.DoubleProperty("min" name, (var).min); \
aWriter.DoubleProperty("max" name, (var).max);
PROFILER_STATS("Interval", intervals);
PROFILER_STATS("Overhead", overheads);
PROFILER_STATS("Lockings", lockings);
PROFILER_STATS("Cleaning", cleanings);
PROFILER_STATS("Counter", counters);
PROFILER_STATS("Thread", threads);
#undef PROFILER_STATS
# undef PROFILER_STATS
aWriter.EndObject(); // statistics
}
aWriter.EndObject(); // profilerOverhead
Expand Down Expand Up @@ -1572,7 +1576,7 @@ void ProfileBuffer::StreamMemoryToJSON(SpliceableJSONWriter& aWriter,
aWriter.EndObject(); // samples
aWriter.EndObject(); // memory
}
#undef ERROR_AND_CONTINUE
# undef ERROR_AND_CONTINUE

static void AddPausedRange(SpliceableJSONWriter& aWriter, const char* aReason,
const Maybe<double>& aStartTime,
Expand Down Expand Up @@ -1772,3 +1776,5 @@ void ProfileBuffer::DiscardSamplesBeforeTime(double aTime) {

// END ProfileBuffer
////////////////////////////////////////////////////////////////////////

#endif // MOZ_BASE_PROFILER
10 changes: 8 additions & 2 deletions mozglue/baseprofiler/core/ProfileJSONWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
* 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/. */

#include "BaseProfileJSONWriter.h"
#include "BaseProfiler.h"

#include "mozilla/HashFunctions.h"
#ifdef MOZ_BASE_PROFILER

# include "BaseProfileJSONWriter.h"

# include "mozilla/HashFunctions.h"

void ChunkedJSONWriteFunc::Write(const char* aStr) {
MOZ_ASSERT(mChunkPtr >= mChunkList.back().get() && mChunkPtr <= mChunkEnd);
Expand Down Expand Up @@ -112,3 +116,5 @@ void SpliceableChunkedJSONWriter::TakeAndSplice(ChunkedJSONWriteFunc* aFunc) {
WriteFunc()->Take(std::move(*aFunc));
mNeedComma[mDepth] = true;
}

#endif // MOZ_BASE_PROFILER
Loading

0 comments on commit e1051b2

Please sign in to comment.