Bug 1353630 (part 5) - Allocate PseudoStack within ThreadInfo's constructor. r=jseward.

This commit is contained in:
Nicholas Nethercote 2017-04-06 09:40:28 +10:00
parent bd098b6cbc
commit 632b8b594d
4 changed files with 19 additions and 22 deletions

View File

@ -20,12 +20,11 @@
#endif
ThreadInfo::ThreadInfo(const char* aName, int aThreadId, bool aIsMainThread,
mozilla::NotNull<PseudoStack*> aPseudoStack,
void* aStackTop)
: mName(strdup(aName))
, mThreadId(aThreadId)
, mIsMainThread(aIsMainThread)
, mPseudoStack(aPseudoStack)
, mPseudoStack(mozilla::WrapNotNull(new PseudoStack()))
, mPlatformData(AllocPlatformData(aThreadId))
, mStackTop(aStackTop)
, mHasProfile(false)

View File

@ -17,7 +17,7 @@ class ThreadInfo final
{
public:
ThreadInfo(const char* aName, int aThreadId, bool aIsMainThread,
mozilla::NotNull<PseudoStack*> aPseudoStack, void* aStackTop);
void* aStackTop);
~ThreadInfo();
@ -25,6 +25,7 @@ public:
int ThreadId() const { return mThreadId; }
bool IsMainThread() const { return mIsMainThread; }
mozilla::NotNull<PseudoStack*> Stack() const { return mPseudoStack; }
void SetHasProfile() { mHasProfile = true; }
@ -41,7 +42,10 @@ private:
int mThreadId;
const bool mIsMainThread;
// The thread's PseudoStack. This is an owning pointer.
// The thread's PseudoStack. This is an owning pointer. It could be an inline
// member, but we don't do that because PseudoStack is quite large, and we
// have ThreadInfo vectors and so we'd end up wasting a lot of space in those
// vectors for excess elements.
mozilla::NotNull<PseudoStack*> mPseudoStack;
UniquePlatformData mPlatformData;

View File

@ -1905,11 +1905,12 @@ locked_register_thread(PS::LockRef aLock, const char* aName, void* stackTop)
if (!tlsPseudoStack.init()) {
return;
}
NotNull<PseudoStack*> stack = WrapNotNull(new PseudoStack());
tlsPseudoStack.set(stack);
ThreadInfo* info = new ThreadInfo(aName, Thread::GetCurrentId(),
NS_IsMainThread(), stack, stackTop);
NS_IsMainThread(), stackTop);
NotNull<PseudoStack*> pseudoStack = info->Stack();
tlsPseudoStack.set(pseudoStack.get());
if (ShouldProfileThread(aLock, info)) {
info->SetHasProfile();
@ -1917,8 +1918,8 @@ locked_register_thread(PS::LockRef aLock, const char* aName, void* stackTop)
if (gPS->IsActive(aLock) && gPS->FeatureJS(aLock)) {
// This startJSSampling() call is on-thread, so we can poll manually to
// start JS sampling immediately.
stack->startJSSampling();
stack->pollJSSampling();
pseudoStack->startJSSampling();
pseudoStack->pollJSSampling();
}
}
@ -2403,8 +2404,8 @@ locked_profiler_start(PS::LockRef aLock, int aEntries, double aInterval,
if (featureJS) {
// We just called startJSSampling() on all relevant threads. We can also
// manually poll the current thread so it starts sampling immediately.
if (PseudoStack* stack = tlsPseudoStack.get()) {
stack->pollJSSampling();
if (PseudoStack* pseudoStack = tlsPseudoStack.get()) {
pseudoStack->pollJSSampling();
}
}

View File

@ -8,22 +8,17 @@
#include "ProfileBufferEntry.h"
#include "ThreadInfo.h"
using mozilla::NotNull;
using mozilla::WrapNotNull;
// Make sure we can initialize our thread profile
TEST(ThreadProfile, Initialization) {
Thread::tid_t tid = 1000;
ThreadInfo info("testThread", tid, true, WrapNotNull(new PseudoStack()),
nullptr);
ThreadInfo info("testThread", tid, true, nullptr);
info.SetHasProfile();
}
// Make sure we can record one tag and read it
TEST(ThreadProfile, InsertOneTag) {
Thread::tid_t tid = 1000;
ThreadInfo info("testThread", tid, true, WrapNotNull(new PseudoStack()),
nullptr);
ThreadInfo info("testThread", tid, true, nullptr);
ProfileBuffer* pb = new ProfileBuffer(10);
pb->addTag(ProfileBufferEntry::Time(123.1));
ASSERT_TRUE(pb->mEntries != nullptr);
@ -35,8 +30,7 @@ TEST(ThreadProfile, InsertOneTag) {
// See if we can insert some tags
TEST(ThreadProfile, InsertTagsNoWrap) {
Thread::tid_t tid = 1000;
ThreadInfo info("testThread", tid, true, WrapNotNull(new PseudoStack()),
nullptr);
ThreadInfo info("testThread", tid, true, nullptr);
ProfileBuffer* pb = new ProfileBuffer(100);
int test_size = 50;
for (int i = 0; i < test_size; i++) {
@ -58,8 +52,7 @@ TEST(ThreadProfile, InsertTagsWrap) {
// we can fit only 24 tags in this buffer because of the empty slot
int tags = 24;
int buffer_size = tags + 1;
ThreadInfo info("testThread", tid, true, WrapNotNull(new PseudoStack()),
nullptr);
ThreadInfo info("testThread", tid, true, nullptr);
ProfileBuffer* pb = new ProfileBuffer(buffer_size);
int test_size = 43;
for (int i = 0; i < test_size; i++) {