Skip to content
Snippets Groups Projects
Commit 30637331 authored by Drake Arconis's avatar Drake Arconis
Browse files

Some changes from viewer64

parent 9ad0f677
Branches
Tags
No related merge requests found
...@@ -234,6 +234,7 @@ U32Kilobytes LLMemory::getAllocatedMemKB() ...@@ -234,6 +234,7 @@ U32Kilobytes LLMemory::getAllocatedMemKB()
#if defined(LL_WINDOWS) #if defined(LL_WINDOWS)
//static
U64 LLMemory::getCurrentRSS() U64 LLMemory::getCurrentRSS()
{ {
PROCESS_MEMORY_COUNTERS counters; PROCESS_MEMORY_COUNTERS counters;
...@@ -264,12 +265,11 @@ U64 LLMemory::getCurrentRSS() ...@@ -264,12 +265,11 @@ U64 LLMemory::getCurrentRSS()
mach_msg_type_number_t basicInfoCount = MACH_TASK_BASIC_INFO_COUNT; mach_msg_type_number_t basicInfoCount = MACH_TASK_BASIC_INFO_COUNT;
if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&basicInfo, &basicInfoCount) == KERN_SUCCESS) if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&basicInfo, &basicInfoCount) == KERN_SUCCESS)
{ {
residentSize = basicInfo.resident_size; // residentSize = basicInfo.resident_size;
// Although this method is defined to return the "resident set size,"
// If we ever wanted it, the process virtual size is also available as: // in fact what callers want from it is the total virtual memory
// virtualSize = basicInfo.virtual_size; // consumed by the application.
residentSize = basicInfo.virtual_size;
// LL_INFOS() << "resident size is " << residentSize << LL_ENDL;
} }
else else
{ {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "lltimer.h" #include "lltimer.h"
#include "lltrace.h" #include "lltrace.h"
#include "lltracethreadrecorder.h" #include "lltracethreadrecorder.h"
#include "llexception.h"
#include <chrono> #include <chrono>
...@@ -109,17 +110,53 @@ void LLThread::runWrapper() ...@@ -109,17 +110,53 @@ void LLThread::runWrapper()
// for now, hard code all LLThreads to report to single master thread recorder, which is known to be running on main thread // for now, hard code all LLThreads to report to single master thread recorder, which is known to be running on main thread
mRecorder = std::make_unique<LLTrace::ThreadRecorder>(*LLTrace::get_master_thread_recorder()); mRecorder = std::make_unique<LLTrace::ThreadRecorder>(*LLTrace::get_master_thread_recorder());
try
{
// Run the user supplied function // Run the user supplied function
do
{
try
{
run(); run();
}
catch (const LLContinueError &e)
{
LL_WARNS("THREAD") << "ContinueException on thread '" << mName <<
"' reentering run(). Error what is: '" << e.what() << "'" << LL_ENDL;
//output possible call stacks to log file.
LLError::LLCallStacks::print();
//LL_INFOS() << "LLThread::staticRun() Exiting: " << threadp->mName << LL_ENDL; LOG_UNHANDLED_EXCEPTION("LLThread");
continue;
}
break;
mRecorder.reset(nullptr); } while (true);
//LL_INFOS() << "LLThread::staticRun() Exiting: " << mName << LL_ENDL;
// We're done with the run function, this thread is done executing now. // We're done with the run function, this thread is done executing now.
//NB: we are using this flag to sync across threads...we really need memory barriers here //NB: we are using this flag to sync across threads...we really need memory barriers here
mStatus = STOPPED; mStatus = STOPPED;
} }
catch (const std::bad_alloc&)
{
mStatus = CRASHED;
LLMemory::logMemoryInfo(TRUE);
//output possible call stacks to log file.
LLError::LLCallStacks::print();
LL_ERRS("THREAD") << "Bad memory allocation in LLThread::staticRun() named '" << mName << "'!" << LL_ENDL;
}
catch (...)
{
mStatus = CRASHED;
CRASH_ON_UNHANDLED_EXCEPTION("LLThread");
}
mRecorder.reset(nullptr);
}
LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : LLThread::LLThread(const std::string& name, apr_pool_t *poolp) :
mPaused(FALSE), mPaused(FALSE),
...@@ -128,6 +165,8 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : ...@@ -128,6 +165,8 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) :
mDataLock(std::make_unique<LLMutex>()), mDataLock(std::make_unique<LLMutex>()),
mStatus(STOPPED) mStatus(STOPPED)
{ {
// Thread creation probably CAN be paranoid about APR being initialized, if necessary // Thread creation probably CAN be paranoid about APR being initialized, if necessary
if (poolp) if (poolp)
{ {
...@@ -147,6 +186,11 @@ LLThread::~LLThread() ...@@ -147,6 +186,11 @@ LLThread::~LLThread()
{ {
shutdown(); shutdown();
if (isCrashed())
{
LL_WARNS("THREAD") << "Destroying crashed thread named '" << mName << "'" << LL_ENDL;
}
if(mLocalAPRFilePoolp) if(mLocalAPRFilePoolp)
{ {
delete mLocalAPRFilePoolp ; delete mLocalAPRFilePoolp ;
...@@ -156,6 +200,10 @@ LLThread::~LLThread() ...@@ -156,6 +200,10 @@ LLThread::~LLThread()
void LLThread::shutdown() void LLThread::shutdown()
{ {
if (isCrashed())
{
LL_WARNS("THREAD") << "Shutting down crashed thread named '" << mName << "'" << LL_ENDL;
}
// Warning! If you somehow call the thread destructor from itself, // Warning! If you somehow call the thread destructor from itself,
// the thread will die in an unclean fashion! // the thread will die in an unclean fashion!
if (!isStopped()) if (!isStopped())
...@@ -245,7 +293,7 @@ void LLThread::start() ...@@ -245,7 +293,7 @@ void LLThread::start()
} }
catch (const boost::thread_resource_error& err) catch (const boost::thread_resource_error& err)
{ {
mStatus = STOPPED; mStatus = CRASHED;
LL_WARNS() << "Failed to start thread: \"" << mName << "\" due to error: " << err.what() << LL_ENDL; LL_WARNS() << "Failed to start thread: \"" << mName << "\" due to error: " << err.what() << LL_ENDL;
} }
} }
......
...@@ -52,15 +52,17 @@ public: ...@@ -52,15 +52,17 @@ public:
{ {
STOPPED = 0, // The thread is not running. Not started, or has exited its run function STOPPED = 0, // The thread is not running. Not started, or has exited its run function
RUNNING = 1, // The thread is currently running RUNNING = 1, // The thread is currently running
QUITTING= 2 // Someone wants this thread to quit QUITTING= 2, // Someone wants this thread to quit
CRASHED = -1 // An uncaught exception was thrown by the thread
} EThreadStatus; } EThreadStatus;
LLThread(const std::string& name, apr_pool_t *poolp = nullptr); LLThread(const std::string& name, apr_pool_t *poolp = NULL);
virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state. virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state.
virtual void shutdown(); // stops the thread virtual void shutdown(); // stops the thread
bool isQuitting() const { return (QUITTING == mStatus); } bool isQuitting() const { return (QUITTING == mStatus); }
bool isStopped() const { return (STOPPED == mStatus); } bool isStopped() const { return (STOPPED == mStatus) || (CRASHED == mStatus); }
bool isCrashed() const { return (CRASHED == mStatus); }
static boost::thread::id currentID(); // Return ID of current thread static boost::thread::id currentID(); // Return ID of current thread
static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure. static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment