Re: [C++-sig] profiling python extension

2010-03-01 Thread John Reid

Alexey Akimov wrote:

Thank you John,

I just installed the tool you suggested and tried to use it. However I 
do not see any output. Could you give some more detailes of how the 
profiling process with the google-profiler should look like?

What I do is:

1) bjam variant=profile toolset=gcc cxxflags=-fno-for-scope 
linkflags=-lprofiler test_ext


2) env CPUPROFILE=/path/to/my/dir/out.prof python ./mypythonscript.py

This runs my python script which invokes the extension. However it does 
not produce any output files (which i expect to be out.prof in my 
working directory). What should I do in order to see the profiling 
information?


I use the profiler via explicit calls to ProfilerStart() and 
ProfilerStop() which I expose through boost.python and call in my python 
scripts. Then I can start and stop the profiler at will.


However from what I can see in the documentation what you've done looks 
correct as well. I suppose you could ask bjam to show you the link 
command to check it is using "-lprofiler".


___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] incorrect linking to libpython (Dane Springmeyer)

2010-03-01 Thread Amos Anderson
>
> Message: 2
> Date: Fri, 26 Feb 2010 18:36:16 -0800
> From: Dane Springmeyer 
> To: Development of Python/C++ integration 
> Subject: Re: [C++-sig] incorrect linking to libpython
> Message-ID: <57569986-7d90-4686-8384-809f8d27f...@hailmail.net>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
> Amos,
>
> I feel your pain, seriously. I've been down many of these paths as well.
>
> My overall sense is that direct linking of boost to a python
> executable may not be necessary, and rather that bjam could use `-
> undefined dynamic_lookup`, which will mean that when you import the
> python module you've built with boost::python the right version of
> python will be dynamically looked up based on the interpreter you are
> running. There are certainly potential problems with this route (and
> I've only lightly tested so far) but I think it may hold promise.
>
> More to the point, I've also got into the habit of passing -Z to the
> linker to make sure that if the custom python framework is not able to
> be linked, ld does not fallback to linking to the "system" or apple
> provided python framework and rather throws an error so you know the
> exact point things went wrong rather than only later by getting the
> dreaded "Version Mismatch" error.
>
> Failing to link to the /Library or user installed python26 is almost
> invariably the case on snow leopard because two copies will exist and
> the user installed version won't be preferentially linked with the
> normal -L/path/to/dir -lpython2.6 method because 'libpython2.6' is
> actually:
>
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/
> libpython2.6.a
>
> and my sense is the linker will prefer the /usr/lib/libpython2.6.dylib
> over that because of the 'a' (even though it is actually, and oddly, a
> symlink to the dynamic library at:
>
> /Library/Frameworks/Python.framework/Versions/2.6/Python
>
> So, one workaround is symlinking:
>
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/
> libpython2.6.dylib  -> ../../../Python
>
> Then bjam should be able to find it.
>
> But I think a preferable method would be if bjam actually sent the
> linker line:
>
> -F/Library/Library/Frameworks -framework Python -Z
>
> instead of -L/etc/etc -lpython...
>
>
> Dane
>
>
> More info on those ld commands at:
> http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/ld.1.html


I can confirm that your solution fixed the problem. Actually, I just did this:

sudo cp libpython2.6.a libpython2.6.dylib

(and recompiled boost python)

Thanks!

Amos.
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] boost python constructor for tr1::array

2010-03-01 Thread Amos Anderson
Hello -- i've got a wrapper for a tr1::array, but i don't know how to
make a constructor for it.

i have something like:
//some stuff defining functions
//...
   class_ > (ss.str().c_str())
  .def("__getitem__", get,
return_value_policy())
  .def("__setitem__", &array_setitem)
  .def("__iter__", range >
   (vecbegin, vecend))
   ;

where the name will end up being something like "Array2_double". In my
python code right now, I have do to something like this:
pair = Array2_double()
pair[0] = 0.1
pair[1] = 1.2

But I'd like to do this:
pair = Array2_double(0.1, 1.2)

or even better:
listOfPairs = Vector_Array2_double()
listOfPairs.append(0.1, 1.2)

i've been able to follow the tutorials etc for simple classes, but
nothing i've tried for this will compile. well, i know i could make an
external function:
pair = make_Array2_double(0.1,1.2)
if i really wanted to, but i don't know how to do this within
templates, so i think i'd have to make all those separately.

thanks!

Amos.
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig