Skip to content

Commit f16097d

Browse files
Add rp2040.getProfileMemoryUsage()
1 parent 35c4eaf commit f16097d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

cores/rp2040/RP2040Support.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ class RP2040 {
489489
__profileFile = f;
490490
_writeProfile(__writeProfileCB);
491491
}
492+
493+
size_t getProfileMemoryUsage() {
494+
extern int __profileMemSize;
495+
return (size_t) __profileMemSize;
496+
}
492497
#endif
493498

494499

cores/rp2040/gprof_gmon.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ static int s_scale;
322322

323323
static void moncontrol(int mode);
324324

325+
int __profileMemSize = 0;
326+
325327
void __no_inline_not_in_flash_func(monstartup)(size_t lowpc, size_t highpc) {
326328
register size_t o;
327329
char *cp;
@@ -343,16 +345,16 @@ void __no_inline_not_in_flash_func(monstartup)(size_t lowpc, size_t highpc) {
343345
p->tolimit = MAXARCS;
344346
}
345347
p->tossize = p->tolimit * sizeof(struct tostruct);
346-
348+
__profileMemSize = p->kcountsize + p->fromssize + p->tossize;
347349
#ifdef RP2350_PSRAM_CS
348-
cp = pmalloc(p->kcountsize + p->fromssize + p->tossize);
350+
cp = pmalloc(__profileMemSize);
349351
if (cp == (char *)0) {
350352
ERR("monstartup: out of memory\n");
351353
already_setup = 0;
352354
return;
353355
}
354356
#else
355-
cp = malloc(p->kcountsize + p->fromssize + p->tossize);
357+
cp = malloc(__profileMemSize);
356358
if (cp == (char *)0) {
357359
ERR("monstartup: out of memory\n");
358360
return;

docs/profiling.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ per second. When an application is complete, the recorded date can be dumped to
1111
s histogram of PCs and tally of function caller/callees can take a significant amount of RAM, from 100KB
1212
to 10000KB depending on the size of the application. As such, while the RP2040 **may** be able to
1313
profile small applications, this is only really recommended on the RP2350 with external PSRAM. The
14-
profiler will automatically use PSRAM when available.
14+
profiler will automatically use PSRAM when available. Call ``rp2040.getProfileMemoryUsage()`` to get the
15+
memory allocated at runtime.
16+
1517

1618
Profiling also adds processing overhead in terms of the periodic sampling and the function preambles.
1719
In most cases there is no reason to enable (and many reasons to disable) profiling when an application

0 commit comments

Comments
 (0)