SL-10297: Get rid of LLError::LLCallStacks::allocateStackBuffer().

Also freeStackBuffer() and all the funky classic-C string management of a big
flat buffer divided into exactly 512 128-byte strings. Define StringVector as
a std::vector<std::string>, and use that instead.

Retain the behavior of clearing the vector if it exceeds 512 entries.

This eliminates the LLError::Log::flush(const std::ostringstream&, char*)
overload as well, with its baffling mix of std::string and classic-C (e.g.
strlen(out.str().c_str()).

If we absolutely MUST use a big memory pool for performance reasons, let's
use StringVector with allocators.
master
Nat Goodspeed 2021-05-12 13:37:24 -04:00
parent 5b96ee0e10
commit 91c20363ee
2 changed files with 18 additions and 80 deletions

View File

@ -1352,25 +1352,6 @@ namespace LLError
}
void Log::flush(const std::ostringstream& out, char* message)
{
LLMutexTrylock lock(getMutex<LOG_MUTEX>(),5);
if (!lock.isLocked())
{
return;
}
if(strlen(out.str().c_str()) < 128)
{
strcpy(message, out.str().c_str());
}
else
{
strncpy(message, out.str().c_str(), 127);
message[127] = '\0' ;
}
}
void Log::flush(const std::ostringstream& out, const CallSite& site)
{
LLMutexTrylock lock(getMutex<LOG_MUTEX>(),5);
@ -1496,33 +1477,7 @@ namespace LLError
namespace LLError
{
char** LLCallStacks::sBuffer = NULL ;
S32 LLCallStacks::sIndex = 0 ;
//static
void LLCallStacks::allocateStackBuffer()
{
if(sBuffer == NULL)
{
sBuffer = new char*[512] ;
sBuffer[0] = new char[512 * 128] ;
for(S32 i = 1 ; i < 512 ; i++)
{
sBuffer[i] = sBuffer[i-1] + 128 ;
}
sIndex = 0 ;
}
}
void LLCallStacks::freeStackBuffer()
{
if(sBuffer != NULL)
{
delete [] sBuffer[0] ;
delete [] sBuffer ;
sBuffer = NULL ;
}
}
LLCallStacks::StringVector LLCallStacks::sBuffer ;
//static
void LLCallStacks::push(const char* function, const int line)
@ -1533,21 +1488,14 @@ namespace LLError
return;
}
if(sBuffer == NULL)
{
allocateStackBuffer();
}
if(sIndex > 511)
if(sBuffer.size() > 511)
{
clear() ;
}
strcpy(sBuffer[sIndex], function) ;
sprintf(sBuffer[sIndex] + strlen(function), " line: %d ", line) ;
sIndex++ ;
return ;
std::ostringstream out;
insert(out, function, line);
sBuffer.push_back(out.str());
}
//static
@ -1565,17 +1513,12 @@ namespace LLError
return;
}
if(sBuffer == NULL)
{
allocateStackBuffer();
}
if(sIndex > 511)
if(sBuffer.size() > 511)
{
clear() ;
}
LLError::Log::flush(out, sBuffer[sIndex++]) ;
sBuffer.push_back(out.str());
}
//static
@ -1587,33 +1530,30 @@ namespace LLError
return;
}
if(sIndex > 0)
if(! sBuffer.empty())
{
LL_INFOS() << " ************* PRINT OUT LL CALL STACKS ************* " << LL_ENDL;
while(sIndex > 0)
for (StringVector::const_reverse_iterator ri(sBuffer.rbegin()), re(sBuffer.rend());
ri != re; ++ri)
{
sIndex-- ;
LL_INFOS() << sBuffer[sIndex] << LL_ENDL;
LL_INFOS() << (*ri) << LL_ENDL;
}
LL_INFOS() << " *************** END OF LL CALL STACKS *************** " << LL_ENDL;
}
if(sBuffer != NULL)
{
freeStackBuffer();
}
cleanup();
}
//static
void LLCallStacks::clear()
{
sIndex = 0 ;
sBuffer.clear();
}
//static
void LLCallStacks::cleanup()
{
freeStackBuffer();
clear();
}
std::ostream& operator<<(std::ostream& out, const LLStacktrace&)

View File

@ -29,7 +29,9 @@
#define LL_LLERROR_H
#include <sstream>
#include <string>
#include <typeinfo>
#include <vector>
#include "stdtypes.h"
@ -198,7 +200,6 @@ namespace LLError
{
public:
static bool shouldLog(CallSite&);
static void flush(const std::ostringstream& out, char* message);
static void flush(const std::ostringstream&, const CallSite&);
static std::string demangle(const char* mangled);
/// classname<TYPE>()
@ -280,11 +281,8 @@ namespace LLError
class LL_COMMON_API LLCallStacks
{
private:
static char** sBuffer ;
static S32 sIndex ;
static void allocateStackBuffer();
static void freeStackBuffer();
typedef std::vector<std::string> StringVector;
static StringVector sBuffer ;
public:
static void push(const char* function, const int line) ;