vfs: check userland buffers before reading them.
[haiku.git] / src / bin / debug / profile / SummaryProfileResult.cpp
blob40f19fcc25ef39af30adb406bc6f98d5bc5021ac
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "SummaryProfileResult.h"
9 #include <new>
12 // #pragma mark - SummaryImage
15 SummaryImage::SummaryImage(ImageProfileResult* result)
17 fResult(result)
19 fResult->AcquireReference();
23 SummaryImage::~SummaryImage()
25 fResult->ReleaseReference();
29 // #pragma mark - SummaryProfileResult
32 SummaryProfileResult::SummaryProfileResult(ProfileResult* result)
34 fResult(result),
35 fNextImageID(1)
37 fResult->AcquireReference();
41 SummaryProfileResult::~SummaryProfileResult()
43 fResult->ReleaseReference();
47 void
48 SummaryProfileResult::SetInterval(bigtime_t interval)
50 ProfileResult::SetInterval(interval);
51 fResult->SetInterval(interval);
55 status_t
56 SummaryProfileResult::Init(ProfiledEntity* entity)
58 status_t error = ProfileResult::Init(entity);
59 if (error != B_OK)
60 return error;
62 error = fImages.Init();
63 if (error != B_OK)
64 return error;
66 return B_OK;
70 void
71 SummaryProfileResult::AddSamples(ImageProfileResultContainer* container,
72 addr_t* samples, int32 sampleCount)
74 fResult->AddSamples(container, samples, sampleCount);
78 void
79 SummaryProfileResult::AddDroppedTicks(int32 dropped)
81 fResult->AddDroppedTicks(dropped);
85 void
86 SummaryProfileResult::PrintResults(ImageProfileResultContainer* container)
88 // This is called for individual threads. We only print results in
89 // PrintSummaryResults(), though.
93 void
94 SummaryProfileResult::PrintSummaryResults()
96 fResult->PrintResults(this);
100 status_t
101 SummaryProfileResult::GetImageProfileResult(SharedImage* image, image_id id,
102 ImageProfileResult*& _imageResult)
104 // Check whether we do already know the image.
105 SummaryImage* summaryImage = fImages.Lookup(image);
106 if (summaryImage == NULL) {
107 // nope, create it
108 ImageProfileResult* imageResult;
109 status_t error = fResult->GetImageProfileResult(image, fNextImageID++,
110 imageResult);
111 if (error != B_OK)
112 return error;
114 BReference<ImageProfileResult> imageResultReference(imageResult, true);
116 summaryImage = new(std::nothrow) SummaryImage(imageResult);
117 if (summaryImage == NULL)
118 return B_NO_MEMORY;
120 fImages.Insert(summaryImage);
123 _imageResult = summaryImage->Result();
124 _imageResult->AcquireReference();
126 return B_OK;
130 int32
131 SummaryProfileResult::CountImages() const
133 return fImages.CountElements();
137 ImageProfileResult*
138 SummaryProfileResult::VisitImages(Visitor& visitor) const
140 for (ImageTable::Iterator it = fImages.GetIterator();
141 SummaryImage* image = it.Next();) {
142 if (visitor.VisitImage(image->Result()))
143 return image->Result();
146 return NULL;
150 ImageProfileResult*
151 SummaryProfileResult::FindImage(addr_t address, addr_t& _loadDelta) const
153 // We cannot and don't need to implement this. It's only relevant for
154 // AddSamples(), where we use the caller's container implementation.
155 return NULL;