Skip to content

Commit

Permalink
fixed int overrun in memory tracker
Browse files Browse the repository at this point in the history
git-svn-id: http://sphinxsearch.googlecode.com/svn/trunk@2274 8b96e2b9-35c5-2c16-bc47-5122d61876d4
  • Loading branch information
tomat committed Apr 12, 2010
1 parent 3def1d8 commit 10be3fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/searchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7808,14 +7808,14 @@ void CheckLeaks ()
static int64_t tmLastLog = -iAllocLogPeriod*10;

const int iAllocCount = sphAllocsCount();
const int iMemTotal = sphAllocBytes();
const int64_t iMemTotal = sphAllocBytes();

if ( iAllocLogPeriod>0 && tmLastLog+iAllocLogPeriod<sphMicroTimer() )
{
tmLastLog = sphMicroTimer ();
const int iThdsCount = g_dThd.GetLength ();
const int iMB = 1024*1024;
sphInfo ( "--- allocs-count=%d, mem-total=%d.%dMb, active-threads=%d", iAllocCount, iMemTotal/iMB, iMemTotal%iMB, iThdsCount );
const int64_t iMB = 1024*1024;
sphInfo ( "--- allocs-count=%d, mem-total="INT64_FMT"."INT64_FMT"Mb, active-threads=%d", iAllocCount, iMemTotal/iMB, iMemTotal%iMB, iThdsCount );
sphMemStatDump();
sphLog ( LOG_INFO, NULL, NULL );
}
Expand Down
30 changes: 15 additions & 15 deletions src/sphinxstd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ static CSphStaticMutex g_tAllocsMutex;
static int g_iCurAllocs = 0;
static int g_iAllocsId = 0;
static CSphMemHeader * g_pAllocs = NULL;
static int g_iCurBytes = 0;
static int64_t g_iCurBytes = 0;
static int g_iTotalAllocs = 0;
static int g_iPeakAllocs = 0;
static int g_iPeakBytes = 0;
static int64_t g_iPeakBytes = 0;

void * sphDebugNew ( size_t iSize, const char * sFile, int iLine, bool bArray )
{
Expand Down Expand Up @@ -191,7 +191,7 @@ void sphDebugDelete ( void * pPtr, bool bArray )
}


int sphAllocBytes ()
int64_t sphAllocBytes ()
{
return g_iCurBytes;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ void sphAllocsDump ( int iFile, int iSinceID )

void sphAllocsStats ()
{
fprintf ( stdout, "--- total-allocs=%d, peak-allocs=%d, peak-bytes=%d\n",
fprintf ( stdout, "--- total-allocs=%d, peak-allocs=%d, peak-bytes="INT64_FMT"\n",
g_iTotalAllocs, g_iPeakAllocs, g_iPeakBytes );
}

Expand Down Expand Up @@ -294,15 +294,15 @@ void operator delete [] ( void * pPtr )

static CSphStaticMutex g_tAllocsMutex;
static int g_iCurAllocs = 0;
static int g_iCurBytes = 0;
static int64_t g_iCurBytes = 0;
static int g_iTotalAllocs = 0;
static int g_iPeakAllocs = 0;
static int g_iPeakBytes = 0;
static int64_t g_iPeakBytes = 0;

struct MemCategorized_t
{
int m_iSize;
int m_iCount;
int64_t m_iSize;
int m_iCount;

MemCategorized_t()
: m_iSize ( 0 )
Expand All @@ -328,7 +328,7 @@ void * sphDebugNew ( size_t iSize )

g_tAllocsMutex.Lock ();
g_iCurAllocs++;
g_iCurBytes += (int)iSize;
g_iCurBytes += iSize;
g_iTotalAllocs++;
g_iPeakAllocs = Max ( g_iCurAllocs, g_iPeakAllocs );
g_iPeakBytes = Max ( g_iCurBytes, g_iPeakBytes );
Expand Down Expand Up @@ -372,12 +372,12 @@ void sphDebugDelete ( void * pPtr )
void sphAllocsStats ()
{
g_tAllocsMutex.Lock ();
fprintf ( stdout, "--- total-allocs=%d, peak-allocs=%d, peak-bytes=%d\n",
fprintf ( stdout, "--- total-allocs=%d, peak-allocs=%d, peak-bytes="INT64_FMT"\n",
g_iTotalAllocs, g_iPeakAllocs, g_iPeakBytes );
g_tAllocsMutex.Unlock ();
}

int sphAllocBytes () { return g_iCurBytes; }
int64_t sphAllocBytes () { return g_iCurBytes; }
int sphAllocsCount () { return g_iCurAllocs; }
int sphAllocsLastID () { return -1; }
void sphAllocsDump ( int, int ) {}
Expand Down Expand Up @@ -503,19 +503,19 @@ extern void sphInfo ( const char * sFmt, ... );

void sphMemStatDump ()
{
const int iMB = 1024*1024;
int iSize = 0;
const int64_t iMB = 1024*1024;
int64_t iSize = 0;
int iCount = 0;
for ( int i=0; i<Memory::SPH_MEM_TOTAL; i++ )
{
iSize += g_dMemCategoryStat[i].m_iSize;
iCount += g_dMemCategoryStat[i].m_iCount;
}
sphInfo ( "%-24s allocs-count=%d, mem-total=%d.%dMb", "(total)", iCount, iSize/iMB, iSize%iMB );
sphInfo ( "%-24s allocs-count=%d, mem-total="INT64_FMT"."INT64_FMT"Mb", "(total)", iCount, iSize/iMB, iSize%iMB );

for ( int i=0; i<Memory::SPH_MEM_TOTAL; i++ )
if ( g_dMemCategoryStat[i].m_iCount>0 )
sphInfo ( "%-24s allocs-count=%d, mem-total=%d.%dMb"
sphInfo ( "%-24s allocs-count=%d, mem-total="INT64_FMT"."INT64_FMT"Mb"
, g_dMemCategoryName[i], g_dMemCategoryStat[i].m_iCount, g_dMemCategoryStat[i].m_iSize/iMB, g_dMemCategoryStat[i].m_iSize%iMB );
}

Expand Down
2 changes: 1 addition & 1 deletion src/sphinxstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void * operator new [] ( size_t iSize, const char * sFile, int iLine );
int sphAllocsCount ();

/// total allocated bytes
int sphAllocBytes ();
int64_t sphAllocBytes ();

/// get last alloc id
int sphAllocsLastID ();
Expand Down
4 changes: 2 additions & 2 deletions src/testrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ int main ()
int64_t tmShutdown = sphMicroTimer();

#if SPH_ALLOCS_PROFILER
printf ( "pre-shutdown allocs=%d, bytes=%d\n", sphAllocsCount(), sphAllocBytes() );
printf ( "pre-shutdown allocs=%d, bytes="INT64_FMT"\n", sphAllocsCount(), sphAllocBytes() );
#endif
SafeDelete ( pIndex );
#if SPH_ALLOCS_PROFILER
printf ( "post-shutdown allocs=%d, bytes=%d\n", sphAllocsCount(), sphAllocBytes() );
printf ( "post-shutdown allocs=%d, bytes="INT64_FMT"\n", sphAllocsCount(), sphAllocBytes() );
#endif

int64_t tmEnd = sphMicroTimer();
Expand Down

0 comments on commit 10be3fc

Please sign in to comment.