8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 00:03:03 +01:00

Poor man's version of the old gds_alloc_report.

This commit is contained in:
robocop 2004-11-17 08:56:07 +00:00
parent 4ae14b8a75
commit eb99bbcccf
4 changed files with 53 additions and 34 deletions

View File

@ -23,7 +23,7 @@
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
* $Id: alloc.cpp,v 1.72 2004-10-25 05:14:05 skidder Exp $
* $Id: alloc.cpp,v 1.73 2004-11-17 08:55:40 robocop Exp $
*
*/
@ -194,6 +194,9 @@ namespace Firebird {
/****************************** Firebird::MemoryPool ***************************/
static void print_block(FILE *file, MemoryBlock *blk, bool used_only,
const char* filter_path, const size_t filter_len);
inline void MemoryPool::increment_usage(size_t size)
{
size_t temp = stats->mst_usage += size;
@ -897,7 +900,8 @@ bool MemoryPool::verify_pool(bool fast_checks_only) {
return true;
}
static void print_block(FILE *file, MemoryBlock *blk, bool used_only)
static void print_block(FILE *file, MemoryBlock *blk, bool used_only,
const char* filter_path, const size_t filter_len)
{
void *mem = blockToPtr<void*>(blk);
if (((blk->mbk_flags & MBK_USED) &&
@ -919,40 +923,50 @@ static void print_block(FILE *file, MemoryBlock *blk, bool used_only)
int size =
blk->mbk_flags & MBK_LARGE ? blk->mbk_large_length : blk->small.mbk_length;
#ifdef DEBUG_GDS_ALLOC
if (blk->mbk_flags & MBK_USED) {
if (blk->mbk_type > 0)
fprintf(file, "%p%s: size=%d type=%d allocated at %s:%d\n",
mem, flags, size, blk->mbk_type, blk->mbk_file, blk->mbk_line);
else if (blk->mbk_type == 0)
fprintf(file, "%p%s: size=%d allocated at %s:%d\n",
mem, flags, size, blk->mbk_file, blk->mbk_line);
else
fprintf(file, "%p%s: size=%d type=%d\n",
mem, flags, size, blk->mbk_type);
if (blk->mbk_flags & MBK_USED)
{
if (!filter_path || blk->mbk_file
&& !strncmp(filter_path, blk->mbk_file, filter_len))
{
if (blk->mbk_type > 0)
fprintf(file, "%p%s: size=%d type=%d allocated at %s:%d\n",
mem, flags, size, blk->mbk_type, blk->mbk_file, blk->mbk_line);
else if (blk->mbk_type == 0)
fprintf(file, "%p%s: size=%d allocated at %s:%d\n",
mem, flags, size, blk->mbk_file, blk->mbk_line);
else
fprintf(file, "%p%s: size=%d type=%d\n",
mem, flags, size, blk->mbk_type);
}
}
#else
if (blk->mbk_type && (blk->mbk_flags & MBK_USED))
fprintf(file, "%p(%s): size=%d type=%d\n",
fprintf(file, "%p%s: size=%d type=%d\n",
mem, flags, size, blk->mbk_type);
#endif
else
fprintf(file, "%p(%s): size=%d\n",
fprintf(file, "%p%s: size=%d\n",
mem, flags, size);
}
}
void MemoryPool::print_contents(const char* filename, bool used_only) {
void MemoryPool::print_contents(const char* filename, bool used_only,
const char* filter_path)
{
FILE *out = fopen(filename, "w");
print_contents(out, used_only);
print_contents(out, used_only, filter_path);
fclose(out);
}
// This member function can't be const because there are calls to the mutex.
void MemoryPool::print_contents(FILE *file, bool used_only)
void MemoryPool::print_contents(FILE *file, bool used_only,
const char* filter_path)
{
lock.enter();
fprintf(file, "********* Printing contents of pool %p used=%ld mapped=%ld:\n",
this, (long)used_memory.value(), (long)mapped_memory);
const size_t filter_len = filter_path ? strlen(filter_path) : 0;
// Print extents
for (MemoryExtent *extent = extents; extent; extent = extent->mxt_next) {
if (!used_only)
@ -961,7 +975,7 @@ void MemoryPool::print_contents(FILE *file, bool used_only)
;
blk = next_block(blk))
{
print_block(file, blk, used_only);
print_block(file, blk, used_only, filter_path, filter_len);
if (blk->mbk_flags & MBK_LAST)
break;
}
@ -970,7 +984,7 @@ void MemoryPool::print_contents(FILE *file, bool used_only)
if (os_redirected) {
fprintf(file, "LARGE BLOCKS:\n");
for (MemoryBlock *blk = os_redirected; blk; blk = block_list_large(blk)->mrl_next)
print_block(file, blk, used_only);
print_block(file, blk, used_only, filter_path, filter_len);
}
lock.leave();
// Print redirected blocks
@ -978,10 +992,10 @@ void MemoryPool::print_contents(FILE *file, bool used_only)
fprintf(file, "REDIRECTED TO PARENT %p:\n", parent);
parent->lock.enter();
for (MemoryBlock *blk = parent_redirected; blk; blk = block_list_small(blk)->mrl_next)
print_block(file, blk, used_only);
print_block(file, blk, used_only, filter_path, filter_len);
parent->lock.leave();
}
fprintf(file, "********* End of output for pool %p:\n", this);
fprintf(file, "********* End of output for pool %p.\n", this);
}
MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent, MemoryStats &stats)
@ -1729,7 +1743,7 @@ void Firebird::AutoStorage::ProbeStack() const {
char ProbeVar = '\0';
const char *MyStack = &ProbeVar;
const char *ThisLocation = (const char *)this;
int distance = ThisLocation - MyStack;
ptrdiff_t distance = ThisLocation - MyStack;
if (distance < 0) {
distance = -distance;
}

View File

@ -29,7 +29,7 @@
* Alex Peshkoff <peshkoff@mail.ru>
* added PermanentStorage and AutoStorage classes.
*
* $Id: alloc.h,v 1.54 2004-11-16 05:02:02 robocop Exp $
* $Id: alloc.h,v 1.55 2004-11-17 08:55:40 robocop Exp $
*
*/
@ -345,10 +345,11 @@ public:
bool verify_pool(bool fast_checks_only = false);
// Print out pool contents. This is debugging routine
void print_contents(FILE*, bool = false);
void print_contents(FILE*, bool = false, const char* filter_path = 0);
// The same routine, but more easily callable from the debugger
void print_contents(const char* filename, bool = false);
void print_contents(const char* filename, bool = false,
const char* filter_path = 0);
// Deallocate memory block. Pool is derived from block header
static void globalFree(void* block) {

View File

@ -716,7 +716,7 @@ void API_ROUTINE gds_alloc_flag_unfreed(void *blk)
}
void API_ROUTINE gds_alloc_report(ULONG flags, const char* filename, int lineno)
void API_ROUTINE gds_alloc_report(ULONG flags, const char* filter_filename, int lineno)
{
/**************************************
*
@ -730,13 +730,14 @@ void API_ROUTINE gds_alloc_report(ULONG flags, const char* filename, int lineno)
*
**************************************/
// Skidder: Calls to this function must be replaced with MemoryPool::print_contents
char report_name[MAXPATHLEN];
gds__prefix(report_name, "fbsrvreport.txt");
// Our new facilities don't expose flags for reporting.
const bool used_only = !(flags & ALLOC_verbose);
getDefaultMemoryPool()->print_contents(report_name, used_only, filter_filename);
}
/* CVC: See comment below. Basically, it provides the needed const correctness,
but throws away the const to make the callee happy, knowing that the callee
indeed treats vector as it was a pointer with the const prefix. */
/**
isc_interpret
@ -1703,7 +1704,7 @@ void API_ROUTINE gds__prefix(TEXT* resultString, const TEXT* file)
}
ib_prefix = ib_prefix_val;
}
strcat(resultString, ib_prefix);
strcpy(resultString, ib_prefix);
safe_concat_path(resultString, file);
}
#endif /* !defined(VMS) */
@ -3555,7 +3556,7 @@ static void safe_concat_path(TEXT *resultString, const TEXT *appendString)
*
* Functional description
* Safely appends appendString to resultString using paths rules.
* resultString must be at least MAXPATHLEN size.
* resultString must be at most MAXPATHLEN size.
*
**************************************/
int len = strlen(resultString);

View File

@ -221,8 +221,11 @@ LRESULT CALLBACK WindowFunc(HWND hWnd,
{
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
}
#ifdef DEV_BUILD
gds_alloc_report(ALLOC_verbose, "from server", 0);
#ifdef DEBUG_GDS_ALLOC
//gds_alloc_report(ALLOC_verbose, "from server", 0);
char fn[] = __FILE__;
fn[strlen(fn) - 19] = 0; // all remote files
gds_alloc_report(ALLOC_verbose, fn, 0);
#endif
THREAD_ENTER();
JRD_shutdown_all();