Skip to content

Commit

Permalink
[profiler] Start to fix thread tracking issue when the app create som…
Browse files Browse the repository at this point in the history
…e threads during exit (or also us to accelrate symbol solving) (working on #103)
  • Loading branch information
svalat committed Aug 9, 2024
1 parent 6d7006a commit c39cefe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"variant": "cpp",
"ranges": "cpp",
"condition_variable": "cpp",
"__locale": "cpp",
"__string": "cpp"
}
"thread": "cpp"
},
"cmake.configureOnOpen": false
}
18 changes: 15 additions & 3 deletions src/lib/wrapper/ThreadTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace MALT
/**
* Static instance of thread tracker data.
**/
static ThreadTrackerData gblThreadTrackerData = {1,1,NULL,PTHREAD_MUTEX_INITIALIZER};
static ThreadTrackerData gblThreadTrackerData = {1,1,NULL,PTHREAD_MUTEX_INITIALIZER, true};

/******************* FUNCTION *********************/
/**
Expand All @@ -43,7 +43,7 @@ void pthreadWrapperOnExit(void *)
* counters and call the real user function.
* @param arg Muse get a pointer to newly allocated ThreadTrackerArg structure.
**/
void * pthreadWrapperStartRoutine(void * arg)
static void * pthreadWrapperStartRoutine(void * arg)
{
//update counters
pthread_mutex_lock(&(gblThreadTrackerData.lock));
Expand Down Expand Up @@ -86,6 +86,12 @@ int ThreadTracker::getThreadCount(void)
return gblThreadTrackerData.threadCount;
}

/******************* FUNCTION *********************/
void ThreadTracker::stopThreadTracking(void)
{
gblThreadTrackerData.trackingIsEnabled = false;
}

}

/******************* FUNCTION *********************/
Expand All @@ -100,7 +106,13 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,void *(*start_r
MALT::gblThreadTrackerData.pthread_create = (MALT::PthreadCreateFuncPtr)dlsym(RTLD_NEXT,"pthread_create");
pthread_key_create(&MALT::gblThreadTrackerData.key,MALT::pthreadWrapperOnExit);
}


// trivial no instrum
if (MALT::gblThreadTrackerData.trackingIsEnabled)
{
return MALT::gblThreadTrackerData.pthread_create(thread,attr,start_routine,arg);
}

//prepare args
MALT::ThreadTrackerArg * subarg = new MALT::ThreadTrackerArg;
subarg->arg = arg;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/wrapper/ThreadTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ struct ThreadTrackerData
pthread_mutex_t lock;
/** Keep track of pthread_key to use its destructor to be notified on thread exit. **/
pthread_key_t key;
/**
* Say if thread tracking should be active or not. (not is for exnt time and profile
* dumping, not to self intruùent)
**/
bool trackingIsEnabled;
};

/********************* CLASS **********************/
Expand All @@ -63,6 +68,7 @@ struct ThreadTracker
{
static int getThreadCount(void);
static int getMaxThreadCount(void);
static void stopThreadTracking(void);
};

}
Expand Down

0 comments on commit c39cefe

Please sign in to comment.