Skip to content

Commit

Permalink
Profile.event dump allow specify file path
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Jun 21, 2024
1 parent 93a3924 commit 8d95f3c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,15 @@ static int write_names( thread_handle *h, FILE *f ) {
return count;
}

static void profile_dump() {
static void profile_dump( vbyte* ptr ) {
if( !data.first_record ) return;

data.profiling_pause++;
printf("Writing profiling data...\n");
fflush(stdout);

FILE *f = fopen("hlprofile.dump","wb");
char* filename = ptr == NULL ? "hlprofile.dump" : hl_to_utf8(ptr);
FILE *f = fopen(filename,"wb");
int version = HL_VERSION;
fwrite("PROF",1,4,f);
fwrite(&version,1,4,f);
Expand Down Expand Up @@ -503,7 +504,7 @@ static void profile_dump() {
}

void hl_profile_end() {
profile_dump();
profile_dump(NULL);
if( !data.sample_count ) return;
data.stopLoop = true;
while( data.stopLoop ) {};
Expand Down Expand Up @@ -539,7 +540,7 @@ static void profile_event( int code, vbyte *ptr, int dataLen ) {
data.profiling_pause--;
break;
case -6:
profile_dump();
profile_dump(ptr);
break;
case -7:
{
Expand Down

0 comments on commit 8d95f3c

Please sign in to comment.