mirror of
https://github.com/boostorg/build.git
synced 2026-02-14 00:32:11 +00:00
Variety of performance improvements.
* bjam; bump to version 3.1.12 * bjam; make it possible to build in MinGW/MSYS shell * bjam; move profile code to debug.h/c to make it available for use everywhere * bjam; cache all filesystem query operations, Unix and Windows only, include PWD and scanning * bjam; add memory profile info, and sprinkle throught code * bbv2; rewrite some while() loops into for() loops to reduce time and memory * bbv2; keep a single instance counter instead of one per type to reduce memory use * bjam+bbv2; change NORMALIZE_PATH builtin to join path parts to reduce memory use [SVN r31177]
This commit is contained in:
127
src/engine/debug.c
Normal file
127
src/engine/debug.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Copyright Rene Rivera 2005.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
# include "jam.h"
|
||||
# include "debug.h"
|
||||
|
||||
# include "hash.h"
|
||||
|
||||
# include <time.h>
|
||||
# include <assert.h>
|
||||
|
||||
static profile_frame* profile_stack = 0;
|
||||
static struct hash* profile_hash = 0;
|
||||
static profile_info profile_other = { "[OTHER]", 0, 0, 0, 0, 0 };
|
||||
static profile_info profile_total = { "[TOTAL]", 0, 0, 0, 0, 0 };
|
||||
|
||||
profile_frame* profile_init( char* rulename, profile_frame* frame )
|
||||
{
|
||||
if ( DEBUG_PROFILE ) profile_enter(rulename,frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
void profile_enter( char* rulename, profile_frame* frame )
|
||||
{
|
||||
if ( DEBUG_PROFILE )
|
||||
{
|
||||
clock_t start = clock();
|
||||
profile_info info, *p = &info;
|
||||
|
||||
if ( !rulename ) p = &profile_other;
|
||||
|
||||
if ( !profile_hash )
|
||||
{
|
||||
if ( rulename ) profile_hash = hashinit(sizeof(profile_info), "profile");
|
||||
}
|
||||
|
||||
info.name = rulename;
|
||||
|
||||
if ( rulename && hashenter( profile_hash, (HASHDATA **)&p ) )
|
||||
p->cumulative = p->net = p->num_entries = p->stack_count = p->memory = 0;
|
||||
|
||||
++(p->num_entries);
|
||||
++(p->stack_count);
|
||||
|
||||
frame->info = p;
|
||||
|
||||
frame->caller = profile_stack;
|
||||
profile_stack = frame;
|
||||
|
||||
frame->entry_time = clock();
|
||||
frame->overhead = 0;
|
||||
frame->subrules = 0;
|
||||
|
||||
/* caller pays for the time it takes to play with the hash table */
|
||||
if ( frame->caller )
|
||||
frame->caller->overhead += frame->entry_time - start;
|
||||
}
|
||||
}
|
||||
|
||||
void profile_memory( long mem )
|
||||
{
|
||||
if ( DEBUG_PROFILE )
|
||||
{
|
||||
if ( profile_stack && profile_stack->info )
|
||||
{
|
||||
profile_stack->info->memory += mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void profile_exit(profile_frame* frame)
|
||||
{
|
||||
if ( DEBUG_PROFILE )
|
||||
{
|
||||
/* cumulative time for this call */
|
||||
clock_t t = clock() - frame->entry_time - frame->overhead;
|
||||
/* If this rule is already present on the stack, don't add the time for
|
||||
this instance. */
|
||||
if (frame->info->stack_count == 1)
|
||||
frame->info->cumulative += t;
|
||||
/* Net time does not depend on presense of the same rule in call stack. */
|
||||
frame->info->net += t - frame->subrules;
|
||||
|
||||
if (frame->caller)
|
||||
{
|
||||
/* caller's cumulative time must account for this overhead */
|
||||
frame->caller->overhead += frame->overhead;
|
||||
frame->caller->subrules += t;
|
||||
}
|
||||
/* pop this stack frame */
|
||||
--frame->info->stack_count;
|
||||
profile_stack = frame->caller;
|
||||
}
|
||||
}
|
||||
|
||||
static void dump_profile_entry(void* p_, void* ignored)
|
||||
{
|
||||
profile_info* p = (profile_info*)p_;
|
||||
unsigned long mem_each = (p->memory/(p->num_entries ? p->num_entries : 1));
|
||||
double q = p->net; q /= (p->num_entries ? p->num_entries : 1);
|
||||
if (!ignored)
|
||||
{
|
||||
profile_total.cumulative += p->net;
|
||||
profile_total.memory += p->memory;
|
||||
}
|
||||
printf("%10d %10d %10d %12.6f %10d %10d %s\n",
|
||||
p->num_entries, p->cumulative, p->net, q,
|
||||
p->memory, mem_each,
|
||||
p->name);
|
||||
}
|
||||
|
||||
void profile_dump()
|
||||
{
|
||||
if ( profile_hash )
|
||||
{
|
||||
printf("%10s %10s %10s %12s %10s %10s %s\n",
|
||||
"--count--", "--gross--", "--net--", "--each--",
|
||||
"--mem--", "--each--",
|
||||
"--name--");
|
||||
hashenumerate( profile_hash, dump_profile_entry, 0 );
|
||||
dump_profile_entry(&profile_other,0);
|
||||
dump_profile_entry(&profile_total,(void*)1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user