Boost logo

Boost-Build :

From: Pedro Ferreira (pedro.ferreira_at_[hidden])
Date: 2003-10-15 04:46:43


Hi Volodya,

> > Note that, for 1000 files, find-project-root is called 3008 times and
> > returing a fixed string reduced the gross time from 22056 ms to 10 ms.
>
> Ehm... I think that's good to see the reduction, though it's probably not
good
> to call this rule that many times.

Right. I was just trying to figure out that.
BTW, is there a way to print out a stack trace in a Jam rule?

> Could you send me your script so that I
> can figure out the origin of that number of calls? And, maybe, the script
> should go to CVS....

It is attached.

The Jamfile it generates is a bit complex for this purpose: it is based on a
Jamfile generator I wrote for our projects and I use it so I can better
simulate what happens with our own projects. Anyway, I have tried it without
all the 'overhead' and it really doesn't affect performance.

> > Would it be possible to cache the value instead of globbing every time?
Is
> > there a map-like container in jam?
>
> Unless I find some deeper inefficiency, I'm really willing to commit the
> change that Rene proposed.

Ok.

Cheers,

Pedro

 ------=_NextPart_000_004F_01C39309.9FB342E0 Content-Type: text/plain;
name="profile_jam.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="profile_jam.py"

import sys
import time
import os
import os.path
import shutil
import string

cpp_data = """
"""

header_data = """
"""

jam_header = """local target-name = ProfileJam ;
local project-name = ProfileJam/src/ProfileJam ;
local is-lib-macro = PROFILEJAM_IS_LIB ;

local project-macros =
PROFILEJAM_EXPORTS
;

local cpp-sources =
"""

jam_footer = """
;

local dependencies =
;

local stageable-dependencies =
;

##########################################################################
# Boilerplate code
#
import path ;
import feature : feature compose ;

feature unicode : off on : link-incompatible propagated ;
feature.set-default unicode : off ;

##########################################################################
# Independent variables
#
local stage-dir = [ modules.peek : STAGE_DIR ] ;
workspace-root = [ path.reverse $(project-name) ] ;

local win32-dll-preprocessor-defines =
<define>WIN32
<define>_WINDOWS
<link>shared:<define>_AFXDLL
<variant>debug:<define>_DEBUG
;

local common-properties =
$(win32-dll-preprocessor-defines)
<link>static:<tag>s
<variant>debug:<tag>_d
<variant>release:<tag>_r
<variant>profile:<tag>_p
<unicode>on:<tag>u
<unicode>on:<define>_UNICODE
<unicode>on:<define>UNICODE
<link>static:<use>$(dependencies)
<link>shared:<library>$(dependencies)
<link>static:<define>$(is-lib-macro)
<link>shared:<define>$(project-macros)
;

local common-requirements =
<link>static:<define>$(is-lib-macro)
;

##########################################################################
# Project name
#
project $(project-name)
:
requirements <include>.
:

:
build-dir $(workspace-root)
;

##########################################################################
# Targets
#

lib $(target-name)
:
$(cpp-sources)
:
$(common-properties)
:
:
$(common-requirements)
;

stage stage-bin
:
$(target-name)
$(stageable-dependencies)
:
<location>$(stage-dir)
;
"""

def create_file (filename, data):
f = open (filename, "w")
f.write (data)
f.close ()

def delete_tree (base_dir):
if (os.path.isdir (base_dir)):
shutil.rmtree (base_dir)

def generate_includes (n_header_files):
data = ""
for i in range (0, n_header_files):
data = data + '#include "ProfileJam/' + str (i) + '.h"\n'

return data

def create_files (base_dir, n_files, n_header_files):
os.makedirs (base_dir)
data = generate_includes (n_header_files)
data = data + cpp_data
files = []
for i in range (0, n_files):
file = str (i) + ".cpp"
files.append (file)
file = base_dir + file
create_file (file, data)

return files

def create_header_files (base_dir, n_files):
os.makedirs (base_dir)
for i in range (0, n_files):
file = base_dir + str (i) + ".h"
create_file (file, header_data)

def generate_root_jamfile (base_dir):
create_file ("Jamfile", "build-project " + base_dir + " ;")

def generate_project_root ():
create_file ("project-root.jam", "")

def generate_jamfile (base_dir, files):
data = jam_header

for file in files:
data += " " + file + "\n"

data += jam_footer
create_file (base_dir + "/Jamfile", data)

def run_jam (id):
filename = str (id) + ".out"
cmd = "bjam -n -d+10 > " + filename
result = os.system (cmd)
if (result != 0):
raise Exception, "Failed to run jam"

def do_it (n_files, n_header_files):
base_dir = "src/ProfileJam/"
header_base_dir = "include/ProfileJam/"

delete_tree (base_dir)
delete_tree (header_base_dir)
files = create_files (base_dir, n_files, n_header_files)
create_header_files (header_base_dir, n_header_files)

generate_project_root ()
generate_root_jamfile (base_dir)
generate_jamfile (base_dir, files)

start_time = time.time ()

run_jam (n_files)

end_time = time.time ()

elapsed = end_time - start_time
print '# files %4d' % n_files,
print 'Elapsed:', string.rjust ('%3.3f' % elapsed, 7)

if __name__ == '__main__':
n_headers = 10

do_it (1, n_headers)
do_it (5, n_headers)
do_it (10, n_headers)
do_it (50, n_headers)
do_it (100, n_headers)
do_it (200, n_headers)
do_it (300, n_headers)
do_it (500, n_headers)
do_it (1000, n_headers)
 ------=_NextPart_000_004F_01C39309.9FB342E0--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk