1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/ProfileEntry.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef MOZ_PROFILE_ENTRY_H 1.11 +#define MOZ_PROFILE_ENTRY_H 1.12 + 1.13 +#include <ostream> 1.14 +#include "GeckoProfiler.h" 1.15 +#include "platform.h" 1.16 +#include "JSStreamWriter.h" 1.17 +#include "ProfilerBacktrace.h" 1.18 +#include "mozilla/Mutex.h" 1.19 + 1.20 +class ThreadProfile; 1.21 + 1.22 +#pragma pack(push, 1) 1.23 + 1.24 +class ProfileEntry 1.25 +{ 1.26 +public: 1.27 + ProfileEntry(); 1.28 + 1.29 + // aTagData must not need release (i.e. be a string from the text segment) 1.30 + ProfileEntry(char aTagName, const char *aTagData); 1.31 + ProfileEntry(char aTagName, void *aTagPtr); 1.32 + ProfileEntry(char aTagName, ProfilerMarker *aTagMarker); 1.33 + ProfileEntry(char aTagName, float aTagFloat); 1.34 + ProfileEntry(char aTagName, uintptr_t aTagOffset); 1.35 + ProfileEntry(char aTagName, Address aTagAddress); 1.36 + ProfileEntry(char aTagName, int aTagLine); 1.37 + ProfileEntry(char aTagName, char aTagChar); 1.38 + friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry); 1.39 + bool is_ent_hint(char hintChar); 1.40 + bool is_ent_hint(); 1.41 + bool is_ent(char tagName); 1.42 + void* get_tagPtr(); 1.43 + void log(); 1.44 + const ProfilerMarker* getMarker() { 1.45 + MOZ_ASSERT(mTagName == 'm'); 1.46 + return mTagMarker; 1.47 + } 1.48 + 1.49 + char getTagName() const { return mTagName; } 1.50 + 1.51 +private: 1.52 + friend class ThreadProfile; 1.53 + union { 1.54 + const char* mTagData; 1.55 + char mTagChars[sizeof(void*)]; 1.56 + void* mTagPtr; 1.57 + ProfilerMarker* mTagMarker; 1.58 + float mTagFloat; 1.59 + Address mTagAddress; 1.60 + uintptr_t mTagOffset; 1.61 + int mTagLine; 1.62 + char mTagChar; 1.63 + }; 1.64 + char mTagName; 1.65 +}; 1.66 + 1.67 +#pragma pack(pop) 1.68 + 1.69 +typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagStringData); 1.70 + 1.71 +class ThreadProfile 1.72 +{ 1.73 +public: 1.74 + ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack, 1.75 + Thread::tid_t aThreadId, PlatformData* aPlatformData, 1.76 + bool aIsMainThread, void *aStackTop); 1.77 + virtual ~ThreadProfile(); 1.78 + void addTag(ProfileEntry aTag); 1.79 + void flush(); 1.80 + void erase(); 1.81 + char* processDynamicTag(int readPos, int* tagsConsumed, char* tagBuff); 1.82 + void IterateTags(IterateTagsCallback aCallback); 1.83 + friend std::ostream& operator<<(std::ostream& stream, 1.84 + const ThreadProfile& profile); 1.85 + void ToStreamAsJSON(std::ostream& stream); 1.86 + JSObject *ToJSObject(JSContext *aCx); 1.87 + PseudoStack* GetPseudoStack(); 1.88 + mozilla::Mutex* GetMutex(); 1.89 + void StreamJSObject(JSStreamWriter& b); 1.90 + void BeginUnwind(); 1.91 + virtual void EndUnwind(); 1.92 + virtual SyncProfile* AsSyncProfile() { return nullptr; } 1.93 + 1.94 + bool IsMainThread() const { return mIsMainThread; } 1.95 + const char* Name() const { return mName; } 1.96 + Thread::tid_t ThreadId() const { return mThreadId; } 1.97 + 1.98 + PlatformData* GetPlatformData() { return mPlatformData; } 1.99 + int GetGenerationID() const { return mGeneration; } 1.100 + bool HasGenerationExpired(int aGenID) { 1.101 + return aGenID + 2 <= mGeneration; 1.102 + } 1.103 + void* GetStackTop() const { return mStackTop; } 1.104 + void DuplicateLastSample(); 1.105 +private: 1.106 + // Circular buffer 'Keep One Slot Open' implementation 1.107 + // for simplicity 1.108 + ProfileEntry* mEntries; 1.109 + int mWritePos; // points to the next entry we will write to 1.110 + int mLastFlushPos; // points to the next entry since the last flush() 1.111 + int mReadPos; // points to the next entry we will read to 1.112 + int mEntrySize; 1.113 + PseudoStack* mPseudoStack; 1.114 + mozilla::Mutex mMutex; 1.115 + char* mName; 1.116 + Thread::tid_t mThreadId; 1.117 + bool mIsMainThread; 1.118 + PlatformData* mPlatformData; // Platform specific data. 1.119 + int mGeneration; 1.120 + int mPendingGenerationFlush; 1.121 + void* const mStackTop; 1.122 +}; 1.123 + 1.124 +std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile); 1.125 + 1.126 +#endif /* ndef MOZ_PROFILE_ENTRY_H */