2013-03-11 02:00:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-09-25 19:28:34 +04:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-11 02:00:23 +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/. */
|
|
|
|
|
|
|
|
#ifndef MOZ_PROFILE_ENTRY_H
|
|
|
|
#define MOZ_PROFILE_ENTRY_H
|
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
#include <ostream>
|
2013-09-27 20:08:45 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "platform.h"
|
2014-04-22 00:48:47 +04:00
|
|
|
#include "JSStreamWriter.h"
|
2013-09-25 19:28:34 +04:00
|
|
|
#include "ProfilerBacktrace.h"
|
2013-03-11 02:00:23 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2014-04-07 23:29:07 +04:00
|
|
|
#include "gtest/MozGtestFriend.h"
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
class ThreadProfile;
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2014-03-31 16:19:00 +04:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
class ProfileEntry
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry();
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
// aTagData must not need release (i.e. be a string from the text segment)
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry(char aTagName, const char *aTagData);
|
|
|
|
ProfileEntry(char aTagName, void *aTagPtr);
|
2013-07-11 08:27:04 +04:00
|
|
|
ProfileEntry(char aTagName, ProfilerMarker *aTagMarker);
|
2014-04-10 18:52:23 +04:00
|
|
|
ProfileEntry(char aTagName, float aTagFloat);
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry(char aTagName, uintptr_t aTagOffset);
|
|
|
|
ProfileEntry(char aTagName, Address aTagAddress);
|
|
|
|
ProfileEntry(char aTagName, int aTagLine);
|
|
|
|
ProfileEntry(char aTagName, char aTagChar);
|
|
|
|
friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry);
|
2013-03-11 02:00:23 +04:00
|
|
|
bool is_ent_hint(char hintChar);
|
|
|
|
bool is_ent_hint();
|
|
|
|
bool is_ent(char tagName);
|
|
|
|
void* get_tagPtr();
|
|
|
|
void log();
|
2013-07-11 08:27:04 +04:00
|
|
|
const ProfilerMarker* getMarker() {
|
|
|
|
MOZ_ASSERT(mTagName == 'm');
|
|
|
|
return mTagMarker;
|
|
|
|
}
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
char getTagName() const { return mTagName; }
|
|
|
|
|
2013-03-11 02:00:23 +04:00
|
|
|
private:
|
2014-04-07 23:29:07 +04:00
|
|
|
FRIEND_TEST(ThreadProfile, InsertOneTag);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertOneTagWithTinyBuffer);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertTagsNoWrap);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertTagsWrap);
|
|
|
|
FRIEND_TEST(ThreadProfile, MemoryMeasure);
|
2013-03-26 01:57:28 +04:00
|
|
|
friend class ThreadProfile;
|
2013-03-11 02:00:23 +04:00
|
|
|
union {
|
|
|
|
const char* mTagData;
|
|
|
|
char mTagChars[sizeof(void*)];
|
|
|
|
void* mTagPtr;
|
2013-07-11 08:27:04 +04:00
|
|
|
ProfilerMarker* mTagMarker;
|
2014-04-10 18:52:23 +04:00
|
|
|
float mTagFloat;
|
2013-03-11 02:00:23 +04:00
|
|
|
Address mTagAddress;
|
|
|
|
uintptr_t mTagOffset;
|
|
|
|
int mTagLine;
|
|
|
|
char mTagChar;
|
|
|
|
};
|
|
|
|
char mTagName;
|
|
|
|
};
|
|
|
|
|
2014-03-31 16:19:00 +04:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagStringData);
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
class ThreadProfile
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-04-04 02:59:17 +04:00
|
|
|
ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack,
|
2013-09-25 19:28:34 +04:00
|
|
|
Thread::tid_t aThreadId, PlatformData* aPlatformData,
|
2013-09-11 22:50:46 +04:00
|
|
|
bool aIsMainThread, void *aStackTop);
|
2013-09-25 19:28:34 +04:00
|
|
|
virtual ~ThreadProfile();
|
2013-03-26 01:57:28 +04:00
|
|
|
void addTag(ProfileEntry aTag);
|
2013-03-11 02:00:23 +04:00
|
|
|
void flush();
|
|
|
|
void erase();
|
|
|
|
char* processDynamicTag(int readPos, int* tagsConsumed, char* tagBuff);
|
2013-03-26 01:57:28 +04:00
|
|
|
void IterateTags(IterateTagsCallback aCallback);
|
2013-03-11 02:00:23 +04:00
|
|
|
friend std::ostream& operator<<(std::ostream& stream,
|
2013-03-26 01:57:28 +04:00
|
|
|
const ThreadProfile& profile);
|
|
|
|
void ToStreamAsJSON(std::ostream& stream);
|
2013-09-06 03:10:37 +04:00
|
|
|
JSObject *ToJSObject(JSContext *aCx);
|
2013-03-11 02:00:23 +04:00
|
|
|
PseudoStack* GetPseudoStack();
|
|
|
|
mozilla::Mutex* GetMutex();
|
2014-04-22 00:48:47 +04:00
|
|
|
void StreamJSObject(JSStreamWriter& b);
|
2013-09-25 19:28:34 +04:00
|
|
|
void BeginUnwind();
|
|
|
|
virtual void EndUnwind();
|
|
|
|
virtual SyncProfile* AsSyncProfile() { return nullptr; }
|
2013-03-29 23:34:49 +04:00
|
|
|
|
|
|
|
bool IsMainThread() const { return mIsMainThread; }
|
|
|
|
const char* Name() const { return mName; }
|
2013-09-25 19:28:34 +04:00
|
|
|
Thread::tid_t ThreadId() const { return mThreadId; }
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
PlatformData* GetPlatformData() { return mPlatformData; }
|
2013-07-11 08:27:04 +04:00
|
|
|
int GetGenerationID() const { return mGeneration; }
|
|
|
|
bool HasGenerationExpired(int aGenID) {
|
|
|
|
return aGenID + 2 <= mGeneration;
|
|
|
|
}
|
2013-09-11 22:50:46 +04:00
|
|
|
void* GetStackTop() const { return mStackTop; }
|
2014-03-29 00:08:22 +04:00
|
|
|
void DuplicateLastSample();
|
2013-03-11 02:00:23 +04:00
|
|
|
private:
|
2014-04-07 23:29:07 +04:00
|
|
|
FRIEND_TEST(ThreadProfile, InsertOneTag);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertOneTagWithTinyBuffer);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertTagsNoWrap);
|
|
|
|
FRIEND_TEST(ThreadProfile, InsertTagsWrap);
|
|
|
|
FRIEND_TEST(ThreadProfile, MemoryMeasure);
|
2013-03-11 02:00:23 +04:00
|
|
|
// Circular buffer 'Keep One Slot Open' implementation
|
|
|
|
// for simplicity
|
2013-09-25 19:28:34 +04:00
|
|
|
ProfileEntry* mEntries;
|
2013-03-11 02:00:23 +04:00
|
|
|
int mWritePos; // points to the next entry we will write to
|
|
|
|
int mLastFlushPos; // points to the next entry since the last flush()
|
|
|
|
int mReadPos; // points to the next entry we will read to
|
|
|
|
int mEntrySize;
|
|
|
|
PseudoStack* mPseudoStack;
|
|
|
|
mozilla::Mutex mMutex;
|
2013-03-29 23:34:49 +04:00
|
|
|
char* mName;
|
2013-09-25 19:28:34 +04:00
|
|
|
Thread::tid_t mThreadId;
|
2013-03-29 23:34:49 +04:00
|
|
|
bool mIsMainThread;
|
2013-04-04 02:59:17 +04:00
|
|
|
PlatformData* mPlatformData; // Platform specific data.
|
2013-07-11 08:27:04 +04:00
|
|
|
int mGeneration;
|
|
|
|
int mPendingGenerationFlush;
|
2013-09-11 22:50:46 +04:00
|
|
|
void* const mStackTop;
|
2014-05-19 22:31:31 +04:00
|
|
|
|
|
|
|
// Only Linux is using a signal sender, instead of stopping the thread, so we
|
|
|
|
// need some space to store the data which cannot be collected in the signal
|
|
|
|
// handler code.
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
public:
|
|
|
|
int64_t mRssMemory;
|
|
|
|
#endif
|
2013-03-11 02:00:23 +04:00
|
|
|
};
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile);
|
|
|
|
|
2013-03-11 02:00:23 +04:00
|
|
|
#endif /* ndef MOZ_PROFILE_ENTRY_H */
|