Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef MOZ_PROFILE_ENTRY_H |
michael@0 | 8 | #define MOZ_PROFILE_ENTRY_H |
michael@0 | 9 | |
michael@0 | 10 | #include <ostream> |
michael@0 | 11 | #include "GeckoProfiler.h" |
michael@0 | 12 | #include "platform.h" |
michael@0 | 13 | #include "JSStreamWriter.h" |
michael@0 | 14 | #include "ProfilerBacktrace.h" |
michael@0 | 15 | #include "mozilla/Mutex.h" |
michael@0 | 16 | |
michael@0 | 17 | class ThreadProfile; |
michael@0 | 18 | |
michael@0 | 19 | #pragma pack(push, 1) |
michael@0 | 20 | |
michael@0 | 21 | class ProfileEntry |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | ProfileEntry(); |
michael@0 | 25 | |
michael@0 | 26 | // aTagData must not need release (i.e. be a string from the text segment) |
michael@0 | 27 | ProfileEntry(char aTagName, const char *aTagData); |
michael@0 | 28 | ProfileEntry(char aTagName, void *aTagPtr); |
michael@0 | 29 | ProfileEntry(char aTagName, ProfilerMarker *aTagMarker); |
michael@0 | 30 | ProfileEntry(char aTagName, float aTagFloat); |
michael@0 | 31 | ProfileEntry(char aTagName, uintptr_t aTagOffset); |
michael@0 | 32 | ProfileEntry(char aTagName, Address aTagAddress); |
michael@0 | 33 | ProfileEntry(char aTagName, int aTagLine); |
michael@0 | 34 | ProfileEntry(char aTagName, char aTagChar); |
michael@0 | 35 | friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry); |
michael@0 | 36 | bool is_ent_hint(char hintChar); |
michael@0 | 37 | bool is_ent_hint(); |
michael@0 | 38 | bool is_ent(char tagName); |
michael@0 | 39 | void* get_tagPtr(); |
michael@0 | 40 | void log(); |
michael@0 | 41 | const ProfilerMarker* getMarker() { |
michael@0 | 42 | MOZ_ASSERT(mTagName == 'm'); |
michael@0 | 43 | return mTagMarker; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | char getTagName() const { return mTagName; } |
michael@0 | 47 | |
michael@0 | 48 | private: |
michael@0 | 49 | friend class ThreadProfile; |
michael@0 | 50 | union { |
michael@0 | 51 | const char* mTagData; |
michael@0 | 52 | char mTagChars[sizeof(void*)]; |
michael@0 | 53 | void* mTagPtr; |
michael@0 | 54 | ProfilerMarker* mTagMarker; |
michael@0 | 55 | float mTagFloat; |
michael@0 | 56 | Address mTagAddress; |
michael@0 | 57 | uintptr_t mTagOffset; |
michael@0 | 58 | int mTagLine; |
michael@0 | 59 | char mTagChar; |
michael@0 | 60 | }; |
michael@0 | 61 | char mTagName; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | #pragma pack(pop) |
michael@0 | 65 | |
michael@0 | 66 | typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagStringData); |
michael@0 | 67 | |
michael@0 | 68 | class ThreadProfile |
michael@0 | 69 | { |
michael@0 | 70 | public: |
michael@0 | 71 | ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack, |
michael@0 | 72 | Thread::tid_t aThreadId, PlatformData* aPlatformData, |
michael@0 | 73 | bool aIsMainThread, void *aStackTop); |
michael@0 | 74 | virtual ~ThreadProfile(); |
michael@0 | 75 | void addTag(ProfileEntry aTag); |
michael@0 | 76 | void flush(); |
michael@0 | 77 | void erase(); |
michael@0 | 78 | char* processDynamicTag(int readPos, int* tagsConsumed, char* tagBuff); |
michael@0 | 79 | void IterateTags(IterateTagsCallback aCallback); |
michael@0 | 80 | friend std::ostream& operator<<(std::ostream& stream, |
michael@0 | 81 | const ThreadProfile& profile); |
michael@0 | 82 | void ToStreamAsJSON(std::ostream& stream); |
michael@0 | 83 | JSObject *ToJSObject(JSContext *aCx); |
michael@0 | 84 | PseudoStack* GetPseudoStack(); |
michael@0 | 85 | mozilla::Mutex* GetMutex(); |
michael@0 | 86 | void StreamJSObject(JSStreamWriter& b); |
michael@0 | 87 | void BeginUnwind(); |
michael@0 | 88 | virtual void EndUnwind(); |
michael@0 | 89 | virtual SyncProfile* AsSyncProfile() { return nullptr; } |
michael@0 | 90 | |
michael@0 | 91 | bool IsMainThread() const { return mIsMainThread; } |
michael@0 | 92 | const char* Name() const { return mName; } |
michael@0 | 93 | Thread::tid_t ThreadId() const { return mThreadId; } |
michael@0 | 94 | |
michael@0 | 95 | PlatformData* GetPlatformData() { return mPlatformData; } |
michael@0 | 96 | int GetGenerationID() const { return mGeneration; } |
michael@0 | 97 | bool HasGenerationExpired(int aGenID) { |
michael@0 | 98 | return aGenID + 2 <= mGeneration; |
michael@0 | 99 | } |
michael@0 | 100 | void* GetStackTop() const { return mStackTop; } |
michael@0 | 101 | void DuplicateLastSample(); |
michael@0 | 102 | private: |
michael@0 | 103 | // Circular buffer 'Keep One Slot Open' implementation |
michael@0 | 104 | // for simplicity |
michael@0 | 105 | ProfileEntry* mEntries; |
michael@0 | 106 | int mWritePos; // points to the next entry we will write to |
michael@0 | 107 | int mLastFlushPos; // points to the next entry since the last flush() |
michael@0 | 108 | int mReadPos; // points to the next entry we will read to |
michael@0 | 109 | int mEntrySize; |
michael@0 | 110 | PseudoStack* mPseudoStack; |
michael@0 | 111 | mozilla::Mutex mMutex; |
michael@0 | 112 | char* mName; |
michael@0 | 113 | Thread::tid_t mThreadId; |
michael@0 | 114 | bool mIsMainThread; |
michael@0 | 115 | PlatformData* mPlatformData; // Platform specific data. |
michael@0 | 116 | int mGeneration; |
michael@0 | 117 | int mPendingGenerationFlush; |
michael@0 | 118 | void* const mStackTop; |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile); |
michael@0 | 122 | |
michael@0 | 123 | #endif /* ndef MOZ_PROFILE_ENTRY_H */ |