xref: /haiku/src/bin/debug/profile/ProfileResult.h (revision 909af08f4328301fbdef1ffb41f566c3b5bec0c7)
1 /*
2  * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef PROFILE_RESULT_H
6 #define PROFILE_RESULT_H
7 
8 
9 #include <Referenceable.h>
10 
11 #include <util/DoublyLinkedList.h>
12 
13 #include "SharedImage.h"
14 
15 
16 class ProfiledEntity;
17 class Team;
18 
19 
20 class ImageProfileResult : public BReferenceable {
21 public:
22 								ImageProfileResult(SharedImage* image,
23 									image_id id);
24 	virtual						~ImageProfileResult();
25 
26 	virtual	status_t			Init();
27 
28 	inline	image_id			ID() const;
29 	inline	SharedImage*		GetImage() const;
30 
31 	inline	int64				TotalHits() const;
32 
33 protected:
34 			SharedImage*		fImage;
35 			int64				fTotalHits;
36 			image_id			fImageID;
37 };
38 
39 
40 class ImageProfileResultContainer {
41 public:
42 			class Visitor;
43 
44 
45 public:
46 	virtual						~ImageProfileResultContainer();
47 
48 	virtual	int32				CountImages() const = 0;
49 	virtual	ImageProfileResult*	VisitImages(Visitor& visitor) const = 0;
50 	virtual	ImageProfileResult*	FindImage(addr_t address,
51 									addr_t& _loadDelta) const = 0;
52 };
53 
54 
55 class ImageProfileResultContainer::Visitor {
56 public:
57 	virtual						~Visitor();
58 
59 	virtual	bool				VisitImage(ImageProfileResult* image) = 0;
60 };
61 
62 
63 class ProfileResult : public BReferenceable {
64 public:
65 								ProfileResult();
66 	virtual						~ProfileResult();
67 
68 	virtual	status_t			Init(ProfiledEntity* entity);
69 
70 			ProfiledEntity*		Entity() const	{ return fEntity; }
71 
72 	virtual	void				SetInterval(bigtime_t interval);
73 			bigtime_t			Interval() const { return fInterval; }
74 
75 	virtual	void				AddSamples(
76 									ImageProfileResultContainer* container,
77 									addr_t* samples,
78 									int32 sampleCount) = 0;
79 	virtual	void				AddExpectedTicks(int32 expected) = 0;
80 	virtual	void				AddDroppedTicks(int32 dropped) = 0;
81 	virtual	void				PrintResults(
82 									ImageProfileResultContainer* container) = 0;
83 
84 	virtual status_t			GetImageProfileResult(SharedImage* image,
85 									image_id id,
86 									ImageProfileResult*& _imageResult) = 0;
87 
88 protected:
89 			template<typename ImageProfileResultType>
90 			int32				GetHitImages(
91 									ImageProfileResultContainer* container,
92 									ImageProfileResultType** images) const;
93 
94 protected:
95 			ProfiledEntity*		fEntity;
96 			bigtime_t			fInterval;
97 };
98 
99 
100 // #pragma mark - ImageProfileResult
101 
102 
103 image_id
104 ImageProfileResult::ID() const
105 {
106 	return fImageID;
107 }
108 
109 
110 SharedImage*
111 ImageProfileResult::GetImage() const
112 {
113 	return fImage;
114 }
115 
116 
117 int64
118 ImageProfileResult::TotalHits() const
119 {
120 	return fTotalHits;
121 }
122 
123 
124 // #pragma mark - ProfileResult
125 
126 
127 template<typename ImageProfileResultType>
128 int32
129 ProfileResult::GetHitImages(ImageProfileResultContainer* container,
130 	ImageProfileResultType** images) const
131 {
132 	struct Visitor : ImageProfileResultContainer::Visitor {
133 		ImageProfileResultType**	images;
134 		int32						imageCount;
135 
136 		virtual bool VisitImage(ImageProfileResult* image)
137 		{
138 			if (image->TotalHits() > 0) {
139 				images[imageCount++]
140 					= static_cast<ImageProfileResultType*>(image);
141 			}
142 			return false;
143 		}
144 	} visitor;
145 
146 	visitor.images = images;
147 	visitor.imageCount = 0;
148 
149 	container->VisitImages(visitor);
150 
151 	return visitor.imageCount;
152 }
153 
154 
155 #endif	// PROFILE_RESULT_H
156