2013-03-10 15:00:23 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-09-25 08:28:34 -07:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-10 15:00:23 -07: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 12:34:49 -07:00
|
|
|
#include <ostream>
|
2013-09-27 09:08:45 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2013-03-25 14:57:28 -07:00
|
|
|
#include "platform.h"
|
2013-09-25 08:28:34 -07:00
|
|
|
#include "ProfilerBacktrace.h"
|
2013-03-10 15:00:23 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
class ThreadProfile;
|
2013-03-10 15:00:23 -07:00
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
class ProfileEntry
|
2013-03-10 15:00:23 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-03-25 14:57:28 -07:00
|
|
|
ProfileEntry();
|
2013-03-10 15:00:23 -07:00
|
|
|
|
|
|
|
// aTagData must not need release (i.e. be a string from the text segment)
|
2013-03-25 14:57:28 -07:00
|
|
|
ProfileEntry(char aTagName, const char *aTagData);
|
|
|
|
ProfileEntry(char aTagName, void *aTagPtr);
|
2013-07-10 21:27:04 -07:00
|
|
|
ProfileEntry(char aTagName, ProfilerMarker *aTagMarker);
|
2013-03-25 14:57:28 -07:00
|
|
|
ProfileEntry(char aTagName, double aTagFloat);
|
|
|
|
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-10 15:00:23 -07:00
|
|
|
bool is_ent_hint(char hintChar);
|
|
|
|
bool is_ent_hint();
|
|
|
|
bool is_ent(char tagName);
|
|
|
|
void* get_tagPtr();
|
|
|
|
void log();
|
2013-07-10 21:27:04 -07:00
|
|
|
const ProfilerMarker* getMarker() {
|
|
|
|
MOZ_ASSERT(mTagName == 'm');
|
|
|
|
return mTagMarker;
|
|
|
|
}
|
2013-03-10 15:00:23 -07:00
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
char getTagName() const { return mTagName; }
|
|
|
|
|
2013-03-10 15:00:23 -07:00
|
|
|
private:
|
2013-03-25 14:57:28 -07:00
|
|
|
friend class ThreadProfile;
|
2013-03-10 15:00:23 -07:00
|
|
|
union {
|
|
|
|
const char* mTagData;
|
|
|
|
char mTagChars[sizeof(void*)];
|
|
|
|
void* mTagPtr;
|
2013-07-10 21:27:04 -07:00
|
|
|
ProfilerMarker* mTagMarker;
|
2013-03-10 15:00:23 -07:00
|
|
|
double mTagFloat;
|
|
|
|
Address mTagAddress;
|
|
|
|
uintptr_t mTagOffset;
|
|
|
|
int mTagLine;
|
|
|
|
char mTagChar;
|
|
|
|
};
|
|
|
|
char mTagName;
|
|
|
|
};
|
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagStringData);
|
2013-03-10 15:00:23 -07:00
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
class ThreadProfile
|
2013-03-10 15:00:23 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-04-03 15:59:17 -07:00
|
|
|
ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack,
|
2013-09-25 08:28:34 -07:00
|
|
|
Thread::tid_t aThreadId, PlatformData* aPlatformData,
|
2013-09-11 11:50:46 -07:00
|
|
|
bool aIsMainThread, void *aStackTop);
|
2013-09-25 08:28:34 -07:00
|
|
|
virtual ~ThreadProfile();
|
2013-03-25 14:57:28 -07:00
|
|
|
void addTag(ProfileEntry aTag);
|
2013-03-10 15:00:23 -07:00
|
|
|
void flush();
|
|
|
|
void erase();
|
|
|
|
char* processDynamicTag(int readPos, int* tagsConsumed, char* tagBuff);
|
2013-03-25 14:57:28 -07:00
|
|
|
void IterateTags(IterateTagsCallback aCallback);
|
2013-03-10 15:00:23 -07:00
|
|
|
friend std::ostream& operator<<(std::ostream& stream,
|
2013-03-25 14:57:28 -07:00
|
|
|
const ThreadProfile& profile);
|
|
|
|
void ToStreamAsJSON(std::ostream& stream);
|
2013-09-05 16:10:37 -07:00
|
|
|
JSObject *ToJSObject(JSContext *aCx);
|
2013-03-10 15:00:23 -07:00
|
|
|
PseudoStack* GetPseudoStack();
|
|
|
|
mozilla::Mutex* GetMutex();
|
2013-09-05 16:10:37 -07:00
|
|
|
template <typename Builder> void BuildJSObject(Builder& b, typename Builder::ObjectHandle profile);
|
2013-09-25 08:28:34 -07:00
|
|
|
void BeginUnwind();
|
|
|
|
virtual void EndUnwind();
|
|
|
|
virtual SyncProfile* AsSyncProfile() { return nullptr; }
|
2013-03-29 12:34:49 -07:00
|
|
|
|
|
|
|
bool IsMainThread() const { return mIsMainThread; }
|
|
|
|
const char* Name() const { return mName; }
|
2013-09-25 08:28:34 -07:00
|
|
|
Thread::tid_t ThreadId() const { return mThreadId; }
|
2013-03-29 12:34:49 -07:00
|
|
|
|
2013-04-03 15:59:17 -07:00
|
|
|
PlatformData* GetPlatformData() { return mPlatformData; }
|
2013-07-10 21:27:04 -07:00
|
|
|
int GetGenerationID() const { return mGeneration; }
|
|
|
|
bool HasGenerationExpired(int aGenID) {
|
|
|
|
return aGenID + 2 <= mGeneration;
|
|
|
|
}
|
2013-09-11 11:50:46 -07:00
|
|
|
void* GetStackTop() const { return mStackTop; }
|
2013-03-10 15:00:23 -07:00
|
|
|
private:
|
|
|
|
// Circular buffer 'Keep One Slot Open' implementation
|
|
|
|
// for simplicity
|
2013-09-25 08:28:34 -07:00
|
|
|
ProfileEntry* mEntries;
|
2013-03-10 15:00:23 -07: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 12:34:49 -07:00
|
|
|
char* mName;
|
2013-09-25 08:28:34 -07:00
|
|
|
Thread::tid_t mThreadId;
|
2013-03-29 12:34:49 -07:00
|
|
|
bool mIsMainThread;
|
2013-04-03 15:59:17 -07:00
|
|
|
PlatformData* mPlatformData; // Platform specific data.
|
2013-07-10 21:27:04 -07:00
|
|
|
int mGeneration;
|
|
|
|
int mPendingGenerationFlush;
|
2013-09-11 11:50:46 -07:00
|
|
|
void* const mStackTop;
|
2013-03-10 15:00:23 -07:00
|
|
|
};
|
|
|
|
|
2013-03-25 14:57:28 -07:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile);
|
|
|
|
|
2013-03-10 15:00:23 -07:00
|
|
|
#endif /* ndef MOZ_PROFILE_ENTRY_H */
|