2 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
12 #include <debug_support.h>
14 #include "debug_utils.h"
21 // #pragma mark - ThreadImage
24 ThreadImage::ThreadImage(Image
* image
, ImageProfileResult
* result
)
29 fImage
->AcquireReference();
30 fResult
->AcquireReference();
34 ThreadImage::~ThreadImage()
36 fImage
->ReleaseReference();
37 fResult
->ReleaseReference();
41 // #pragma mark - ThreadI
44 Thread::Thread(thread_id threadID
, const char* name
, Team
* team
)
54 fTeam
->AcquireReference();
61 delete_area(fSampleArea
);
63 if (fProfileResult
!= NULL
)
64 fProfileResult
->ReleaseReference();
66 while (ThreadImage
* image
= fImages
.RemoveHead())
68 while (ThreadImage
* image
= fOldImages
.RemoveHead())
71 fTeam
->ReleaseReference();
76 Thread::EntityID() const
83 Thread::EntityName() const
90 Thread::EntityType() const
97 Thread::SetProfileResult(ProfileResult
* result
)
99 ProfileResult
* oldResult
= fProfileResult
;
101 fProfileResult
= result
;
102 if (fProfileResult
!= NULL
)
103 fProfileResult
->AcquireReference();
106 oldResult
->ReleaseReference();
111 Thread::UpdateInfo(const char* name
)
118 Thread::SetSampleArea(area_id area
, addr_t
* samples
)
126 Thread::SetInterval(bigtime_t interval
)
128 fProfileResult
->SetInterval(interval
);
133 Thread::SetLazyImages(bool lazy
)
140 Thread::AddImage(Image
* image
)
142 ImageProfileResult
* result
;
143 status_t error
= fProfileResult
->GetImageProfileResult(
144 image
->GetSharedImage(), image
->ID(), result
);
148 BReference
<ImageProfileResult
> resultReference(result
, true);
150 ThreadImage
* threadImage
= new(std::nothrow
) ThreadImage(image
, result
);
151 if (threadImage
== NULL
)
155 fNewImages
.Add(threadImage
);
157 fImages
.Add(threadImage
);
164 Thread::RemoveImage(Image
* image
)
166 ImageList::Iterator it
= fImages
.GetIterator();
167 while (ThreadImage
* threadImage
= it
.Next()) {
168 if (threadImage
->GetImage() == image
) {
170 if (threadImage
->Result()->TotalHits() > 0)
171 fOldImages
.Add(threadImage
);
181 Thread::AddSamples(int32 count
, int32 dropped
, int32 stackDepth
,
182 bool variableStackDepth
, int32 event
)
184 _SynchronizeImages(event
);
186 if (variableStackDepth
) {
187 addr_t
* samples
= fSamples
;
190 addr_t sampleCount
= *(samples
++);
192 if (sampleCount
>= B_DEBUG_PROFILE_EVENT_BASE
) {
193 int32 eventParameterCount
194 = sampleCount
& B_DEBUG_PROFILE_EVENT_PARAMETER_MASK
;
195 if (sampleCount
== B_DEBUG_PROFILE_IMAGE_EVENT
) {
196 _SynchronizeImages((int32
)samples
[0]);
198 fprintf(stderr
, "unknown profile event: %#lx\n",
202 samples
+= eventParameterCount
;
203 count
-= eventParameterCount
+ 1;
207 fProfileResult
->AddSamples(this, samples
, sampleCount
);
209 samples
+= sampleCount
;
210 count
-= sampleCount
+ 1;
213 count
= count
/ stackDepth
* stackDepth
;
215 for (int32 i
= 0; i
< count
; i
+= stackDepth
)
216 fProfileResult
->AddSamples(this, fSamples
+ i
, stackDepth
);
219 fProfileResult
->AddDroppedTicks(dropped
);
224 Thread::AddSamples(addr_t
* samples
, int32 sampleCount
)
226 fProfileResult
->AddSamples(this, samples
, sampleCount
);
231 Thread::PrintResults()
233 fProfileResult
->PrintResults(this);
238 Thread::CountImages() const
240 return fImages
.Count() + fOldImages
.Count();
245 Thread::VisitImages(Visitor
& visitor
) const
247 ImageList::ConstIterator it
= fOldImages
.GetIterator();
248 while (ThreadImage
* image
= it
.Next()) {
249 if (visitor
.VisitImage(image
->Result()))
250 return image
->Result();
253 it
= fImages
.GetIterator();
254 while (ThreadImage
* image
= it
.Next()) {
255 if (visitor
.VisitImage(image
->Result()))
256 return image
->Result();
264 Thread::FindImage(addr_t address
, addr_t
& _loadDelta
) const
266 ImageList::ConstIterator it
= fImages
.GetIterator();
267 while (ThreadImage
* image
= it
.Next()) {
268 if (image
->GetImage()->ContainsAddress(address
)) {
269 _loadDelta
= image
->GetImage()->LoadDelta();
270 return image
->Result();
278 Thread::_SynchronizeImages(int32 event
)
280 // remove obsolete images
281 ImageList::Iterator it
= fImages
.GetIterator();
282 while (ThreadImage
* image
= it
.Next()) {
283 int32 deleted
= image
->GetImage()->DeletionEvent();
284 if (deleted
>= 0 && event
>= deleted
) {
286 if (image
->Result()->TotalHits() > 0)
287 fOldImages
.Add(image
);
294 it
= fNewImages
.GetIterator();
295 while (ThreadImage
* image
= it
.Next()) {
296 if (image
->GetImage()->CreationEvent() <= event
) {
298 int32 deleted
= image
->GetImage()->DeletionEvent();
299 if (deleted
>= 0 && event
>= deleted
) {
300 // image already deleted