diff -r 563b0557dcb9 -r 80a0423ec9e5 src/SConscript --- a/src/SConscript Fri Sep 14 16:06:40 2012 +0100 +++ b/src/SConscript Fri Sep 14 16:12:26 2012 +0100 @@ -932,14 +932,18 @@ envList.append(new_env) # Create the ccflags and ldflags for the different targets and compilers -target_types = ['debug', 'opt', 'fast', 'prof'] +target_types = ['debug', 'opt', 'fast', 'prof', 'perf'] # Start out with the compiler flags common to all compilers, -# i.e. they all use -g for opt and -g -pg for prof -ccflags = dict(zip(target_types, [[], ['-g'], [], ['-g', '-pg']])) +# i.e. they all use -g for opt, -g -pg for prof, and -g for perf +ccflags = dict(zip(target_types, [[], ['-g'], [], ['-g', '-pg'], ['-g']])) -# Start out with the linker flags common to all linkers, i.e. -pg for prof. -ldflags = dict(zip(target_types, [[], [], [], ['-pg']])) +# Start out with the linker flags common to all linkers, i.e. -pg for +# prof, and -lprofiler for perf. The -lprofile flag is surrounded by +# no-as-needed and as-needed as the binutils linker is too clever and +# simply doesn't link to the library otherwise. +perf_ldflags = ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed'] +ldflags = dict(zip(target_types, [[], [], [], ['-pg'], perf_ldflags])) if env['GCC']: if sys.platform == 'sunos5': @@ -947,34 +951,37 @@ else: ccflags['debug'] += ['-ggdb3'] ldflags['debug'] += ['-O0'] - # opt, fast and prof all share the same cc flags - for target in ['opt', 'fast', 'prof']: + # opt, fast, prof and perf all share the same cc flags + for target in ['opt', 'fast', 'prof', 'perf']: ccflags[target] += ['-O3'] elif env['SUNCC']: ccflags['debug'] += ['-g0'] ccflags['opt'] += ['-O'] - ccflags['fast'] += ['-fast'] - ccflags['prof'] += ['-fast'] + for target in ['fast', 'prof', 'perf']: + ccflags[target] += ['-fast'] elif env['ICC']: ccflags['debug'] += ['-g', '-O0'] ccflags['opt'] += ['-O'] - ccflags['fast'] += ['-fast'] - ccflags['prof'] += ['-fast'] + for target in ['fast', 'prof', 'perf']: + ccflags[target] += ['-fast'] elif env['CLANG']: ccflags['debug'] += ['-g', '-O0'] - ccflags['opt'] += ['-O3'] - ccflags['fast'] += ['-O3'] - ccflags['prof'] += ['-O3'] + # opt, fast, prof and perf all share the same cc flags + for target in ['opt', 'fast', 'prof', 'perf']: + ccflags[target] += ['-O3'] else: print 'Unknown compiler, please fix compiler options' Exit(1) # To speed things up, we only instantiate the build environments we -# need. We try to identify the needed environment for each target; if +# need. We try to identify the needed environment for each target; if # we can't, we fall back on instantiating all the environments just to -# be safe. -obj2target = dict(zip(['do', 'o', 'fo', 'po'], target_types)) +# be safe. The object files are named according to the target, with do +# for debug, o for opt, fo for fast, po for prof, and gpo for +# google-pprof. The file ending .go doesn't work as this suffix is +# recognized by gcc as a Go source file. +obj2target = dict(zip(['do', 'o', 'fo', 'po', 'gpo'], target_types)) def identifyTarget(t): ext = t.split('.')[-1] @@ -1012,11 +1019,18 @@ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], LINKFLAGS = Split(ldflags['fast'])) -# Profiled binary +# Profiled binary using gprof if 'prof' in needed_envs: makeEnv('prof', '.po', CCFLAGS = Split(ccflags['prof']), CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], LINKFLAGS = Split(ldflags['prof'])) +# Profiled binary using google-pprof +if 'perf' in needed_envs: + makeEnv('perf', '.gpo', + CCFLAGS = Split(ccflags['perf']), + CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], + LINKFLAGS = Split(ldflags['perf'])) + Return('envList')