Author: bonefish Date: 2010-02-21 18:16:59 +0100 (Sun, 21 Feb 2010) New Revision: 35556 Changeset: http://dev.haiku-os.org/changeset/35556/haiku Modified: haiku/trunk/src/bin/debug/profile/BasicProfileResult.cpp haiku/trunk/src/bin/debug/profile/BasicProfileResult.h haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.cpp haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.h haiku/trunk/src/bin/debug/profile/ProfileResult.cpp haiku/trunk/src/bin/debug/profile/ProfileResult.h haiku/trunk/src/bin/debug/profile/Team.cpp haiku/trunk/src/bin/debug/profile/Team.h haiku/trunk/src/bin/debug/profile/Thread.cpp haiku/trunk/src/bin/debug/profile/Thread.h Log: More refactoring: * Renamed *ProfileResultImage to *ImageProfileResult. * Separated the image result management from the *ProfileResult classes: - The general per-thread image management functionality does now live in Thread. - Introduced interface ImageProfileResultContainer which is implemented by Thread. An instance is passed to ProfileResult::AddSamples()/PrintResult(). * Made *ProfileResultImage independent of Image. The dependency is now to SharedImage only. Modified: haiku/trunk/src/bin/debug/profile/BasicProfileResult.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile/BasicProfileResult.cpp 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/BasicProfileResult.cpp 2010-02-21 17:16:59 UTC (rev 35556) @@ -27,25 +27,26 @@ }; -// #pragma mark - BasicProfileResultImage +// #pragma mark - BasicImageProfileResult -BasicProfileResultImage::BasicProfileResultImage(Image* image) +BasicImageProfileResult::BasicImageProfileResult(SharedImage* image, + image_id id) : - ProfileResultImage(image), + ImageProfileResult(image, id), fSymbolHits(NULL), fUnknownHits(0) { } -BasicProfileResultImage::~BasicProfileResultImage() +BasicImageProfileResult::~BasicImageProfileResult() { } status_t -BasicProfileResultImage::Init() +BasicImageProfileResult::Init() { int32 symbolCount = fImage->SymbolCount(); fSymbolHits = new(std::nothrow) int64[symbolCount]; @@ -59,7 +60,7 @@ bool -BasicProfileResultImage::AddHit(addr_t address) +BasicImageProfileResult::AddHit(addr_t address) { int32 symbolIndex = fImage->FindSymbol(address); if (symbolIndex < 0) @@ -73,7 +74,7 @@ void -BasicProfileResultImage::AddUnknownHit() +BasicImageProfileResult::AddUnknownHit() { fUnknownHits++; fTotalHits++; @@ -81,28 +82,28 @@ void -BasicProfileResultImage::AddSymbolHit(int32 symbolIndex) +BasicImageProfileResult::AddSymbolHit(int32 symbolIndex) { fSymbolHits[symbolIndex]++; } void -BasicProfileResultImage::AddImageHit() +BasicImageProfileResult::AddImageHit() { fTotalHits++; } const int64* -BasicProfileResultImage::SymbolHits() const +BasicImageProfileResult::SymbolHits() const { return fSymbolHits; } int64 -BasicProfileResultImage::UnknownHits() const +BasicImageProfileResult::UnknownHits() const { return fUnknownHits; } @@ -129,16 +130,16 @@ void -BasicProfileResult::PrintResults() +BasicProfileResult::PrintResults(ImageProfileResultContainer* container) { // get hit images - BasicProfileResultImage* images[fOldImages.Count() + fImages.Count()]; - int32 imageCount = GetHitImages(images); + BasicImageProfileResult* images[container->CountImages()]; + int32 imageCount = GetHitImages(container, images); // count symbols int32 symbolCount = 0; for (int32 k = 0; k < imageCount; k++) { - BasicProfileResultImage* image = images[k]; + BasicImageProfileResult* image = images[k]; if (image->TotalHits() > image->UnknownHits()) symbolCount += image->GetImage()->SymbolCount(); } @@ -148,7 +149,7 @@ int32 hitSymbolCount = 0; for (int32 k = 0; k < imageCount; k++) { - BasicProfileResultImage* image = images[k]; + BasicImageProfileResult* image = images[k]; if (image->TotalHits() > image->UnknownHits()) { Symbol** symbols = image->GetImage()->Symbols(); const int64* symbolHits = image->SymbolHits(); @@ -193,10 +194,10 @@ fprintf(gOptions.output, " ---------------------------------------" "---------------------------------------\n"); for (int32 k = 0; k < imageCount; k++) { - BasicProfileResultImage* image = images[k]; + BasicImageProfileResult* image = images[k]; fprintf(gOptions.output, " %10lld %10lld %7ld %s\n", image->TotalHits(), image->UnknownHits(), - image->GetImage()->ID(), image->GetImage()->Name()); + image->ID(), image->GetImage()->Name()); } } @@ -219,10 +220,10 @@ } -BasicProfileResultImage* -BasicProfileResult::CreateProfileResultImage(Image* image) +ImageProfileResult* +BasicProfileResult::CreateImageProfileResult(SharedImage* image, image_id id) { - return new(std::nothrow) BasicProfileResultImage(image); + return new(std::nothrow) BasicImageProfileResult(image, id); } @@ -230,7 +231,8 @@ void -InclusiveProfileResult::AddSamples(addr_t* samples, int32 sampleCount) +InclusiveProfileResult::AddSamples(ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount) { // Sort the samples. This way hits of the same symbol are // successive and we can avoid incrementing the hit count of the @@ -238,15 +240,17 @@ std::sort(samples, samples + sampleCount); int32 unknownSamples = 0; - BasicProfileResultImage* previousImage = NULL; + BasicImageProfileResult* previousImage = NULL; int32 previousSymbol = -1; for (int32 i = 0; i < sampleCount; i++) { addr_t address = samples[i]; - BasicProfileResultImage* image = FindImage(address); + addr_t loadDelta; + BasicImageProfileResult* image = static_cast<BasicImageProfileResult*>( + container->FindImage(address, loadDelta)); int32 symbol = -1; if (image != NULL) { - symbol = image->GetImage()->FindSymbol(address); + symbol = image->GetImage()->FindSymbol(address - loadDelta); if (symbol < 0) { // TODO: Count unknown image hits? } else if (image != previousImage || symbol != previousSymbol) @@ -273,18 +277,21 @@ void -ExclusiveProfileResult::AddSamples(addr_t* samples, int32 sampleCount) +ExclusiveProfileResult::AddSamples(ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount) { - BasicProfileResultImage* image = NULL; + BasicImageProfileResult* image = NULL; // the image in which we hit a symbol - BasicProfileResultImage* firstImage = NULL; + BasicImageProfileResult* firstImage = NULL; // the first image we hit, != image if no symbol was hit for (int32 k = 0; k < sampleCount; k++) { addr_t address = samples[k]; - image = FindImage(address); + addr_t loadDelta; + image = static_cast<BasicImageProfileResult*>( + container->FindImage(address, loadDelta)); if (image != NULL) { - if (image->AddHit(address)) + if (image->AddHit(address - loadDelta)) break; if (firstImage == NULL) firstImage = image; Modified: haiku/trunk/src/bin/debug/profile/BasicProfileResult.h =================================================================== --- haiku/trunk/src/bin/debug/profile/BasicProfileResult.h 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/BasicProfileResult.h 2010-02-21 17:16:59 UTC (rev 35556) @@ -9,11 +9,12 @@ #include "ProfileResult.h" -class BasicProfileResultImage : public ProfileResultImage, - public DoublyLinkedListLinkImpl<BasicProfileResultImage> { +class BasicImageProfileResult : public ImageProfileResult, + public DoublyLinkedListLinkImpl<BasicImageProfileResult> { public: - BasicProfileResultImage(Image* image); - virtual ~BasicProfileResultImage(); + BasicImageProfileResult(SharedImage* image, + image_id id); + virtual ~BasicImageProfileResult(); virtual status_t Init(); @@ -31,15 +32,16 @@ }; -class BasicProfileResult - : public AbstractProfileResult<BasicProfileResultImage> { +class BasicProfileResult : public ProfileResult { public: BasicProfileResult(); virtual void AddDroppedTicks(int32 dropped); - virtual void PrintResults(); + virtual void PrintResults( + ImageProfileResultContainer* container); - virtual BasicProfileResultImage* CreateProfileResultImage(Image* image); + virtual ImageProfileResult* CreateImageProfileResult(SharedImage* image, + image_id id); protected: int64 fTotalTicks; @@ -51,15 +53,17 @@ class InclusiveProfileResult : public BasicProfileResult { public: - virtual void AddSamples(addr_t* samples, - int32 sampleCount); + virtual void AddSamples( + ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount); }; class ExclusiveProfileResult : public BasicProfileResult { public: - virtual void AddSamples(addr_t* samples, - int32 sampleCount); + virtual void AddSamples( + ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount); }; Modified: haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.cpp 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.cpp 2010-02-21 17:16:59 UTC (rev 35556) @@ -1,5 +1,5 @@ /* - * Copyright 2010, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@xxxxxxx * Distributed under the terms of the MIT License. */ @@ -16,19 +16,20 @@ #include "ProfiledEntity.h" -// #pragma mark - CallgrindProfileResultImage +// #pragma mark - CallgrindImageProfileResult -CallgrindProfileResultImage::CallgrindProfileResultImage(Image* image) +CallgrindImageProfileResult::CallgrindImageProfileResult(SharedImage* image, + image_id id) : - ProfileResultImage(image), + ImageProfileResult(image, id), fFunctions(NULL), fOutputIndex(0) { } -CallgrindProfileResultImage::~CallgrindProfileResultImage() +CallgrindImageProfileResult::~CallgrindImageProfileResult() { int32 symbolCount = fImage->SymbolCount(); for (int32 i = 0; i < symbolCount; i++) { @@ -44,7 +45,7 @@ status_t -CallgrindProfileResultImage::Init() +CallgrindImageProfileResult::Init() { int32 symbolCount = fImage->SymbolCount(); fFunctions = new(std::nothrow) CallgrindFunction[symbolCount]; @@ -58,8 +59,8 @@ void -CallgrindProfileResultImage::AddSymbolHit(int32 symbolIndex, - CallgrindProfileResultImage* calledImage, int32 calledSymbol) +CallgrindImageProfileResult::AddSymbolHit(int32 symbolIndex, + CallgrindImageProfileResult* calledImage, int32 calledSymbol) { fTotalHits++; @@ -94,21 +95,21 @@ CallgrindFunction* -CallgrindProfileResultImage::Functions() const +CallgrindImageProfileResult::Functions() const { return fFunctions; } int32 -CallgrindProfileResultImage::OutputIndex() const +CallgrindImageProfileResult::OutputIndex() const { return fOutputIndex; } void -CallgrindProfileResultImage::SetOutputIndex(int32 index) +CallgrindImageProfileResult::SetOutputIndex(int32 index) { fOutputIndex = index; } @@ -129,19 +130,23 @@ void -CallgrindProfileResult::AddSamples(addr_t* samples, int32 sampleCount) +CallgrindProfileResult::AddSamples(ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount) { int32 unknownSamples = 0; - CallgrindProfileResultImage* previousImage = NULL; + CallgrindImageProfileResult* previousImage = NULL; int32 previousSymbol = -1; // TODO: That probably doesn't work with recursive functions. for (int32 i = 0; i < sampleCount; i++) { addr_t address = samples[i]; - CallgrindProfileResultImage* image = FindImage(address); + addr_t loadDelta; + CallgrindImageProfileResult* image + = static_cast<CallgrindImageProfileResult*>( + container->FindImage(address, loadDelta)); int32 symbol = -1; if (image != NULL) { - symbol = image->GetImage()->FindSymbol(address); + symbol = image->GetImage()->FindSymbol(address - loadDelta); if (symbol >= 0) { image->AddSymbolHit(symbol, previousImage, previousSymbol); previousImage = image; @@ -166,7 +171,7 @@ void -CallgrindProfileResult::PrintResults() +CallgrindProfileResult::PrintResults(ImageProfileResultContainer* container) { // create output file @@ -206,11 +211,11 @@ fprintf(out, "summary: %lld %lld\n", fTotalTicks, fTotalTicks * fInterval); // get hit images - CallgrindProfileResultImage* images[fOldImages.Count() + fImages.Count()]; - int32 imageCount = GetHitImages(images); + CallgrindImageProfileResult* images[container->CountImages()]; + int32 imageCount = GetHitImages(container, images); for (int32 i = 0; i < imageCount; i++) { - CallgrindProfileResultImage* image = images[i]; + CallgrindImageProfileResult* image = images[i]; CallgrindFunction* functions = image->Functions(); int32 imageSymbolCount = image->GetImage()->SymbolCount(); @@ -257,16 +262,17 @@ } -CallgrindProfileResultImage* -CallgrindProfileResult::CreateProfileResultImage(Image* image) +ImageProfileResult* +CallgrindProfileResult::CreateImageProfileResult(SharedImage* image, + image_id id) { - return new(std::nothrow) CallgrindProfileResultImage(image); + return new(std::nothrow) CallgrindImageProfileResult(image, id); } void CallgrindProfileResult::_PrintFunction(FILE* out, - CallgrindProfileResultImage* image, int32 functionIndex, bool called) + CallgrindImageProfileResult* image, int32 functionIndex, bool called) { if (image->OutputIndex() == 0) { // need to print the image name Modified: haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.h =================================================================== --- haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.h 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/CallgrindProfileResult.h 2010-02-21 17:16:59 UTC (rev 35556) @@ -11,16 +11,16 @@ #include "ProfileResult.h" -class CallgrindProfileResultImage; +class CallgrindImageProfileResult; struct CallgrindCalledFunction { CallgrindCalledFunction* next; - CallgrindProfileResultImage* image; + CallgrindImageProfileResult* image; int32 function; int64 hits; - CallgrindCalledFunction(CallgrindProfileResultImage* image, int32 function) + CallgrindCalledFunction(CallgrindImageProfileResult* image, int32 function) : next(NULL), image(image), @@ -39,16 +39,17 @@ }; -class CallgrindProfileResultImage : public ProfileResultImage, - public DoublyLinkedListLinkImpl<CallgrindProfileResultImage> { +class CallgrindImageProfileResult : public ImageProfileResult, + public DoublyLinkedListLinkImpl<CallgrindImageProfileResult> { public: - CallgrindProfileResultImage(Image* image); - virtual ~CallgrindProfileResultImage(); + CallgrindImageProfileResult(SharedImage* image, + image_id id); + virtual ~CallgrindImageProfileResult(); virtual status_t Init(); inline void AddSymbolHit(int32 symbolIndex, - CallgrindProfileResultImage* calledImage, + CallgrindImageProfileResult* calledImage, int32 calledSymbol); inline CallgrindFunction* Functions() const; @@ -62,21 +63,23 @@ }; -class CallgrindProfileResult - : public AbstractProfileResult<CallgrindProfileResultImage> { +class CallgrindProfileResult : public ProfileResult { public: CallgrindProfileResult(); - virtual void AddSamples(addr_t* samples, - int32 sampleCount); + virtual void AddSamples( + ImageProfileResultContainer* container, + addr_t* samples, int32 sampleCount); virtual void AddDroppedTicks(int32 dropped); - virtual void PrintResults(); + virtual void PrintResults( + ImageProfileResultContainer* container); - virtual CallgrindProfileResultImage* CreateProfileResultImage(Image* image); + virtual ImageProfileResult* CreateImageProfileResult(SharedImage* image, + image_id id); private: void _PrintFunction(FILE* out, - CallgrindProfileResultImage* image, + CallgrindImageProfileResult* image, int32 functionIndex, bool called); private: int64 fTotalTicks; Modified: haiku/trunk/src/bin/debug/profile/ProfileResult.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile/ProfileResult.cpp 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/ProfileResult.cpp 2010-02-21 17:16:59 UTC (rev 35556) @@ -7,26 +7,43 @@ #include "ProfileResult.h" -// #pragma mark - ProfileResultImage +// #pragma mark - ImageProfileResultContainer -ProfileResultImage::ProfileResultImage(Image* image) +ImageProfileResultContainer::~ImageProfileResultContainer() +{ +} + + +// #pragma mark - ImageProfileResultContainer::Visitor + + +ImageProfileResultContainer::Visitor::~Visitor() +{ +} + + +// #pragma mark - ImageProfileResult + + +ImageProfileResult::ImageProfileResult(SharedImage* image, image_id id) : fImage(image), - fTotalHits(0) + fTotalHits(0), + fImageID(id) { fImage->AddReference(); } -ProfileResultImage::~ProfileResultImage() +ImageProfileResult::~ImageProfileResult() { fImage->RemoveReference(); } status_t -ProfileResultImage::Init() +ImageProfileResult::Init() { return B_OK; } Modified: haiku/trunk/src/bin/debug/profile/ProfileResult.h =================================================================== --- haiku/trunk/src/bin/debug/profile/ProfileResult.h 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/ProfileResult.h 2010-02-21 17:16:59 UTC (rev 35556) @@ -8,258 +8,141 @@ #include <util/DoublyLinkedList.h> -#include "Image.h" +#include "SharedImage.h" class ProfiledEntity; class Team; -class ProfileResultImage { +class ImageProfileResult { public: - ProfileResultImage(Image* image); - virtual ~ProfileResultImage(); + ImageProfileResult(SharedImage* image, + image_id id); + virtual ~ImageProfileResult(); virtual status_t Init(); inline image_id ID() const; - inline Image* GetImage() const; + inline SharedImage* GetImage() const; - inline bool ContainsAddress(addr_t address) const; - inline int64 TotalHits() const; protected: - Image* fImage; + SharedImage* fImage; int64 fTotalHits; + image_id fImageID; }; -class ProfileResult { +class ImageProfileResultContainer { public: - ProfileResult(); - virtual ~ProfileResult(); + class Visitor; - virtual status_t Init(ProfiledEntity* entity); - void SetInterval(bigtime_t interval); +public: + virtual ~ImageProfileResultContainer(); - virtual void SetLazyImages(bool lazy) = 0; + virtual int32 CountImages() const = 0; + virtual ImageProfileResult* VisitImages(Visitor& visitor) const = 0; + virtual ImageProfileResult* FindImage(addr_t address, + addr_t& _loadDelta) const = 0; +}; - virtual status_t AddImage(Image* image) = 0; - virtual void RemoveImage(Image* image) = 0; - virtual void SynchronizeImages(int32 event) = 0; - virtual void AddSamples(addr_t* samples, - int32 sampleCount) = 0; - virtual void AddDroppedTicks(int32 dropped) = 0; - virtual void PrintResults() = 0; +class ImageProfileResultContainer::Visitor { +public: + virtual ~Visitor(); -protected: - ProfiledEntity* fEntity; - bigtime_t fInterval; + virtual bool VisitImage(ImageProfileResult* image) = 0; }; -template<typename ProfileResultImageType> -class AbstractProfileResult : public ProfileResult { +class ProfileResult { public: - AbstractProfileResult(); - virtual ~AbstractProfileResult(); + ProfileResult(); + virtual ~ProfileResult(); - virtual void SetLazyImages(bool lazy); + virtual status_t Init(ProfiledEntity* entity); - virtual status_t AddImage(Image* image); - virtual void RemoveImage(Image* image); - virtual void SynchronizeImages(int32 event); + void SetInterval(bigtime_t interval); - ProfileResultImageType* FindImage(addr_t address) const; - int32 GetHitImages( - ProfileResultImageType** images) const; + virtual void AddSamples( + ImageProfileResultContainer* container, + addr_t* samples, + int32 sampleCount) = 0; + virtual void AddDroppedTicks(int32 dropped) = 0; + virtual void PrintResults( + ImageProfileResultContainer* container) = 0; - virtual ProfileResultImageType* CreateProfileResultImage(Image* image) = 0; + virtual ImageProfileResult* CreateImageProfileResult(SharedImage* image, + image_id id) = 0; protected: - typedef DoublyLinkedList<ProfileResultImageType> ImageList; + template<typename ImageProfileResultType> + int32 GetHitImages( + ImageProfileResultContainer* container, + ImageProfileResultType** images) const; - ImageList fImages; - ImageList fNewImages; - ImageList fOldImages; - bool fLazyImages; +protected: + ProfiledEntity* fEntity; + bigtime_t fInterval; }; -// #pragma mark - +// #pragma mark - ImageProfileResult image_id -ProfileResultImage::ID() const +ImageProfileResult::ID() const { - return fImage->ID(); + return fImageID; } -bool -ProfileResultImage::ContainsAddress(addr_t address) const +SharedImage* +ImageProfileResult::GetImage() const { - return fImage->ContainsAddress(address); -} - - -Image* -ProfileResultImage::GetImage() const -{ return fImage; } int64 -ProfileResultImage::TotalHits() const +ImageProfileResult::TotalHits() const { return fTotalHits; } -// #pragma mark - AbstractProfileResult +// #pragma mark - ProfileResult -template<typename ProfileResultImageType> -AbstractProfileResult<ProfileResultImageType>::AbstractProfileResult() - : - fImages(), - fNewImages(), - fOldImages(), - fLazyImages(true) +template<typename ImageProfileResultType> +int32 +ProfileResult::GetHitImages(ImageProfileResultContainer* container, + ImageProfileResultType** images) const { -} + struct Visitor : ImageProfileResultContainer::Visitor { + ImageProfileResultType** images; + int32 imageCount; - -template<typename ProfileResultImageType> -AbstractProfileResult<ProfileResultImageType>::~AbstractProfileResult() -{ - while (ProfileResultImageType* image = fImages.RemoveHead()) - delete image; - while (ProfileResultImageType* image = fOldImages.RemoveHead()) - delete image; -} - - -template<typename ProfileResultImageType> -void -AbstractProfileResult<ProfileResultImageType>::SetLazyImages(bool lazy) -{ - fLazyImages = lazy; -} - - -template<typename ProfileResultImageType> -status_t -AbstractProfileResult<ProfileResultImageType>::AddImage(Image* image) -{ - ProfileResultImageType* resultImage = CreateProfileResultImage(image); - if (resultImage == NULL) - return B_NO_MEMORY; - - status_t error = resultImage->Init(); - if (error != B_OK) { - delete resultImage; - return error; - } - - if (fLazyImages) - fNewImages.Add(resultImage); - else - fImages.Add(resultImage); - - return B_OK; -} - - -template<typename ProfileResultImageType> -void -AbstractProfileResult<ProfileResultImageType>::RemoveImage(Image* image) -{ - typename ImageList::Iterator it = fImages.GetIterator(); - while (ProfileResultImageType* resultImage = it.Next()) { - if (resultImage->GetImage() == image) { - it.Remove(); - if (resultImage->TotalHits() > 0) - fOldImages.Add(resultImage); - else - delete resultImage; - break; + virtual bool VisitImage(ImageProfileResult* image) + { + if (image->TotalHits() > 0) { + images[imageCount++] + = static_cast<ImageProfileResultType*>(image); + } + return false; } - } -} + } visitor; + visitor.images = images; + visitor.imageCount = 0; -template<typename ProfileResultImageType> -void -AbstractProfileResult<ProfileResultImageType>::SynchronizeImages(int32 event) -{ - // remove obsolete images - typename ImageList::Iterator it = fImages.GetIterator(); - while (ProfileResultImageType* image = it.Next()) { - int32 deleted = image->GetImage()->DeletionEvent(); - if (deleted >= 0 && event >= deleted) { - it.Remove(); - if (image->TotalHits() > 0) - fOldImages.Add(image); - else - delete image; - } - } + container->VisitImages(visitor); - // add new images - it = fNewImages.GetIterator(); - while (ProfileResultImageType* image = it.Next()) { - if (image->GetImage()->CreationEvent() <= event) { - it.Remove(); - int32 deleted = image->GetImage()->DeletionEvent(); - if (deleted >= 0 && event >= deleted) { - // image already deleted - delete image; - } else - fImages.Add(image); - } - } + return visitor.imageCount; } -template<typename ProfileResultImageType> -ProfileResultImageType* -AbstractProfileResult<ProfileResultImageType>::FindImage(addr_t address) const -{ - typename ImageList::ConstIterator it = fImages.GetIterator(); - while (ProfileResultImageType* image = it.Next()) { - if (image->ContainsAddress(address)) - return image; - } - return NULL; -} - - -template<typename ProfileResultImageType> -int32 -AbstractProfileResult<ProfileResultImageType>::GetHitImages( - ProfileResultImageType** images) const -{ - int32 imageCount = 0; - - typename ImageList::ConstIterator it = fOldImages.GetIterator(); - while (ProfileResultImageType* image = it.Next()) { - if (image->TotalHits() > 0) - images[imageCount++] = image; - } - - it = fImages.GetIterator(); - while (ProfileResultImageType* image = it.Next()) { - if (image->TotalHits() > 0) - images[imageCount++] = image; - } - - return imageCount; -} - - #endif // PROFILE_RESULT_H Modified: haiku/trunk/src/bin/debug/profile/Team.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile/Team.cpp 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/Team.cpp 2010-02-21 17:16:59 UTC (rev 35556) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@xxxxxxx * Distributed under the terms of the MIT License. */ @@ -14,6 +14,7 @@ #include "debug_utils.h" +#include "Image.h" #include "Options.h" @@ -104,7 +105,7 @@ Team::InitThread(Thread* thread) { // The thread - thread->GetProfileResult()->SetLazyImages(!_SynchronousProfiling()); + thread->SetLazyImages(!_SynchronousProfiling()); // create the sample area char areaName[B_OS_NAME_LENGTH]; @@ -267,7 +268,7 @@ if (_SynchronousProfiling()) { ThreadList::Iterator it = fThreads.GetIterator(); while (Thread* thread = it.Next()) - thread->GetProfileResult()->RemoveImage(image); + thread->RemoveImage(image); } else { // Note: We don't tell the threads that the image has been removed. They // will be updated lazily when their next profiler update arrives. This Modified: haiku/trunk/src/bin/debug/profile/Team.h =================================================================== --- haiku/trunk/src/bin/debug/profile/Team.h 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/Team.h 2010-02-21 17:16:59 UTC (rev 35556) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@xxxxxxx * Distributed under the terms of the MIT License. */ #ifndef TEAM_H @@ -14,6 +14,8 @@ #include "Thread.h" +class Image; +class SharedImage; struct system_profiler_team_added; Modified: haiku/trunk/src/bin/debug/profile/Thread.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile/Thread.cpp 2010-02-21 16:31:50 UTC (rev 35555) +++ haiku/trunk/src/bin/debug/profile/Thread.cpp 2010-02-21 17:16:59 UTC (rev 35556) @@ -13,11 +13,33 @@ #include "debug_utils.h" +#include "Image.h" #include "Options.h" #include "Team.h" +// #pragma mark - ThreadImage + +ThreadImage::ThreadImage(Image* image, ImageProfileResult* result) + : + fImage(image), + fResult(result) +{ + fImage->AcquireReference(); +} + + +ThreadImage::~ThreadImage() +{ + fImage->ReleaseReference(); + delete fResult; +} + + +// #pragma mark - ThreadI + + Thread::Thread(thread_id threadID, const char* name, Team* team) : fID(threadID), @@ -25,7 +47,8 @@ fTeam(team), fSampleArea(-1), fSamples(NULL), - fProfileResult(NULL) + fProfileResult(NULL), + fLazyImages(true) { } @@ -36,6 +59,11 @@ delete_area(fSampleArea); delete fProfileResult; [... truncated: 288 lines follow ...]