xref: /haiku/src/bin/debug/profile/SummaryProfileResult.cpp (revision 342a1b221b5bb385410f758df2c625b70cafdd03)
1 /*
2  * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "SummaryProfileResult.h"
8 
9 #include <new>
10 
11 
12 // #pragma mark - SummaryImage
13 
14 
15 SummaryImage::SummaryImage(ImageProfileResult* result)
16 	:
17 	fResult(result)
18 {
19 	fResult->AcquireReference();
20 }
21 
22 
23 SummaryImage::~SummaryImage()
24 {
25 	fResult->ReleaseReference();
26 }
27 
28 
29 // #pragma mark - SummaryProfileResult
30 
31 
32 SummaryProfileResult::SummaryProfileResult(ProfileResult* result)
33 	:
34 	fResult(result),
35 	fNextImageID(1)
36 {
37 	fResult->AcquireReference();
38 }
39 
40 
41 SummaryProfileResult::~SummaryProfileResult()
42 {
43 	fResult->ReleaseReference();
44 }
45 
46 
47 void
48 SummaryProfileResult::SetInterval(bigtime_t interval)
49 {
50 	ProfileResult::SetInterval(interval);
51 	fResult->SetInterval(interval);
52 }
53 
54 
55 status_t
56 SummaryProfileResult::Init(ProfiledEntity* entity)
57 {
58 	status_t error = ProfileResult::Init(entity);
59 	if (error != B_OK)
60 		return error;
61 
62 	error = fImages.Init();
63 	if (error != B_OK)
64 		return error;
65 
66 	return B_OK;
67 }
68 
69 
70 void
71 SummaryProfileResult::AddSamples(ImageProfileResultContainer* container,
72 	addr_t* samples, int32 sampleCount)
73 {
74 	fResult->AddSamples(container, samples, sampleCount);
75 }
76 
77 
78 void
79 SummaryProfileResult::AddExpectedTicks(int32 expected)
80 {
81 	fResult->AddExpectedTicks(expected);
82 }
83 
84 
85 void
86 SummaryProfileResult::AddDroppedTicks(int32 dropped)
87 {
88 	fResult->AddDroppedTicks(dropped);
89 }
90 
91 
92 void
93 SummaryProfileResult::PrintResults(ImageProfileResultContainer* container)
94 {
95 	// This is called for individual threads. We only print results in
96 	// PrintSummaryResults(), though.
97 }
98 
99 
100 void
101 SummaryProfileResult::PrintSummaryResults()
102 {
103 	fResult->PrintResults(this);
104 }
105 
106 
107 status_t
108 SummaryProfileResult::GetImageProfileResult(SharedImage* image, image_id id,
109 	ImageProfileResult*& _imageResult)
110 {
111 	// Check whether we do already know the image.
112 	SummaryImage* summaryImage = fImages.Lookup(image);
113 	if (summaryImage == NULL) {
114 		// nope, create it
115 		ImageProfileResult* imageResult;
116 		status_t error = fResult->GetImageProfileResult(image, fNextImageID++,
117 			imageResult);
118 		if (error != B_OK)
119 			return error;
120 
121 		BReference<ImageProfileResult> imageResultReference(imageResult, true);
122 
123 		summaryImage = new(std::nothrow) SummaryImage(imageResult);
124 		if (summaryImage == NULL)
125 			return B_NO_MEMORY;
126 
127 		fImages.Insert(summaryImage);
128 	}
129 
130 	_imageResult = summaryImage->Result();
131 	_imageResult->AcquireReference();
132 
133 	return B_OK;
134 }
135 
136 
137 int32
138 SummaryProfileResult::CountImages() const
139 {
140 	return fImages.CountElements();
141 }
142 
143 
144 ImageProfileResult*
145 SummaryProfileResult::VisitImages(Visitor& visitor) const
146 {
147 	for (ImageTable::Iterator it = fImages.GetIterator();
148 			SummaryImage* image = it.Next();) {
149 		if (visitor.VisitImage(image->Result()))
150 			return image->Result();
151 	}
152 
153 	return NULL;
154 }
155 
156 
157 ImageProfileResult*
158 SummaryProfileResult::FindImage(addr_t address, addr_t& _loadDelta) const
159 {
160 	// We cannot and don't need to implement this. It's only relevant for
161 	// AddSamples(), where we use the caller's container implementation.
162 	return NULL;
163 }
164