xref: /haiku/src/bin/debug/profile/ProfileResult.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
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 
74 	virtual	void				AddSamples(
75 									ImageProfileResultContainer* container,
76 									addr_t* samples,
77 									int32 sampleCount) = 0;
78 	virtual	void				AddDroppedTicks(int32 dropped) = 0;
79 	virtual	void				PrintResults(
80 									ImageProfileResultContainer* container) = 0;
81 
82 	virtual status_t			GetImageProfileResult(SharedImage* image,
83 									image_id id,
84 									ImageProfileResult*& _imageResult) = 0;
85 
86 protected:
87 			template<typename ImageProfileResultType>
88 			int32				GetHitImages(
89 									ImageProfileResultContainer* container,
90 									ImageProfileResultType** images) const;
91 
92 protected:
93 			ProfiledEntity*		fEntity;
94 			bigtime_t			fInterval;
95 };
96 
97 
98 // #pragma mark - ImageProfileResult
99 
100 
101 image_id
102 ImageProfileResult::ID() const
103 {
104 	return fImageID;
105 }
106 
107 
108 SharedImage*
109 ImageProfileResult::GetImage() const
110 {
111 	return fImage;
112 }
113 
114 
115 int64
116 ImageProfileResult::TotalHits() const
117 {
118 	return fTotalHits;
119 }
120 
121 
122 // #pragma mark - ProfileResult
123 
124 
125 template<typename ImageProfileResultType>
126 int32
127 ProfileResult::GetHitImages(ImageProfileResultContainer* container,
128 	ImageProfileResultType** images) const
129 {
130 	struct Visitor : ImageProfileResultContainer::Visitor {
131 		ImageProfileResultType**	images;
132 		int32						imageCount;
133 
134 		virtual bool VisitImage(ImageProfileResult* image)
135 		{
136 			if (image->TotalHits() > 0) {
137 				images[imageCount++]
138 					= static_cast<ImageProfileResultType*>(image);
139 			}
140 			return false;
141 		}
142 	} visitor;
143 
144 	visitor.images = images;
145 	visitor.imageCount = 0;
146 
147 	container->VisitImages(visitor);
148 
149 	return visitor.imageCount;
150 }
151 
152 
153 #endif	// PROFILE_RESULT_H
154