<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<font style="font-size:10pt;" color="#366092" face="Tahoma" size="2">Thanks Thomas! I will try the timer code that you provided. I have tried profiling with just wrapping the python code with cprofiler's runctx but the problem is that my python code is sort of a packet parser and is called for each packet, but when I see the profiled results  it appears that the profile gets rewritten for each packet and I can't see the aggregate result: I see 1-2 calls per function and each call is shown to have taken 0.00 time.<br><br>I have also tried valgrind's callgrind in conjunction with kcachegrind but it doesn't seem to show time measurement and by some reading I learned that it gives the CPU cycle's per function and not time. Any suggestions in this regard will also be very helpful.. Thanks!<br><br>Salman<br id="FontBreak"></font><br><br><div><div id="SkyDrivePlaceholder"></div>> Date: Sat, 7 Jul 2012 11:50:05 +0200<br>> From: t@jollybox.de<br>> To: python-list@python.org<br>> Subject: Re: PyEval_SetProfile usage ?<br>> <br>> On 07/06/2012 11:40 PM, Salman Malik wrote:<br>> > Hi All,<br>> > <br>> > I have used the Python's C-API to call some Python code in my c code and<br>> > now I want to know how much time does my Python part of the program<br>> > takes. I came across the PyEval_SetProfile API and am not sure how to<br>> > use it. Do I need to write my own profiling function?<br>> <br>> You could have a look at the source code of the cProfile extension<br>> module. I assume it uses the feature.<br>> <br>> In your case, what's wrong with simply measuring the time?<br>> <br>> <br>> /* variables. */<br>> unsigned long delta_usec;<br>> struct timeval t1, t2;<br>> <br>> /* get start time */<br>> gettimeofday (&t1, NULL);<br>> <br>> /* DO PYTHON STUFF */<br>> <br>> /* get end time */<br>> gettimeofday (&t2, NULL);<br>> <br>> /* delta? */<br>> delta_usec = (t2.tv_sec - t1.tv_sec) * 1000<br>>            + (signed)(t2.tv_usec - t1.tv_usec);<br>> <br>> /* if your Python code is called multiple times, do this for each one,<br>>    and (if you like) sum up the result. It's simpe enough, and you<br>>    don't have to mess with profiling function.<br>>    Alternatively, you could use a C profiler like Valgrind<br>> */<br>> -- <br>> http://mail.python.org/mailman/listinfo/python-list<br></div>                                    </div></body>
</html>