Skip to content

Commit

Permalink
Add function to split profiling package when IO packages forks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Oct 9, 2018
1 parent 7c1f3e9 commit 29b3368
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ dnl Define kernel version
dnl


gap_kernel_major_version=5
gap_kernel_major_version=6
gap_kernel_minor_version=0
AC_SUBST([gap_kernel_major_version])
AC_SUBST([gap_kernel_minor_version])
Expand Down
5 changes: 5 additions & 0 deletions doc/ref/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ limitations which users should be aware of:
is most obvious when looking at code coverage examples, which will appear
to miss lines of code in files not in a function.
</Item>
<Item>
If the current GAP is forked, using the IO_fork function in the IO package,
a new profile output file will be created for the new child process, with
the process ID of the child attached to the end of the filename.
</Item>
</List>

Profiles are transformed into a human-readable form with
Expand Down
29 changes: 29 additions & 0 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
#include "modules.h"
#include "plist.h"
#include "stringobj.h"
#include "sysfiles.h"
#include "vars.h"

#include "hpc/thread.h"

#include <sys/time.h> // for gettimeofday
#include <sys/types.h>
#include <unistd.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h> // definition of 'struct rusage'
#endif
Expand Down Expand Up @@ -114,6 +117,8 @@ struct ProfileState
{
// C steam we are writing to
FILE* Stream;
// Filename we are writing to
char filename[GAP_PATH_MAX];
// Did we use 'popen' to open the stream (matters when closing)
int StreamWasPopened;
// Are we currently outputting repeats (false=code coverage)
Expand Down Expand Up @@ -337,6 +342,26 @@ static void fcloseMaybeCompressed(struct ProfileState* ps)
ps->Stream = 0;
}

// When a child is forked off, we force profile information to be stored
// in a new file for the child, to avoid corruption
void InformProfilingThatThisIsAForkedGAP(void)
{
HashLock(&profileState);
if (profileState_Active) {
char filenamecpy[GAP_PATH_MAX + 20];
if (endsWithgz(profileState.filename)) {
snprintf(filenamecpy, sizeof(filenamecpy), "%s.%d.gz",
profileState.filename, getpid());
}
else {
snprintf(filenamecpy, sizeof(filenamecpy), "%s.%d",
profileState.filename, getpid());
}
fcloseMaybeCompressed(&profileState);
fopenMaybeCompressed(filenamecpy, &profileState);
}
}

static inline Int8 CPUmicroseconds(void)
{
#ifdef HAVE_GETRUSAGE
Expand Down Expand Up @@ -576,6 +601,8 @@ void enableAtStartup(char * filename, Int repeats, TickMethod tickMethod)
exit(1);
}

strlcpy(profileState.filename, filename, GAP_PATH_MAX);

ActivateHooks(&profileHooks);

profileState_Active = 1;
Expand Down Expand Up @@ -706,6 +733,8 @@ Obj FuncACTIVATE_PROFILING(Obj self,

fopenMaybeCompressed(CONST_CSTR_STRING(filename), &profileState);

strlcpy(profileState.filename, CONST_CSTR_STRING(filename), GAP_PATH_MAX);

if(profileState.Stream == 0) {
HashUnlock(&profileState);
return Fail;
Expand Down
5 changes: 5 additions & 0 deletions src/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/

// When a child is forked off, we force profile information to be stored
// in a new file for the child, to avoid corruption.
// This function is for use by the IO package
void InformProfilingThatThisIsAForkedGAP(void);


/****************************************************************************
**
Expand Down

0 comments on commit 29b3368

Please sign in to comment.