473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

some profiler questions

Mac
I'm writing a bunch of algorithms in Python for solving a certain class
of problems, and I was interested in doing some comparisons between
them and would like to collect various high-level runtime stats, such
as the number of invocations of certain key subroutines. I have my own
code to do this. Then just earlier today it hit me that I'm really
just profiling, albeit in a more restricted way than the "profile"
module. This got me thinking and looking deeper at "profile.py", and
I've got some questions:

1) I'd still like to run my whole app (i.e., using main()), but I'd
like to limit the profiling to only the select few subroutines. That
is, say I have a set of such fns in mind, call it "key_fns", and I
would like to only profile # of invocations of these fns from key_fns,
as well as by whom they were called, and how much cumulative time was
spent in them. Is such lower-level control possible? The main reason
I want this is that I do not want to profile most of the low-level
routines, like vector addition, at least not yet... I don't want to
slow down code execution any more than is necessary, as the statistics
gathering should occur during "normal" runs (i.e., during normal
operation).

2) I've only just discovered that pstats has "print_callers()"! That's
very useful info I wasn't aware was available! What I'm really looking
for now is profiler output in the style generated by "gprof", the GNU
profiler, as I have found that format terribly useful (a section for
each fn, with the fn's callers and callees interwoven in each section).
Does anyone know of a utility which would format the Python profiling
info in that format, or something very similar? I haven't actually
seen any output from print_callers (can't find any samples on Net, and
my app is currently half-busted, mid-refactor), so if that's what it
precisely does, ignore this question.

3) assuming the above-mentioned fine control of (1) is not yet
possible, I will muddle on with my own "selective" profiling code; the
question I have then is, what is the cleanest way to override a class
instance's method at runtime? What my profiler is doing is overriding
the key fns/methods of an instance with a stat-gatherer-instrumented
version, which ends up calling the original method. I tried reading
profile.py and pstats.py for ideas, but they are a little too
complicated for me, for now; I doubt that's how they do their profiling
anyways. Any way to do this in an automated fashion, given that I have
the list of method names I want to instrument in a list variable?

Jul 19 '05 #1
1 1109
"Mac" <id******************@yahoo.com> writes on 7 Jun 2005 20:38:51 -0700:
....
1) I'd still like to run my whole app (i.e., using main()), but I'd
like to limit the profiling to only the select few subroutines. That
is, say I have a set of such fns in mind, call it "key_fns", and I
would like to only profile # of invocations of these fns from key_fns,
as well as by whom they were called, and how much cumulative time was
spent in them. Is such lower-level control possible? The main reason
I want this is that I do not want to profile most of the low-level
routines, like vector addition, at least not yet... I don't want to
slow down code execution any more than is necessary, as the statistics
gathering should occur during "normal" runs (i.e., during normal
operation).
Please read the "How it works section".

You find an example how the profiler can be customized
in my "ZopeProfiler" product (the "HLProfiler.py").
It makes profiling slower (as it derives high level profiles
in addition to the low level ones) but might nevertheless
help you as an example.

<http://www.dieter.handshake.de/pyprojects/zope>
2) I've only just discovered that pstats has "print_callers()"! That's
very useful info I wasn't aware was available! What I'm really looking
for now is profiler output in the style generated by "gprof", the GNU
profiler, as I have found that format terribly useful (a section for
each fn, with the fn's callers and callees interwoven in each section).
Does anyone know of a utility which would format the Python profiling
info in that format, or something very similar? I haven't actually
seen any output from print_callers (can't find any samples on Net, and
my app is currently half-busted, mid-refactor), so if that's what it
precisely does, ignore this question.
Thus, you look at the internal representation of "pstats"
and format it in the way you like...
3) assuming the above-mentioned fine control of (1) is not yet
possible, I will muddle on with my own "selective" profiling code; the
question I have then is, what is the cleanest way to override a class
instance's method at runtime?
class_.f = some_wrapper(class_.f)
What my profiler is doing is overriding
the key fns/methods of an instance with a stat-gatherer-instrumented
version, which ends up calling the original method. I tried reading
profile.py and pstats.py for ideas, but they are a little too
complicated for me, for now; I doubt that's how they do their profiling
anyways.


You should read the "How it works section".
You will find out that your doubt is justified...
Dieter
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeff Mair | last post by:
Hello all, I haven't been using profiler for a terribly long time, and I've come across something that I just can't figure out. I'm running MS Virtual PC to run a Win2K Server OS with SQL...
8
by: patrickshroads | last post by:
I am running a profiler trace against a database and noticed that the reads column always shows 0. When running the same trace against another machine I get back values in the reads column. I took...
0
by: DraguVaso | last post by:
Hi, I'm using for a while DevPartner Profiler (http://www.compuware.com/products/devpartner/resources/profiler/profiler.as p), but unfortunately it works only for 2002 and 2003. Is there a...
4
by: pnp | last post by:
Which is the best profiler for C# apps? Thanks in advance, Peter
3
by: Rajko | last post by:
Does anyone know any program which could be used as profiler for programs written in .NET? Thx, Rajko.
3
by: Maansi Gupta | last post by:
Platform - Windows 2000 Professional , VC .NET 7.1 Hello, I have recently ported my source code from Visual Studio 6.0 to .NET 7.1 Previously with Visual Studio 6.0 I was using the profiler...
5
by: SharpSmith | last post by:
hi all the question is more related to architecture and practices and I'll appreciate any opinion i work with asp net 1/2 few years and with any project we developing we meet performance issues...
3
by: akkha1234 | last post by:
I am using SQL Profiler to monitor one of my database. The temporary trace file is stored under C:\Documents and Settings\user \Local Settings\Temp by default. Is it possible to re-configure it to...
1
by: ofirmgr | last post by:
im trying to understand how the profiler works. so i started 2 profilers,one listen to another and I saw the profiler is running: exec sp_trace_create @P1 output, 1, NULL, NULL, NULL which means...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.