Skip to content

Commit 35c4eaf

Browse files
Buffer gmon.out writes for speed
Decrease the overhead of the semihosting (~100ms per write call + time to transfer actual data) by buffering up multiple chunks in the gmon.out generator. Speeds up writing 30x+.
1 parent 977fa45 commit 35c4eaf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cores/rp2040/gprof_gmon.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ void _writeProfile(profileWriteCB writeCB) {
405405
size_t frompc;
406406
int toindex;
407407
struct rawarc rawarc;
408+
const int BS = 64;
409+
struct rawarc rawarcbuff[BS];
410+
int rawarcbuffptr = 0;
408411
struct gmonparam *p = &_gmonparam;
409412
struct gmonhdr gmonhdr, *hdr;
410413

@@ -429,9 +432,17 @@ void _writeProfile(profileWriteCB writeCB) {
429432
rawarc.raw_frompc = frompc;
430433
rawarc.raw_selfpc = GETSELFPC(&p->tos[toindex]);
431434
rawarc.raw_count = GETCOUNT(&p->tos[toindex]);
432-
writeCB((void *)&rawarc, sizeof rawarc);
435+
// Buffer up writes because Semihosting is really slow per write call
436+
rawarcbuff[rawarcbuffptr++] = rawarc;
437+
if (rawarcbuffptr == BS) {
438+
writeCB((void *)rawarcbuff, BS * sizeof(struct rawarc));
439+
rawarcbuffptr = 0;
440+
}
433441
}
434442
}
443+
if (rawarcbuffptr) {
444+
writeCB((void *)rawarcbuff, rawarcbuffptr * sizeof(struct rawarc));
445+
}
435446
}
436447

437448
/*

0 commit comments

Comments
 (0)