comp.lang.ada
 help / color / mirror / Atom feed
* CPU time for Win32 & GNAT
@ 2001-10-12 11:21 Gautier
  2001-10-12 13:50 ` Pat Rogers
  2001-10-12 14:36 ` Ted Dennison
  0 siblings, 2 replies; 10+ messages in thread
From: Gautier @ 2001-10-12 11:21 UTC (permalink / raw)


Hi!

Does someone know how to obtain the CPU time (or a CPU
duration...) for Win32 (under GNAT) in a simple way ?
The program doesn't use tasking and no more resolution
than the one of Duration is needed for time spans.
I'm sure someone has a ready-made function in his/her toolbox...

TIA

________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!
    Ne r�pondez pas � l'exp�diteur, visitez le site ouaibe!



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 11:21 CPU time for Win32 & GNAT Gautier
@ 2001-10-12 13:50 ` Pat Rogers
  2001-10-12 14:43   ` Ted Dennison
  2001-10-12 14:36 ` Ted Dennison
  1 sibling, 1 reply; 10+ messages in thread
From: Pat Rogers @ 2001-10-12 13:50 UTC (permalink / raw)


"Gautier" <gautier_niouzes@hotmail.com> wrote in message
news:17cd177c.0110120321.3077bccf@posting.google.com...
> Hi!
>
> Does someone know how to obtain the CPU time (or a CPU
> duration...) for Win32 (under GNAT) in a simple way ?
> The program doesn't use tasking and no more resolution
> than the one of Duration is needed for time spans.
> I'm sure someone has a ready-made function in his/her toolbox...

Better yet, why not use the Pentium ReadTimeStampCounter (RDTSC)
instruction?  It samples the register that keeps a count of the number of
clock cycles since boot-up.  Given the exact clock speed you can compute
exactly how much time has elapsed between two samples.


with Interfaces;

package Pentium_Cycle_Counter is

  pragma Suppress( All_Checks );

  type Count is new Interfaces.Unsigned_64;

  function Sample return Count;

  pragma Inline( Sample );

end Pentium_Cycle_Counter;


with Machine_Code;

package body Pentium_Cycle_Counter is

  use Machine_Code;

  function Sample return Count is
    Result : Count;
  begin
    Asm( "RDTSC", Count'Asm_Output("=A",Result), Volatile => True );
    return Result;
  end Sample;

end Pentium_Cycle_Counter;


---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com          Real-Time/OO Languages
progers@classwide.com               Hard Deadline Schedulability Analysis
(281)648-3165                                 Software Fault Tolerance





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 11:21 CPU time for Win32 & GNAT Gautier
  2001-10-12 13:50 ` Pat Rogers
@ 2001-10-12 14:36 ` Ted Dennison
  2001-10-12 18:30   ` Sune Falck
  1 sibling, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2001-10-12 14:36 UTC (permalink / raw)


In article <17cd177c.0110120321.3077bccf@posting.google.com>, Gautier says...
>Does someone know how to obtain the CPU time (or a CPU
>duration...) for Win32 (under GNAT) in a simple way ?
>The program doesn't use tasking and no more resolution
>than the one of Duration is needed for time spans.
>I'm sure someone has a ready-made function in his/her toolbox...

There's probably some neat little trick out there (have you tried using bash?).

I believe the programatic way to do it depends on your OS. For NT-based OS's,
you can gather "performance information" from the registry. That is how the NT
task manager and perfmon gather their information. For Win9x OS's, you have to
do it in a completely different way (which doesn't work on NT).

The current version of the SETI@Home Service uses the NT performance information
to check to see if certian executables are running (so that it can stop SETI
processing). If you download the source distribution, you can look at how it is
done. There's also an NT performance information helper package in there you can
use under the GPL, but its in a primitive state right now.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 13:50 ` Pat Rogers
@ 2001-10-12 14:43   ` Ted Dennison
  2001-10-12 14:48     ` Pat Rogers
  0 siblings, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2001-10-12 14:43 UTC (permalink / raw)


In article <oyCx7.10592$Lz2.3580572774@newssvr30.news.prodigy.com>, Pat Rogers
says...
>
>"Gautier" <gautier_niouzes@hotmail.com> wrote in message
>news:17cd177c.0110120321.3077bccf@posting.google.com...
>> Does someone know how to obtain the CPU time (or a CPU
>> duration...) for Win32 (under GNAT) in a simple way ?
>> The program doesn't use tasking and no more resolution
>> than the one of Duration is needed for time spans.
>> I'm sure someone has a ready-made function in his/her toolbox...
>
>Better yet, why not use the Pentium ReadTimeStampCounter (RDTSC)
>instruction?  It samples the register that keeps a count of the number of
>clock cycles since boot-up.  Given the exact clock speed you can compute
>exactly how much time has elapsed between two samples.

I think he wants elapsed CPU time for his process, not for the whole system.
That would essentially just give him wall time (really really precise wall
time).

Is that instruction avalilable in ring 3?

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 14:43   ` Ted Dennison
@ 2001-10-12 14:48     ` Pat Rogers
  2001-10-12 17:17       ` Ted Dennison
  0 siblings, 1 reply; 10+ messages in thread
From: Pat Rogers @ 2001-10-12 14:48 UTC (permalink / raw)


"Ted Dennison" <dennison@telepath.com> wrote in message
news:tkDx7.26129$ev2.34679@www.newsranger.com...
> In article <oyCx7.10592$Lz2.3580572774@newssvr30.news.prodigy.com>, Pat
Rogers
> says...
> >
> >"Gautier" <gautier_niouzes@hotmail.com> wrote in message
> >news:17cd177c.0110120321.3077bccf@posting.google.com...
> >> Does someone know how to obtain the CPU time (or a CPU
> >> duration...) for Win32 (under GNAT) in a simple way ?
> >> The program doesn't use tasking and no more resolution
> >> than the one of Duration is needed for time spans.
> >> I'm sure someone has a ready-made function in his/her toolbox...
> >
> >Better yet, why not use the Pentium ReadTimeStampCounter (RDTSC)
> >instruction?  It samples the register that keeps a count of the number of
> >clock cycles since boot-up.  Given the exact clock speed you can compute
> >exactly how much time has elapsed between two samples.
>
> I think he wants elapsed CPU time for his process, not for the whole
system.
> That would essentially just give him wall time (really really precise wall
> time).
>
> Is that instruction avalilable in ring 3?

I can't say.  (I know I can trust you -- I just don't know!  :-)





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 14:48     ` Pat Rogers
@ 2001-10-12 17:17       ` Ted Dennison
  0 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 2001-10-12 17:17 UTC (permalink / raw)


In article <WoDx7.10597$sj3.3583583254@newssvr30.news.prodigy.com>, Pat Rogers
says...
>
>"Ted Dennison" <dennison@telepath.com> wrote in message
>news:tkDx7.26129$ev2.34679@www.newsranger.com...
>> In article <oyCx7.10592$Lz2.3580572774@newssvr30.news.prodigy.com>, Pat
>Rogers
>> says...
>> >Better yet, why not use the Pentium ReadTimeStampCounter (RDTSC)

>> Is that instruction avalilable in ring 3?
>
>I can't say.  (I know I can trust you -- I just don't know!  :-)

Well, I've found lots of examples of its use mixed with user calls from various
OS's, so I guess so. Thinking about it, I can't come up with any reason why it
would be a security or stability problem, but then again the bad guys are always
way more creative than I am. 

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-12 14:36 ` Ted Dennison
@ 2001-10-12 18:30   ` Sune Falck
  0 siblings, 0 replies; 10+ messages in thread
From: Sune Falck @ 2001-10-12 18:30 UTC (permalink / raw)


If you want to fetch elapsed time, cpu time in user mode and cpu time in
kernel mode
have a look at the system call GetProcessTimes.

A sample:

...
      Created : aliased Win32.Winbase.FILETIME;
      Exited  : aliased Win32.Winbase.FILETIME;
      User    : aliased Win32.Winbase.FILETIME;
      Kernel  : aliased Win32.Winbase.FILETIME;

      Ok          : Win32.BOOL;
   begin
      Ok :=  Win32.Winbase.GetProcessTimes (Win32.Winbase.GetCurrentProcess,
                                            Created'Unchecked_Access,
                                            Exited'Unchecked_Access,
                                            User'Unchecked_Access,
                                            Kernel'Unchecked_Access);
...

Sune Falck






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
@ 2001-10-14 19:54 Gautier Write-only-address
  2001-10-15 14:33 ` Ted Dennison
  0 siblings, 1 reply; 10+ messages in thread
From: Gautier Write-only-address @ 2001-10-14 19:54 UTC (permalink / raw)
  To: comp.lang.ada

Ted:

> > I think he wants elapsed CPU time for his process, not for the whole
>system.
> > That would essentially just give him wall time (really really precise 
>wall
> > time).
> >
> > Is that instruction avalilable in ring 3?

Pat:

>I can't say.  (I know I can trust you -- I just don't know!  :-)

Effectively, I'm looking for the time elapsed during the
process, not the wall-clock time.

Ideally I'm looking for something like

  function Process_Clock return Process_Time;

and of course...

  function "-"(T2,T1:Process_Time) return Duration;

but just an indication of a Win32 function to use would already
be sufficient (I'll do the rest!).

Thx

Gautier


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
@ 2001-10-15  9:47 Gautier Write-only-address
  0 siblings, 0 replies; 10+ messages in thread
From: Gautier Write-only-address @ 2001-10-15  9:47 UTC (permalink / raw)
  To: comp.lang.ada

Sune Falck

>If you want to fetch elapsed time, cpu time in user mode and cpu time
>in kernel mode have a look at the system call GetProcessTimes.

Thank you very much! It seems to be exactly what I'm looking for.
____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: Do not answer to sender address, visit the Web site!
    Ne r�pondez pas � l'exp�diteur, visitez le site ouaibe!


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: CPU time for Win32 & GNAT
  2001-10-14 19:54 Gautier Write-only-address
@ 2001-10-15 14:33 ` Ted Dennison
  0 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 2001-10-15 14:33 UTC (permalink / raw)


In article <mailman.1003089321.30613.comp.lang.ada@ada.eu.org>, Gautier
Write-only-address says...
>
>Ted:
>Ideally I'm looking for something like
>
>  function Process_Clock return Process_Time;
>
>and of course...
>
>  function "-"(T2,T1:Process_Time) return Duration;
>
>but just an indication of a Win32 function to use would already
>be sufficient (I'll do the rest!).

I'm glad to see someone came up with one for you (in another post).

The way I was talking about doing it (performance information from the registry)
is *way* more complicated than just making a single Win32 function call. There's
a series of at least 5 calls that have to be made, the way I remember it. That's
why I had to create a helper package for it.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-10-15 14:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-12 11:21 CPU time for Win32 & GNAT Gautier
2001-10-12 13:50 ` Pat Rogers
2001-10-12 14:43   ` Ted Dennison
2001-10-12 14:48     ` Pat Rogers
2001-10-12 17:17       ` Ted Dennison
2001-10-12 14:36 ` Ted Dennison
2001-10-12 18:30   ` Sune Falck
  -- strict thread matches above, loose matches on Subject: below --
2001-10-14 19:54 Gautier Write-only-address
2001-10-15 14:33 ` Ted Dennison
2001-10-15  9:47 Gautier Write-only-address

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox