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::AddDroppedTicks(int32 dropped) 80 { 81 fResult->AddDroppedTicks(dropped); 82 } 83 84 85 void 86 SummaryProfileResult::PrintResults(ImageProfileResultContainer* container) 87 { 88 // This is called for individual threads. We only print results in 89 // PrintSummaryResults(), though. 90 } 91 92 93 void 94 SummaryProfileResult::PrintSummaryResults() 95 { 96 fResult->PrintResults(this); 97 } 98 99 100 status_t 101 SummaryProfileResult::GetImageProfileResult(SharedImage* image, image_id id, 102 ImageProfileResult*& _imageResult) 103 { 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; 113 114 BReference<ImageProfileResult> imageResultReference(imageResult, true); 115 116 summaryImage = new(std::nothrow) SummaryImage(imageResult); 117 if (summaryImage == NULL) 118 return B_NO_MEMORY; 119 120 fImages.Insert(summaryImage); 121 } 122 123 _imageResult = summaryImage->Result(); 124 _imageResult->AcquireReference(); 125 126 return B_OK; 127 } 128 129 130 int32 131 SummaryProfileResult::CountImages() const 132 { 133 return fImages.CountElements(); 134 } 135 136 137 ImageProfileResult* 138 SummaryProfileResult::VisitImages(Visitor& visitor) const 139 { 140 for (ImageTable::Iterator it = fImages.GetIterator(); 141 SummaryImage* image = it.Next();) { 142 if (visitor.VisitImage(image->Result())) 143 return image->Result(); 144 } 145 146 return NULL; 147 } 148 149 150 ImageProfileResult* 151 SummaryProfileResult::FindImage(addr_t address, addr_t& _loadDelta) const 152 { 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; 156 } 157