1120cfc62SIngo Weinhold /*
25fc675d5SIngo Weinhold * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3120cfc62SIngo Weinhold * Distributed under the terms of the MIT License.
4120cfc62SIngo Weinhold */
5120cfc62SIngo Weinhold #ifndef THREAD_H
6120cfc62SIngo Weinhold #define THREAD_H
7120cfc62SIngo Weinhold
8a39c92c2SIngo Weinhold
91b9d2885SIngo Weinhold #include <String.h>
101b9d2885SIngo Weinhold
11120cfc62SIngo Weinhold #include <util/DoublyLinkedList.h>
12120cfc62SIngo Weinhold
135fc675d5SIngo Weinhold #include "ProfiledEntity.h"
145fc675d5SIngo Weinhold #include "ProfileResult.h"
15120cfc62SIngo Weinhold
16120cfc62SIngo Weinhold
176a28c22fSIngo Weinhold class Image;
18120cfc62SIngo Weinhold class Team;
19120cfc62SIngo Weinhold
20120cfc62SIngo Weinhold
216a28c22fSIngo Weinhold class ThreadImage : public DoublyLinkedListLinkImpl<ThreadImage> {
226a28c22fSIngo Weinhold public:
236a28c22fSIngo Weinhold ThreadImage(Image* image,
246a28c22fSIngo Weinhold ImageProfileResult* result);
256a28c22fSIngo Weinhold ~ThreadImage();
266a28c22fSIngo Weinhold
GetImage()276a28c22fSIngo Weinhold Image* GetImage() const { return fImage; }
Result()286a28c22fSIngo Weinhold ImageProfileResult* Result() const { return fResult; }
296a28c22fSIngo Weinhold
306a28c22fSIngo Weinhold private:
316a28c22fSIngo Weinhold Image* fImage;
326a28c22fSIngo Weinhold ImageProfileResult* fResult;
336a28c22fSIngo Weinhold };
346a28c22fSIngo Weinhold
356a28c22fSIngo Weinhold
366a28c22fSIngo Weinhold class Thread : public ProfiledEntity, public DoublyLinkedListLinkImpl<Thread>,
376a28c22fSIngo Weinhold private ImageProfileResultContainer {
38120cfc62SIngo Weinhold public:
39*2813fd13SAugustin Cavalier Thread(Team* team, thread_id threadID,
40*2813fd13SAugustin Cavalier const char* name, bigtime_t initialCPUTime);
415fc675d5SIngo Weinhold virtual ~Thread();
42120cfc62SIngo Weinhold
43120cfc62SIngo Weinhold inline thread_id ID() const;
44120cfc62SIngo Weinhold inline const char* Name() const;
45120cfc62SIngo Weinhold inline addr_t* Samples() const;
46120cfc62SIngo Weinhold inline Team* GetTeam() const;
47120cfc62SIngo Weinhold
485fc675d5SIngo Weinhold virtual int32 EntityID() const;
495fc675d5SIngo Weinhold virtual const char* EntityName() const;
505fc675d5SIngo Weinhold virtual const char* EntityType() const;
515fc675d5SIngo Weinhold
525fc675d5SIngo Weinhold inline ProfileResult* GetProfileResult() const;
535fc675d5SIngo Weinhold void SetProfileResult(ProfileResult* result);
54ed2fc873SIngo Weinhold
551b9d2885SIngo Weinhold void UpdateInfo(const char* name);
56120cfc62SIngo Weinhold
57120cfc62SIngo Weinhold void SetSampleArea(area_id area, addr_t* samples);
58120cfc62SIngo Weinhold void SetInterval(bigtime_t interval);
59120cfc62SIngo Weinhold
606a28c22fSIngo Weinhold void SetLazyImages(bool lazy);
616a28c22fSIngo Weinhold
626a28c22fSIngo Weinhold status_t AddImage(Image* image);
636a28c22fSIngo Weinhold void RemoveImage(Image* image);
64120cfc62SIngo Weinhold
65120cfc62SIngo Weinhold void AddSamples(int32 count, int32 dropped,
66120cfc62SIngo Weinhold int32 stackDepth, bool variableStackDepth,
67120cfc62SIngo Weinhold int32 event);
680f379156SIngo Weinhold void AddSamples(addr_t* samples, int32 sampleCount);
69*2813fd13SAugustin Cavalier void UpdateCPUTime(bigtime_t time);
70*2813fd13SAugustin Cavalier
716a28c22fSIngo Weinhold void PrintResults();
726a28c22fSIngo Weinhold
736a28c22fSIngo Weinhold private:
746a28c22fSIngo Weinhold typedef DoublyLinkedList<ThreadImage> ImageList;
756a28c22fSIngo Weinhold
766a28c22fSIngo Weinhold private:
776a28c22fSIngo Weinhold // ImageProfileResultContainer
786a28c22fSIngo Weinhold virtual int32 CountImages() const;
796a28c22fSIngo Weinhold virtual ImageProfileResult* VisitImages(Visitor& visitor) const;
806a28c22fSIngo Weinhold virtual ImageProfileResult* FindImage(addr_t address,
816a28c22fSIngo Weinhold addr_t& _loadDelta) const;
826a28c22fSIngo Weinhold
836a28c22fSIngo Weinhold private:
846a28c22fSIngo Weinhold void _SynchronizeImages(int32 event);
85120cfc62SIngo Weinhold
86120cfc62SIngo Weinhold private:
87*2813fd13SAugustin Cavalier ::Team* fTeam;
881b9d2885SIngo Weinhold thread_id fID;
891b9d2885SIngo Weinhold BString fName;
90*2813fd13SAugustin Cavalier bigtime_t fLastCPUTime;
91120cfc62SIngo Weinhold area_id fSampleArea;
92120cfc62SIngo Weinhold addr_t* fSamples;
935fc675d5SIngo Weinhold ProfileResult* fProfileResult;
946a28c22fSIngo Weinhold ImageList fImages;
956a28c22fSIngo Weinhold ImageList fNewImages;
966a28c22fSIngo Weinhold ImageList fOldImages;
976a28c22fSIngo Weinhold bool fLazyImages;
98ed2fc873SIngo Weinhold };
99ed2fc873SIngo Weinhold
100ed2fc873SIngo Weinhold
101120cfc62SIngo Weinhold thread_id
ID()102120cfc62SIngo Weinhold Thread::ID() const
103120cfc62SIngo Weinhold {
1041b9d2885SIngo Weinhold return fID;
105120cfc62SIngo Weinhold }
106120cfc62SIngo Weinhold
107120cfc62SIngo Weinhold
108120cfc62SIngo Weinhold const char*
Name()109120cfc62SIngo Weinhold Thread::Name() const
110120cfc62SIngo Weinhold {
1111b9d2885SIngo Weinhold return fName.String();
112120cfc62SIngo Weinhold }
113120cfc62SIngo Weinhold
114120cfc62SIngo Weinhold
115120cfc62SIngo Weinhold addr_t*
Samples()116120cfc62SIngo Weinhold Thread::Samples() const
117120cfc62SIngo Weinhold {
118120cfc62SIngo Weinhold return fSamples;
119120cfc62SIngo Weinhold }
120120cfc62SIngo Weinhold
121120cfc62SIngo Weinhold
122120cfc62SIngo Weinhold Team*
GetTeam()123120cfc62SIngo Weinhold Thread::GetTeam() const
124120cfc62SIngo Weinhold {
125120cfc62SIngo Weinhold return fTeam;
126120cfc62SIngo Weinhold }
127120cfc62SIngo Weinhold
128120cfc62SIngo Weinhold
1295fc675d5SIngo Weinhold ProfileResult*
GetProfileResult()1305fc675d5SIngo Weinhold Thread::GetProfileResult() const
131ed2fc873SIngo Weinhold {
132ed2fc873SIngo Weinhold return fProfileResult;
133ed2fc873SIngo Weinhold }
134ed2fc873SIngo Weinhold
135ed2fc873SIngo Weinhold
136120cfc62SIngo Weinhold #endif // THREAD_H
137