473,795 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1762
Federico,
I normally use QueryPerformanc eCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanc eCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanc eFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanc eFrequency(freq uency)
QueryPerformanc eCounter(start)

' work

QueryPerformanc eCounter(finish )
Dim time As TimeSpan = TimeSpan.FromSe conds((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.Tic kCount

' work

' set second time var and comapre to get result
finish = Environment.Tic kCount
Dim time As TimeSpan = TimeSpan.FromMi lliseconds(fini sh - start)

My understanding is that QueryPerformanc eCounter will normally be a higher
resolution then Environment.Tic kCount, however QueryPerformanc eCounter may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnost ics.Stopwatch class that will automatically
choose between QueryPerformanc eCounter & Environment.Tic kCount...

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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.phx.gbl...
Federico,
I normally use QueryPerformanc eCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanc eCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanc eFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanc eFrequency(freq uency)
QueryPerformanc eCounter(start)

' work

QueryPerformanc eCounter(finish )
Dim time As TimeSpan = TimeSpan.FromSe conds((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.Tic kCount

' work

' set second time var and comapre to get result
finish = Environment.Tic kCount
Dim time As TimeSpan = TimeSpan.FromMi lliseconds(fini sh - start)

My understanding is that QueryPerformanc eCounter will normally be a higher
resolution then Environment.Tic kCount, however QueryPerformanc eCounter may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnost ics.Stopwatch class that will automatically
choose between QueryPerformanc eCounter & Environment.Tic kCount...

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******** ******@TK2MSFTN GP10.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.ToSt ring() will give you what you want.

--
Larry Lard
Replies to group please

Nov 21 '05 #4
Federico,
As Larry suggests, calling TimeSpan.ToStri ng() 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 "formattabl e" 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.MinVal ue.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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.phx.gbl...
Federico,
I normally use QueryPerformanc eCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanc eCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanc eFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanc eFrequency(freq uency)
QueryPerformanc eCounter(start)

' work

QueryPerformanc eCounter(finish )
Dim time As TimeSpan = TimeSpan.FromSe conds((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.Tic kCount

' work

' set second time var and comapre to get result
finish = Environment.Tic kCount
Dim time As TimeSpan = TimeSpan.FromMi lliseconds(fini sh - start)

My understanding is that QueryPerformanc eCounter will normally be a
higher
resolution then Environment.Tic kCount, however QueryPerformanc eCounter
may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnost ics.Stopwatch class that will automatically
choose between QueryPerformanc eCounter & Environment.Tic kCount...

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******** ******@TK2MSFTN GP10.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
5081
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 them with a batch file that changes to my apps home directory. I've tried exec() with a full pathname (which seems to have problems on Windows if it has spaces in it, but I'm not sure if that's really the problem), with just the simple short batch...
2
11078
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 the results are the same on SunOS 5.8, Redhat8.0, cygwin. I read relevant articles and find the reason is that the output of the process exceeds the buffer allocated for that process. So can I adjust the buffer size (on any
14
1539
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
232
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
9617
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 console) and i would like to communikcate with its I/O before it is finished. I don't have this issue if for instance i am starting another java app. The problem i meet is that the I/O is bloked while the process is being executed.When i terminate...
1
2860
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: Create a child process step 2. Make child process perfrom some operation. Step 3: Make parent process monitor the runtime of the child process Step 4: Parent process to terminate the child process after threshold time say 1000000 seconds is equal...
2
3370
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 (arg.equals("Execute")){ inputText=(String)commandText.getText(); System.out.println(inputText); try{ Runtime rt = Runtime.getRuntime(); //Process cp1=Runtime.getRuntime().exec(inputText);
7
8456
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 this installer will install them. But what about the situation where VC runtime has already been installed? In fact it's been installed twice. Although the project was built on a Windows XP system with Visual Studio 2005 SP1 and the results were...
3
7016
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 = Runtime.getRuntime().exec("cmd /c start C:\\MyFolder\\JavaApp.bat"); the seperate process runs perfectly, but when i add a space to the path: Process process = Runtime.getRuntime().exec("cmd /c start \"C:\\My Folder\\JavaApp.bat\""); then the java.exe...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.