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
GetImage()27 Image* GetImage() const { return fImage; }
Result()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(Team* team, thread_id threadID,
40 const char* name, bigtime_t initialCPUTime);
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 UpdateCPUTime(bigtime_t time);
70
71 void PrintResults();
72
73 private:
74 typedef DoublyLinkedList<ThreadImage> ImageList;
75
76 private:
77 // ImageProfileResultContainer
78 virtual int32 CountImages() const;
79 virtual ImageProfileResult* VisitImages(Visitor& visitor) const;
80 virtual ImageProfileResult* FindImage(addr_t address,
81 addr_t& _loadDelta) const;
82
83 private:
84 void _SynchronizeImages(int32 event);
85
86 private:
87 ::Team* fTeam;
88 thread_id fID;
89 BString fName;
90 bigtime_t fLastCPUTime;
91 area_id fSampleArea;
92 addr_t* fSamples;
93 ProfileResult* fProfileResult;
94 ImageList fImages;
95 ImageList fNewImages;
96 ImageList fOldImages;
97 bool fLazyImages;
98 };
99
100
101 thread_id
ID()102 Thread::ID() const
103 {
104 return fID;
105 }
106
107
108 const char*
Name()109 Thread::Name() const
110 {
111 return fName.String();
112 }
113
114
115 addr_t*
Samples()116 Thread::Samples() const
117 {
118 return fSamples;
119 }
120
121
122 Team*
GetTeam()123 Thread::GetTeam() const
124 {
125 return fTeam;
126 }
127
128
129 ProfileResult*
GetProfileResult()130 Thread::GetProfileResult() const
131 {
132 return fProfileResult;
133 }
134
135
136 #endif // THREAD_H
137