profile: Use BStackOrHeapArray to store the result arrays.

Otherwise with very large profile results we can overflow the stack.
This commit is contained in:
Augustin Cavalier
2024-07-17 12:43:24 -04:00
parent 421a5795ae
commit 1b6cac3521
2 changed files with 8 additions and 6 deletions
+5 -4
View File
@@ -13,6 +13,7 @@
#include <algorithm>
#include <new>
#include <StackOrHeapArray.h>
#include "Options.h"
#include "ProfiledEntity.h"
@@ -144,8 +145,8 @@ void
BasicProfileResult::PrintResults(ImageProfileResultContainer* container)
{
// get hit images
BasicImageProfileResult* images[container->CountImages()];
int32 imageCount = GetHitImages(container, images);
BStackOrHeapArray<BasicImageProfileResult*, 128> images(container->CountImages());
int32 imageCount = GetHitImages(container, &*images);
// count symbols
int32 symbolCount = 0;
@@ -156,7 +157,7 @@ BasicProfileResult::PrintResults(ImageProfileResultContainer* container)
}
// find and sort the hit symbols
HitSymbol hitSymbols[symbolCount];
BStackOrHeapArray<HitSymbol, 128> hitSymbols(symbolCount);
int32 hitSymbolCount = 0;
for (int32 k = 0; k < imageCount; k++) {
@@ -177,7 +178,7 @@ BasicProfileResult::PrintResults(ImageProfileResultContainer* container)
}
if (hitSymbolCount > 1)
std::sort(hitSymbols, hitSymbols + hitSymbolCount);
std::sort(&*hitSymbols, hitSymbols + hitSymbolCount);
int64 totalTicks = fTotalTicks;
const int64 missedTicks = fExpectedTicks - fTotalTicks;
@@ -11,6 +11,7 @@
#include <algorithm>
#include <new>
#include <StackOrHeapArray.h>
#include "Options.h"
#include "ProfiledEntity.h"
@@ -221,8 +222,8 @@ CallgrindProfileResult::PrintResults(ImageProfileResultContainer* container)
fTotalTicks, fTotalTicks * fInterval);
// get hit images
CallgrindImageProfileResult* images[container->CountImages()];
int32 imageCount = GetHitImages(container, images);
BStackOrHeapArray<CallgrindImageProfileResult*, 128> images(container->CountImages());
int32 imageCount = GetHitImages(container, &*images);
for (int32 i = 0; i < imageCount; i++) {
CallgrindImageProfileResult* image = images[i];