Skip to content

Commit

Permalink
Messing around..
Browse files Browse the repository at this point in the history
  • Loading branch information
afxgroup committed Sep 20, 2023
1 parent 0c41adb commit 645659b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile.os4
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ WARNINGS := \
-Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-unused-value -Wno-comment -Wno-missing-braces \
-Wno-deprecated-declarations -Wno-sign-compare -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
-Wstrict-aliasing -Wno-shadow -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing \
-Wno-type-limits -Wno-cast-function-type -Werror # -Wbad-function-cast -Wconversion -Wformat
-Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Werror # -Wbad-function-cast -Wconversion -Wformat

PIC := -fPIC -DPIC
INCLUDES := -I$(LIB_DIR)/include \
Expand Down
17 changes: 9 additions & 8 deletions library/profile/_mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ __mcount(uint32 frompc, uint32 selfpc) {
* Check if the PC is inside our text segment.
* Really should be...
*/
dprintf("p->textsize %x\n", p->textsize);
dprintf("p->lowpc %x\n", p->lowpc);
dprintf("frompc1 %x\n", frompc);
dprintf("selfpc1 %x\n", selfpc);
frompc -= p->lowpc;
selfpc -= p->lowpc;
dprintf("frompc %d\n", frompc);
dprintf("p->textsize %d\n", p->textsize);
dprintf("selfpc %d\n", selfpc);
dprintf("frompc2 %x\n", frompc);
dprintf("selfpc2 %x\n", selfpc);
if (frompc > p->textsize)
goto done;

Expand Down Expand Up @@ -71,11 +74,9 @@ __mcount(uint32 frompc, uint32 selfpc) {
goto done;
}
top = &p->tos[toindex];
printf("top->selfpc = %d - selfpc = %d\n", top->selfpc, selfpc);
printf("p->lowpc = %p - top->selfpc = %x - selfpc = %x\n", p->lowpc, top->selfpc, selfpc);
if (top->selfpc == selfpc) {
/*
* arc at front of chain; usual case.
*/
/* arc at front of chain; usual case. */
top->count++;
goto done;
}
Expand All @@ -85,7 +86,7 @@ __mcount(uint32 frompc, uint32 selfpc) {
* prevtop points to previous top.
* we know it is not at the head of the chain.
*/
for (; /* goto done */; ) {
for (;; ) {
if (top->link == 0) {
/*
* top is end of the chain and none of the chain
Expand Down
46 changes: 34 additions & 12 deletions library/profile/gmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,27 @@ void
write_hist(int fd) {
u_char tag = GMON_TAG_TIME_HIST;

printf("_gmonparam.kcountsize = %d\n", _gmonparam.kcountsize);
if (_gmonparam.kcountsize > 0) {
struct iovec iov[3] = {
{ &tag, sizeof(tag) },
{ &thdr, sizeof(struct gmon_hist_hdr) },
{ _gmonparam.kcount, _gmonparam.kcountsize }
};

if (sizeof(thdr) != sizeof(struct gmon_hist_hdr) || (offsetof(struct real_gmon_hist_hdr, low_pc) != offsetof(struct gmon_hist_hdr, low_pc)) || (offsetof(struct real_gmon_hist_hdr, high_pc) != offsetof(struct gmon_hist_hdr, high_pc)) || (offsetof(struct real_gmon_hist_hdr, hist_size) != offsetof(struct gmon_hist_hdr, hist_size)) || (offsetof(struct real_gmon_hist_hdr, prof_rate) != offsetof(struct gmon_hist_hdr, prof_rate)) || (offsetof(struct real_gmon_hist_hdr, dimen) != offsetof(struct gmon_hist_hdr, dimen)) || (offsetof(struct real_gmon_hist_hdr, dimen_abbrev) != offsetof(struct gmon_hist_hdr, dimen_abbrev)))
if (
sizeof(thdr) != sizeof(struct gmon_hist_hdr) ||
(offsetof(struct real_gmon_hist_hdr, low_pc) != offsetof(struct gmon_hist_hdr, low_pc)) ||
(offsetof(struct real_gmon_hist_hdr, high_pc) != offsetof(struct gmon_hist_hdr, high_pc)) ||
(offsetof(struct real_gmon_hist_hdr, hist_size) != offsetof(struct gmon_hist_hdr, hist_size)) ||
(offsetof(struct real_gmon_hist_hdr, prof_rate) != offsetof(struct gmon_hist_hdr, prof_rate)) ||
(offsetof(struct real_gmon_hist_hdr, dimen) != offsetof(struct gmon_hist_hdr, dimen)) ||
(offsetof(struct real_gmon_hist_hdr, dimen_abbrev) != offsetof(struct gmon_hist_hdr, dimen_abbrev))
)
return;

thdr.low_pc = (char *)_gmonparam.lowpc;
thdr.high_pc = (char *)_gmonparam.highpc;
thdr.low_pc = (char *) _gmonparam.lowpc;
thdr.high_pc = (char *) _gmonparam.highpc;
thdr.hist_size = _gmonparam.kcountsize / sizeof(HISTCOUNTER);
printf("hist_size = %d - _gmonparam.kcountsize = %d - sizeof(HISTCOUNTER) = %d\n",
thdr.hist_size, _gmonparam.kcountsize, sizeof(HISTCOUNTER));
Expand Down Expand Up @@ -80,7 +89,8 @@ write_call_graph(int fd) {
continue;

/* FIXME: was p->lowpc; needs to be 0 and assumes -Ttext=0 on compile. Better idea? */
frompc = 0; //_gmonparam.lowpc;
printf("_gmonparam.lowpc = %x\n", _gmonparam.lowpc);
frompc = _gmonparam.lowpc;
frompc += (from_index * _gmonparam.hashfraction * sizeof(*_gmonparam.froms));
for (to_index = _gmonparam.froms[from_index];
to_index != 0;
Expand All @@ -94,7 +104,7 @@ write_call_graph(int fd) {
arc.frompc = (char *)frompc;
arc.selfpc = (char *)_gmonparam.tos[to_index].selfpc;
arc.count = _gmonparam.tos[to_index].count;
printf("arc.count = %d\n", arc.count);
printf("arc.frompc = %x - _gmonparam.tos[to_index].selfpc = %x\n", arc.frompc, _gmonparam.tos[to_index].selfpc);
memcpy(raw_arc + nfilled, &arc, sizeof(raw_arc[0]));

if (++nfilled == NARCS_PER_WRITEV) {
Expand Down Expand Up @@ -152,7 +162,7 @@ void monstartup(uint32 low_pc, uint32 high_pc) {
struct gmonparam *p = &_gmonparam;
register int o;

dprintf("in monstartup)\n");
dprintf("in monstartup low_pc = %d - high_pc = %d\n", low_pc, high_pc);

/*
* If we don't get proper lowpc and highpc, then
Expand Down Expand Up @@ -268,32 +278,36 @@ void moncontrol(int mode) {
}

void moncleanup(void) {
BPTR fd;
int fd;
struct gmonparam *p = &_gmonparam;

moncontrol(0);

if (p->state == kGmonProfError) {
fprintf(stderr, "WARNING: Overflow during profiling\n");
goto out;
}

if (_gmonparam.kcountsize > 0) {
fd = open("gmon.out", O_CREAT | O_TRUNC | O_WRONLY);
if (!fd) {
fprintf(stderr, "ERROR: could not open gmon.out\n");
return;
goto out;
}

/* write gmon.out header: */
struct real_gmon_hdr
{
struct real_gmon_hdr {
char cookie[4];
int32_t version;
char spare[3 * 4];
} ghdr;

if (sizeof(ghdr) != sizeof(struct gmon_hdr) || (offsetof(struct real_gmon_hdr, cookie) != offsetof(struct gmon_hdr, cookie)) || (offsetof(struct real_gmon_hdr, version) != offsetof(struct gmon_hdr, version)))
return;
if (
sizeof(ghdr) != sizeof(struct gmon_hdr) ||
(offsetof(struct real_gmon_hdr, cookie) != offsetof(struct gmon_hdr, cookie)) ||
(offsetof(struct real_gmon_hdr, version) != offsetof(struct gmon_hdr, version))) {
goto out;
}

memcpy(&ghdr.cookie[0], GMON_MAGIC, sizeof(ghdr.cookie));
ghdr.version = GMON_VERSION;
Expand All @@ -311,6 +325,12 @@ void moncleanup(void) {

close(fd);
}
out:
if (p->tos) {
FreeVec(p->tos);
p->tos = NULL;
}

}

void mongetpcs(uint32 *lowpc, uint32 *highpc) {
Expand Down Expand Up @@ -344,6 +364,8 @@ void mongetpcs(uint32 *lowpc, uint32 *highpc) {
uint32 base = (uint32) GetSectionTags(elfHandle, GST_SectionIndex, i, TAG_DONE);
*lowpc = base;
*highpc = base + shdr->sh_size;
printf("LOWPC = %x\n", lowpc);
printf("HIGHPC = %x\n", highpc);
break;
}
}
Expand Down

0 comments on commit 645659b

Please sign in to comment.