Thread overview
[phobos] Is it possible to get Function Time in ticks like profiler give, but at runtime?
Aug 20, 2011
unDEFER
Aug 20, 2011
Jonathan M Davis
Aug 21, 2011
unDEFER
Aug 23, 2011
Jonathan M Davis
Aug 29, 2011
unDEFER
August 20, 2011
Hello, again!
I want one very strange feature. I even don't know if it is really
possible with C for any OS.
But I sure that in D it must be not more complicate to get this
information.

So I want to get how much ticks of CPU was wasted on some function
(including all calls) in real time.
Seems profiler give this information but only when the program was end.
Is it possible to get the same at runtime?
Also is it possible to get profiler info from other process before end of
program?

I know with core.time or std.c.time I can measure real time of function execution, but it will too much different depend on system loading. But I want to get approximately the same numbers at the same point of program.

Thank you in advance!
Sorry if I send this question to not right mail list.

-- 
Nikolay Krivchenkov aka unDEFER
I want to believe... in unDE.su
registered Linux user #360474
Don't worry, I can read OpenOffice.org/Libre Office/Lotus Symphony
documents
August 20, 2011
On Saturday, August 20, 2011 14:10:44 unDEFER wrote:
> Hello, again!
> I want one very strange feature. I even don't know if it is really
> possible with C for any OS.
> But I sure that in D it must be not more complicate to get this
> information.
> 
> So I want to get how much ticks of CPU was wasted on some function
> (including all calls) in real time.
> Seems profiler give this information but only when the program was end.
> Is it possible to get the same at runtime?
> Also is it possible to get profiler info from other process before end of
> program?
> 
> I know with core.time or std.c.time I can measure real time of function execution, but it will too much different depend on system loading. But I want to get approximately the same numbers at the same point of program.
> 
> Thank you in advance!
> Sorry if I send this question to not right mail list.

If you're looking to time how long a function takes to call, then use std.datetime.benchmark. If you're looking to determine how much your specific program calls a particular function and how much time it spends in that function, then compile with -profile, run the program, and then look at the files that it generates. If you want to do the equivalent of -profile at runtime, I don't think that that's really possible, and I'm not quite sure why you'd want to. But even if you could, it would affect the performance of the program and probably skew the results anyway. It would certainly slow down the program a lot. I suppose that you could write a wrapper function for your specific function, time the exact time that it takes on each call with std.datetime.StopWatch, and then send that information to another process via std.socket if you really want something like that. But that sort of thing sounds rather complicated to me, and I have no idea what good the information would do you at runtime anyway. Usually, the reason that people want to profile code is to determine what code they need to optimize make the program faster, and -profile is plenty for that.

- Jonathan M Davis
August 21, 2011
If you really want to understand my goal you can try to read my the next article (sorry for bad english): http://unde.sf.net/estimation-resources

If shortly I just want to estimate CPU using by program also as other
resources like memory.
I just try test `time` output (it prints user time and sys time for any
program in Linux) for loaded and not loaded system and looks like that for
Linux getrusage is what I need.
As I understand there is no any universal methods to get this information
for any OS?

On Sun, 21 Aug 2011 03:58:26 +0400, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> If you're looking to time how long a function takes to call, then use
> std.datetime.benchmark. If you're looking to determine how much your
> specific
> program calls a particular function and how much time it spends in that
> function, then compile with -profile, run the program, and then look at
> the
> files that it generates. If you want to do the equivalent of -profile at
> runtime, I don't think that that's really possible, and I'm not quite
> sure why
> you'd want to. But even if you could, it would affect the performance of
> the
> program and probably skew the results anyway. It would certainly slow
> down the
> program a lot. I suppose that you could write a wrapper function for your
> specific function, time the exact time that it takes on each call with
> std.datetime.StopWatch, and then send that information to another
> process via
> std.socket if you really want something like that. But that sort of thing
> sounds rather complicated to me, and I have no idea what good the
> information
> would do you at runtime anyway. Usually, the reason that people want to
> profile
> code is to determine what code they need to optimize make the program
> faster,
> and -profile is plenty for that.
>
> - Jonathan M Davis

-- 
Nikolay Krivchenkov aka unDEFER
I want to believe... in unDE.su
registered Linux user #360474
Don't worry, I can read OpenOffice.org/Libre Office/Lotus Symphony
documents
August 22, 2011
On Sunday, August 21, 2011 05:21:02 unDEFER wrote:
> If you really want to understand my goal you can try to read my the next article (sorry for bad english): http://unde.sf.net/estimation-resources
> 
> If shortly I just want to estimate CPU using by program also as other
> resources like memory.
> I just try test `time` output (it prints user time and sys time for any
> program in Linux) for loaded and not loaded system and looks like that for
> Linux getrusage is what I need.
> As I understand there is no any universal methods to get this information
> for any OS?

There's pretty much nothing in terms of time-related functions - beyond C's time function - which exist on all OSes.  If you stick to just Posix, you do get a bit more - e.g. gettimeofday - but even then, it varies per OS pretty quickly. This is definitely the sort of thing that you're going to have to handle differently on each OS that you're working with.

- Jonathan M Davis
August 29, 2011
Thank you, Jonathan, I will see methods for all target OS'es.

On Tue, 23 Aug 2011 09:50:12 +0400, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> On Sunday, August 21, 2011 05:21:02 unDEFER wrote:
>> If you really want to understand my goal you can try to read my the next article (sorry for bad english): http://unde.sf.net/estimation-resources
>>
>> If shortly I just want to estimate CPU using by program also as other
>> resources like memory.
>> I just try test `time` output (it prints user time and sys time for any
>> program in Linux) for loaded and not loaded system and looks like that
>> for
>> Linux getrusage is what I need.
>> As I understand there is no any universal methods to get this
>> information
>> for any OS?
>
> There's pretty much nothing in terms of time-related functions - beyond
> C's
> time function - which exist on all OSes.  If you stick to just Posix,
> you do
> get a bit more - e.g. gettimeofday - but even then, it varies per OS
> pretty
> quickly. This is definitely the sort of thing that you're going to have
> to
> handle differently on each OS that you're working with.
>
> - Jonathan M Davis
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


-- 
Nikolay Krivchenkov aka unDEFER
I want to believe... in unDE.su
registered Linux user #360474
Don't worry, I can read OpenOffice.org/Libre Office/Lotus Symphony
documents