1 /* 2 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef THREAD_H 6 #define THREAD_H 7 8 9 #include <String.h> 10 11 #include <util/DoublyLinkedList.h> 12 13 #include "ProfiledEntity.h" 14 #include "ProfileResult.h" 15 16 17 class Image; 18 class Team; 19 20 21 class ThreadImage : public DoublyLinkedListLinkImpl<ThreadImage> { 22 public: 23 ThreadImage(Image* image, 24 ImageProfileResult* result); 25 ~ThreadImage(); 26 27 Image* GetImage() const { return fImage; } 28 ImageProfileResult* Result() const { return fResult; } 29 30 private: 31 Image* fImage; 32 ImageProfileResult* fResult; 33 }; 34 35 36 class Thread : public ProfiledEntity, public DoublyLinkedListLinkImpl<Thread>, 37 private ImageProfileResultContainer { 38 public: 39 Thread(thread_id threadID, const char* name, 40 Team* team); 41 virtual ~Thread(); 42 43 inline thread_id ID() const; 44 inline const char* Name() const; 45 inline addr_t* Samples() const; 46 inline Team* GetTeam() const; 47 48 virtual int32 EntityID() const; 49 virtual const char* EntityName() const; 50 virtual const char* EntityType() const; 51 52 inline ProfileResult* GetProfileResult() const; 53 void SetProfileResult(ProfileResult* result); 54 55 void UpdateInfo(const char* name); 56 57 void SetSampleArea(area_id area, addr_t* samples); 58 void SetInterval(bigtime_t interval); 59 60 void SetLazyImages(bool lazy); 61 62 status_t AddImage(Image* image); 63 void RemoveImage(Image* image); 64 65 void AddSamples(int32 count, int32 dropped, 66 int32 stackDepth, bool variableStackDepth, 67 int32 event); 68 void AddSamples(addr_t* samples, int32 sampleCount); 69 void PrintResults(); 70 71 private: 72 typedef DoublyLinkedList<ThreadImage> ImageList; 73 74 private: 75 // ImageProfileResultContainer 76 virtual int32 CountImages() const; 77 virtual ImageProfileResult* VisitImages(Visitor& visitor) const; 78 virtual ImageProfileResult* FindImage(addr_t address, 79 addr_t& _loadDelta) const; 80 81 private: 82 void _SynchronizeImages(int32 event); 83 84 private: 85 thread_id fID; 86 BString fName; 87 ::Team* fTeam; 88 area_id fSampleArea; 89 addr_t* fSamples; 90 ProfileResult* fProfileResult; 91 ImageList fImages; 92 ImageList fNewImages; 93 ImageList fOldImages; 94 bool fLazyImages; 95 }; 96 97 98 thread_id 99 Thread::ID() const 100 { 101 return fID; 102 } 103 104 105 const char* 106 Thread::Name() const 107 { 108 return fName.String(); 109 } 110 111 112 addr_t* 113 Thread::Samples() const 114 { 115 return fSamples; 116 } 117 118 119 Team* 120 Thread::GetTeam() const 121 { 122 return fTeam; 123 } 124 125 126 ProfileResult* 127 Thread::GetProfileResult() const 128 { 129 return fProfileResult; 130 } 131 132 133 #endif // THREAD_H 134