Skip to content

Instantly share code, notes, and snippets.

@rhb2
Created March 19, 2020 18:04
Show Gist options
  • Save rhb2/abc00a68774da23539ea38cdaea82620 to your computer and use it in GitHub Desktop.
Save rhb2/abc00a68774da23539ea38cdaea82620 to your computer and use it in GitHub Desktop.
#!/usr/sbin/dtrace -s
#pragma D option quiet
pid$target::malloc:entry
{
self->size = arg0;
}
pid$target::malloc:return
/self->size/
{
addresses[arg1] = 1;
/* print details of the allocation */
/* seq_id;event;tid;address;size;datetime */
printf("<__%i;%Y;%d;new;0x%x;%d;\n",
i++, walltimestamp, tid, arg1, self->size);
ustack(50);
printf("__>\n\n");
@mem[arg1] = sum(1);
self->size=0;
}
pid$target::free:entry
/addresses[arg0]/
{
@mem[arg0] = sum(-1);
/* print details of the deallocation */
/* seq_id;event;tid;address;datetime */
printf("<__%i;%Y;%d;delete;0x%x__>\n",
i++, walltimestamp, tid, arg0);
}
END
{
printf("== REPORT ==\n\n");
printa("0x%x => %@u\n",@mem);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment