473,394 Members | 1,766 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,394 software developers and data experts.

Gather the runtime of a process

Hi All:

I need to gather the runtime in format "HH:mm:ss" of certain processes from
its start to its end, any ideas ?

thanks,
Federico
Nov 21 '05 #1
4 1745
Federico,
I normally use QueryPerformanceCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanceFrequency(frequency)
QueryPerformanceCounter(start)

' work

QueryPerformanceCounter(finish)
Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start) /
frequency)

Alternatively you can use DateTime:

' set some time var
Dim start, finish As DateTime
start = DateTime.Now

' work

finish = DateTime.Now
Dim time As TimeSpan = finish.Subtract(start)

A third alternative would be to use "Ticks"

' set some time var
Dim start, finish As Integer
start = Environment.TickCount

' work

' set second time var and comapre to get result
finish = Environment.TickCount
Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish - start)

My understanding is that QueryPerformanceCounter will normally be a higher
resolution then Environment.TickCount, however QueryPerformanceCounter may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnostics.Stopwatch class that will automatically
choose between QueryPerformanceCounter & Environment.TickCount...

http://lab.msdn.microsoft.com/vs2005/

http://msdn2.microsoft.com/library/ebf7z0sw.aspx

Hope this helps
Jay

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Hi All:

I need to gather the runtime in format "HH:mm:ss" of certain processes
from
its start to its end, any ideas ?

thanks,
Federico

Nov 21 '05 #2
Impressive !

Thanks for your help !

PS: How can i transform the TimeSpan results into format HH:mm:ss ?

Regards,
Federico
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
Federico,
I normally use QueryPerformanceCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanceFrequency(frequency)
QueryPerformanceCounter(start)

' work

QueryPerformanceCounter(finish)
Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start) /
frequency)

Alternatively you can use DateTime:

' set some time var
Dim start, finish As DateTime
start = DateTime.Now

' work

finish = DateTime.Now
Dim time As TimeSpan = finish.Subtract(start)

A third alternative would be to use "Ticks"

' set some time var
Dim start, finish As Integer
start = Environment.TickCount

' work

' set second time var and comapre to get result
finish = Environment.TickCount
Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish - start)

My understanding is that QueryPerformanceCounter will normally be a higher
resolution then Environment.TickCount, however QueryPerformanceCounter may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnostics.Stopwatch class that will automatically
choose between QueryPerformanceCounter & Environment.TickCount...

http://lab.msdn.microsoft.com/vs2005/

http://msdn2.microsoft.com/library/ebf7z0sw.aspx

Hope this helps
Jay

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Hi All:

I need to gather the runtime in format "HH:mm:ss" of certain processes
from
its start to its end, any ideas ?

thanks,
Federico


Nov 21 '05 #3

Federico G. Babelis wrote:
PS: How can i transform the TimeSpan results into format HH:mm:ss ?


You are lucky in that "hh:mm:ss" is the default string conversion of a
TimeSpan, so just MyTimeSpan.ToString() will give you what you want.

--
Larry Lard
Replies to group please

Nov 21 '05 #4
Federico,
As Larry suggests, calling TimeSpan.ToString() will return the results in
the format: [-][d.]hh:mm:ss[.ff]

http://msdn.microsoft.com/library/de...tringTopic.asp

Remember the ToString method of "formattable" objects in .NET is normally
overridden to provide formatting for that object.

If you don't want the fractional seconds or days on the formatted string, I
normally convert the TimeSpan to a DateTime & then use custom DateTime
formatting.

Note TimeSpan itself only supports a fixed format, I will convert a TimeSpan
into a DateTime if I need custom formatting.

Dim ts As TimeSpan
Dim dt As DateTime = DateTime.MinValue.Add(ts)
Dim s As String

s = ts.ToString() ' default TimeSpan formatting
s = dt.ToString("H:mm:ss") ' custom DateTime formatting
For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp
Hope this helps
Jay

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
Impressive !

Thanks for your help !

PS: How can i transform the TimeSpan results into format HH:mm:ss ?

Regards,
Federico
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
Federico,
I normally use QueryPerformanceCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanceFrequency(frequency)
QueryPerformanceCounter(start)

' work

QueryPerformanceCounter(finish)
Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start) /
frequency)

Alternatively you can use DateTime:

' set some time var
Dim start, finish As DateTime
start = DateTime.Now

' work

finish = DateTime.Now
Dim time As TimeSpan = finish.Subtract(start)

A third alternative would be to use "Ticks"

' set some time var
Dim start, finish As Integer
start = Environment.TickCount

' work

' set second time var and comapre to get result
finish = Environment.TickCount
Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish - start)

My understanding is that QueryPerformanceCounter will normally be a
higher
resolution then Environment.TickCount, however QueryPerformanceCounter
may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnostics.Stopwatch class that will automatically
choose between QueryPerformanceCounter & Environment.TickCount...

http://lab.msdn.microsoft.com/vs2005/

http://msdn2.microsoft.com/library/ebf7z0sw.aspx

Hope this helps
Jay

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Hi All:

I need to gather the runtime in format "HH:mm:ss" of certain processes
from
its start to its end, any ideas ?

thanks,
Federico



Nov 21 '05 #5

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

Similar topics

1
by: Hal Vaughan | last post by:
I've been using Runtime.exec() like this: Runtime rt = Runtime.getRuntime(); try {Process p = rt.exec("MyCommand.bat");} catch (Exception e) {do stuff} When I start my Java classes, I start...
2
by: uwnewsgroup | last post by:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and try to get its standard output by using Process.getOutputStream(), it blocks forever. I tried it using Java 1.4 and...
14
by: Klaus Neuner | last post by:
Hello, I need to gather information that is contained in various files. Like so: file1: ===================== foo : 1 2 bar : 2 4
0
by: Federico G. Babelis | last post by:
Hi All: I need to gather the runtime in format "HH:mm:ss" of certain processes from its start to its end, any ideas ? thanks, Federico
8
by: angelotti | last post by:
Hi everyone , i am banging my head over the following problem for a couple of weeks now: i am starting a MyProg.exe(a simple C app) from a java class with .exec() as a system process(not in it's own...
1
by: ganeshp | last post by:
Hi , In my project i have come across a requirement where i must track the runtime of a process and terminate the process if it execeed a certain threshold limit. semthing like step 1: ...
2
by: jerry chapman | last post by:
I am trying to send a command to windows from my java program, and I get an error. The pertinent (?) part of my code follows: public boolean action(Event evt, Object arg) { if...
7
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then...
3
by: Shayco | last post by:
hey, in my code i'm using Runtime.getRuntime().exec() in order to run a .bat file that calls another java program (they communicate with each other using RMI). when i call: Process process =...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.