How to measure and control process CPU time of a java program

Hi dudes,
what I am trying to do is to compare 2 algorithms, with the same computation time. To measure the time, one can for example:
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < 10 * 1000) {
running some code
However, in this case System.currentTimeMillis() measures only the wall clock time, not the real process time, i.e. if the CPU is also running some other processes at the same time, the computation time measure is inaccurate.
I learned from other post that this is not easy, but is there on earth a way to solve it? the java profiler seems to be able to monitor the process time but cannot be used to control the computation time at run time. And another thing I learned is a method Thread.getCurrentThreadCpuTime, does it measure the real thread process time or wall clock time?
Any other suggestions? I had all my codes in java and used only single thread, running under linux.
Thanks a lot in advance!
Eric

Check out:
http://java.sun.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html
The timing methods measure thread CPU time, not wall clock time.

Similar Messages

  • How to read and then extract HTMl source code using java program?

    Hi,
    Could someone tell me how to read and then extract the content of certain tag from html source code. For example, given url http://.... , I would like to know what the <Title> content <Title> in that page is.
    Any help is greatly appreciate.

    Use a URLConnection to make the connection to the page at the needed URL. From the URLConnection, you can get an InputStream that is the stream of data from that page. Just search through the stream and find the <title> tags (don't forget to check for case sensitivity).

  • How to Start and Stop Processes?

    How to Start and Stop Processes?
    Im trying to create a program which allows me to Start and Stop (and Restart) GameServers. I will then expand on this so i can start and stop them through a web applet with build in useraccounts.
    Currently the way we do this is to log into the server using a RemoteAssistance. Which is not very safe as the users have the abbility to do anything on the server and potentially corrupt it.
    Below is my code for how i start the servers. But i dont know how i would stop the process.
                    private void startServers()
                   for(GameServer gs : servers)
                        int ID = Integer.parseInt(gs.getID());
                        if(isChecked(ID))
                             try
                                  String cmd[] = gs.getStartString();
                                  Runtime.getRuntime().exec(cmd);
                                  int sleepPeriod = Integer.parseInt(sleepField.getText());
                                  Thread.sleep(sleepPeriod*100);     
                             catch(Exception e)
                             System.out.println(e);
                   }//end of iterator
                   JOptionPane.showMessageDialog(null,"All Selected Servers Have been started.","Servers Started",2);     
         }//end of startserversAnyhelp would be great thanks.

    Using the process class would give you a nicer API, but using destroy isn't a nice way to shutdown a process. Its like killing the process with your task manager. You should make a connection in some way with the game server and tell it to shutdown in stead (gracefull termination).

  • How to run and control any program by java

    hi everyone ,
    I wonder that how to execute and control some menus or how to use some property of any program by java, not for the whole program, it's just only a few features of program.
    Is there any idea?
    if it's impossible to do with java , how can I do it? which way?
    thanks a lot..

    No. Applications have to be specifically built to be able to be controlled by other programs; for example office applications allow you to communicate with them through a special protocol. To be able to communicate you need to know the protocol and write specific code for specific tasks.
    The software world is not as simple as they show in movies, where hackers just press two buttons and take control over entire buildings and applications.

  • How to create a file under web application root from java program

    how to create a file under web application root from java program like an action class?

    like an action class?Huh? What exactly is your requirement?
    Creating a file is usually done with java.io API. Read the java.io tutorials how to play with files.

  • How to measure and plot RMS value of real time data?

    hi
    i need to measure and plot real time RMS value of EMG voltage. I made a VI. But I dont know why it didn't work. Can anyone please help me out? My VI is attached  in 2013 and 2011 both version. One sample data is also attached. Thanks at advance.
    Solved!
    Go to Solution.
    Attachments:
    RMS.vi ‏47 KB
    RMS_2011.vi ‏41 KB
    Sample Data.docx ‏20 KB

    You seem to select EMG voltage vs Angle(Z-axis). Is that really what you want? More resasonable would seem e.g. EMG voltage vs. time.
    If you want to process the 3D (xyz data), you probably need to add some more math). Why are you taking the absolute value? RMS does not care about the sign anyway, right?
    They you are trying an XY graph with a single point, because your Y value is only a single number. You need an equal number of points for Y.
    Here's a quick modification that graph EMG(mV) vs. time(ms) and takes the RMS of the EMG data. See if this gives you some ideas.
    Please provide more information what you want to do with the angles.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    RMS_MOD.vi ‏18 KB

  • How to measure and log frequency with fieldpoint CTR

    Hi,
    I am developing a data acquistion and control system for an engine dynamometer using the fieldpoint modules and Labview.  One of the most important signals is the engine speed, measured in RPM.  The RPM signal is a 0-12V pulse where one pulse equals one revolution of the engine.  As well as being an important piece of data for later analysis, engine RPM will also be in the input into a PID controller, so the signal must be both accurate and have a high measurement frequency. 
    Currently I am using the FP-CTR500 modules to measure the frequency of the signal.  I am already aware of the included frequency measurement VI example, as well as the one posted before for low frequency measurements, and I have gotten both to work with my setup.  I would be using the low frequency VI becuase the max frequency measurement would be in the 200Hz range. 
    The first problem I am having is with the structure of the VI and how the data is output.  The case structure in the VI activates when the counter is read and resets the counter, then switches to the next case.  I would like the RPM number to output out of the case structure into a write_to_file VI and PID controller input.  The problem is that when the case switches, the counter is reset to 0, which will be recorded in the written file. 
    This is some example output data (RPM):
    1232
    0
    2321
    0
    2400
    0
    2521
    0
    The data is being written correctly, but of course I can't have 0 readings when the case structure changes.  This would be especially problematic when input into a controller VI. 
    The next problem I am having is with sampling rate.  If I were to use the low frequency measurement VI, the sampling rate of RPM would be variable based upon the the speed of the signal.  Or, the original frequency measurement VI has an adjustable sampling rate.  Of course, in my system there are a number of other signals that need to be recorded at the same time.  I have found that as I am collecting data, the "write to file frequency" is entirely dependent on the read frequency of the frequency measurement.  Therefore, if I had set the read frequency VI to read at 1 Hz, data will be recorded only every 2Hz.  Ideally I would like an overall measurement frequency of all channels (mix of analog and digital) to read between 20-50Hz, but if I am limited by the frequency measurement. 
    Any ideas on how to solve this problem, either through Fieldpoint or Labview?
    I can post my VI if this help.
    Thanks,
    Huang

    Thanks for your reply. 
    I should probably describe my current setup before I go into anymore details with the problem.  As for my specific setup, I am using an FP-1000 connected with an AIO600, AI110, CTR500, and TC120 all running through the RS232 line to a desktop running labview 8.  The actual counter module is reading a tachometer signal output from a separate engine controller.  THe output is a 0-12V ON 50% duty cycle signal.  As for data logging, i am simply using a "write to measurement file"  Express VI.  I have a while structure which holds all of the express VIs which access the fieldpoint IO, and these are all routed to the "write to" VI. 
    As for the specifics of the data logging problem, as I said, when I set the count frequency of the "Fieldpoint Frequency Measurement" VI to 1Hz, (which means the VI calls the case structure at 2Hz), the "write to measurment file" VI is called at the same rate (2Hz).  Which means that the overall logging rate of the VI is only 2Hz.  Is there someway to decouple this? 
    I was able to solve the problem of calling the frequency variable from the case structure by using a local variable which is called outside the case structure. 
    And now I have been having a lot of problems with reading the actual frequency from my engine controller.  THe actual signal will only range from 0 to around 200Hz.  I noticed, by comparing the actual signal to what was being read in my labview program, that after around 80Hz the signal increases by around 1.5times more than the actual signal.  ie.  Actual signal = 100hz, Read Signal = 150Hz.  After trying to figure out what was the problem, I decided to change the Noise Filter settings to 200Hz.  It actually worked for all the frequency ranges up to around 150Hz but after that the filter attenuates the signal to the point where the actual signal is 160Hz, but is being read at 100Hz.  My question is if there is a way to change the actual filter setting outside of the 2 given setpoints (200hz and 40khz) or if you have any other suggestions on how to fix this problem?  I was thinking of creating a noise filter input in MAX so that i could play with the values in Labview, but am i only limited to those two filters? 
    Thanks again for your help,
    Huang

  • Measurement and control via Producer/Consumer

    Hello folks,
    Iam trying to realise an automated projekt, for testing an actuator.
    It has to Measure the Signals, process them and also has to create signals controling the actuator.
    So far no Problem....But,it also has to run trough 3 or more Test-cycles of wich each has different ControlSignals.
    (example: Test1 - input: 40VSin(40Hz), Test2 - input:Triangle, Test 3 - input: 100Vsin(100Hz)
    It still doesnt sound quite difficult, but as an LabView beginner, i´m having a lot of trouble finding the Right Structure to realise all This. normally i use SPS systems, but this time it has to be Labview  
    Had some trys an hav uploaded them.
    But The Producer/Consumer Structure makes some Problems. It doesnt give out any Signals from the ProducerLoop. :/
    Is there any outher way programing Labview more efficient for that Problem ?
    Sorry 4 the bad English
    Greetings
    Solved!
    Go to Solution.
    Attachments:
    ProcessTest2.vi ‏129 KB

    MarioMueller wrote:
    Hello folks,
    Iam trying to realise an automated projekt, for testing an actuator.
    It has to Measure the Signals, process them and also has to create signals controling the actuator.
    So far no Problem....But,it also has to run trough 3 or more Test-cycles of wich each has different ControlSignals.
    (example: Test1 - input: 40VSin(40Hz), Test2 - input:Triangle, Test 3 - input: 100Vsin(100Hz)
    It still doesnt sound quite difficult, but as an LabView beginner, i´m having a lot of trouble finding the Right Structure to realise all This. normally i use SPS systems, but this time it has to be Labview  
    Had some trys an hav uploaded them.
    But The Producer/Consumer Structure makes some Problems. It doesnt give out any Signals from the ProducerLoop. :/
    Is there any outher way programing Labview more efficient for that Problem ?
    Sorry 4 the bad English
    Greetings
    your architecture is hard to follow. i think you can do this with a state machine..write out your test requirements in steps and what requirement you need to transition. be more specific in describing your problems (error messeges?)..

  • How to stop and start process SAPOSCOL

    Hi, i have a problem with write access for saposcol program. I see that the file saposcol is read the file but its unable to wirte the same.
    Collector           : running
    Start time coll.    : Mon May 21 17:49:49 2007
    Current Time        : Mon Jun 11 13:27:51 2007
    Last write access   : Tue May 29 06:23:46 2007
    Last Read  Access   : Mon Jun 11 13:26:24 2007
    When i try to stop the saposcol i get the following error:
    igzadm> saposcol -k
    Setting Stop Flag :
    13:24:44 11.06.2007   LOG: ==== Stop Flag was set by saposcol (kill_collector()).
    13:24:44 11.06.2007   LOG: ====  The collection process will stop as soon as possible
    can't kill process 409656.
    kill: No such process
    ERROR:No reaction from collecting process 409656.
          Please kill collecting process.exes.
    Am doing this command through SID<ADM> from change directory /run.
    Please help me how to check the permission of the SIDADM to stop the services.
    I also try the same from root user but now use..
    Please guide me how to stop and start the SAPOSCOL in AIX 5.3.
    Advance Thanks.
    Suri Tyson

    Hi, i have the following permission for saposcol
    imserv:/ # ps -ef | grep saposcol | more
        root  118842  528422   0 14:02:17  pts/2  0:00 grep saposcol
    I have changed the ownership as you mentioned....
    imserv:/usr/sap/IGZ/SYS/exe/run # ./saproot.sh igz
    Preparing /usr/sap/IGZ/SYS/exe/run/brbackup ...
    Preparing /usr/sap/IGZ/SYS/exe/run/brarchive ...
    Preparing /usr/sap/IGZ/SYS/exe/run/brconnect ...
    Preparing /usr/sap/IGZ/SYS/exe/run/brtools ...
    Preparing saposcol ...
    Preparing icmbnd ...
    done
    However, i still get the error as:
    igzadm> saposcol -k
    Setting Stop Flag :
    14:12:13 11.06.2007   LOG: ==== Stop Flag was set by saposcol (kill_collector()).
    14:12:13 11.06.2007   LOG: ====  The collection process will stop as soon as possible
    can't kill process 409656.
    kill: No such process
    ERROR:No reaction from collecting process 409656.
          Please kill collecting process.
    Now the permission are set in my system as:
    igzadm> ps -ef |grep saposcol|more
      igzadm  729196  983058   0 14:13:25  pts/2  0:00 grep saposcol

  • How to start and control a WIN console application out of Labview ?

    I have a windows console application, which requires user inputs (keystrokes) during the application run. Now I want to start and control this application out of labview (8.5). Has anyone a good idea, how this can be done ? The "System Exec.vi" seems to be unsuitable, because you can not pass any data to stdin during the run of the application.

    Well, of course I agree absolutely with JoeLabView that Cheap + Fast != (not equal) Good. My company is a manufacturer for medical devices. These are long-living (compared to consumer electronics) and therefore it is extremly important for us that my written code is manageable, reusable and stable. Thats the reason, why I spent  time to think about the really best solution for my task here and I am very amused that we can share our knowledge here in this forum.
    I also thinked about creating a DLL as suggested by smercurio. If I will solve my task in that way, I still have to remove the User Interactions and call the appropriate subfunctions directly. If a newer ART-Tool will be used in the future, this work must be repeated. It that maybe that the developer must go deeply into the coding of the tool. Nevertheless it is a possible way, of course.
    Actually I thinked about a further solution I want to discuss with you. The .NET framework provides functions for redirection of standart input and output. Refer to the explanation of  "ProcessStartInfo.RedirectStandardOutput Property" and "ProcessStartInfoRedirectStandardInput Property" within the .NET Framework Documentation, there are also some examples of how to use them. With this background knowledge, I think that it must be possible to write some kind of wrapper code, which starts the tool and redirects the input/output to labview. The code maybe implemented as a DLL which can then being embedded into LV, or as a separate executable file, whereby the communication between LV and the wrapper code may be done over TCP for example. What do you think about this attempt ?
    @smercurio:
    >> trying to use the ART-tool as it is for automated testing will cause you grief in the long run ....
    Where exactly, did you have the problems? Did you have the problems across multiple art revisions ? What was your "main" problem ? Please let me know your experience, cause I do not want to run into similar problems.

  • How to generate netui controls at run time through some action in pageflow

    Hi,
    I want to create a dynamic table on jsp but don't want to create any control in design time. I will pass some query to the database and no. of textboxes should be created automatically based on the no. of field in result.
    Could you please help me in achieving this?
    Thanks in advance.
    Alka

    I know this but I don't want to write <netui:repeater> tag in jsp page at design time. I want to write some code in an action of page flow which will create that repeater programmtically and will set all it's properties accordingly.
    Initially my jsp page will not contain any netui control even I want to do this at run time through some coding. Is there any way to do this?
    Did you get what I want to do?

  • How to view and control a VI remotely from a web browser

    Hello,
    I want to see and control a vi using a web browser.
    I followed the steps recommended in help and I can see and control the front panel of my vi.
    So far everything is OK.
    First problem:
    A button activates a simple window display a message (One Dialog button). The dialog box opens on the server computer but can not be seen in brouser and therefore can not be closed remotely.
    The second problem:
    Another button activates another window (vi) loaded dynamically. The VI is reentrant and is open with option 0xC0 ("Enable simultaneous calls on reentrant VIs" and "Prepare to call and forget"). By activating the button, it opens multiple instances of the VI properly and runs on the server computer, but their are not visible to the client computer.
    I created, after the same algorithm, corresponding HTML file for the dynamically loaded VI and it is saved in the same place with the main program HTML file.
    What to do as the client computer can operate main VI and adjacent windows from the browser?
    Thanks,
    Cristian
    Solved!
    Go to Solution.

    Another option would be to use something like WebSockets and have your LabVIEW application communicate with a web-page you've designed/developed with Javascript. Then you can use things like floating windows/dialogues with jQuery. It's a lot of work though as you'll need to define your websockets API for talking to your application and then develop the web-page in HTML/CSS/JavaScript for your user interface.
    Unfortunately, even browsers are moving away from pop-up windows (chrome and various addons tend to block popups and they don't play nice with mobile devices). You can have semi-dialogue-like pop-ups though with modal dialogues: https://jqueryui.com/dialog/#modal-message Note though that they are contained within the browser window.
    My advice would be to think about creating a custom UI in LabVIEW that works with a single pane / panel (you can use tab controls!) and use that with remote front panels. Then decide if you want to invest the time/effort in a WebSockets/Web Services approach with your own browser-based UI. Note as well that remote front panels don't work in Chrome properly any more.
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • How to measure and limit the data volume?

    Morning.
    I need a tool to measure and limit the data volume of internet usage. My internet tariff allows a maximum of 5 GB data volume per month. Exceeds my usage that amount the bandwidth will reduce to only 64 kB/s or the exceeding data volume must be paid extraordinarily expensive.
    Do you know a tool that measures the data volume in a given time period and can alert or limit the internet connection for instance if the data volume at the half of the months has exceeded more than the half of the data volume for the entire month?
    Kind regards, vatolin

    You could generate large amount of data and then use any SNMP Viewer (BMC Dahsboard, Solarwinds, Nagios, CiscoWorks etc.) to see the throughput of the interfaces at peak. But why bother? Cisco has been commented by numerous research firms (Gartner etc.) to be very precise about their stated throughputs.
    Regards
    Farrukh

  • How to copy and paste files to Time Capsule

    I thought it could be used as an external disk.
    Do you guys know how to copy and paste files directly into Time Capsule?

    I thought it could be used as an external disk.
    An external disk...also known as a local disk....connects directly to a computer using USB or FireWire.
    The Time Capsule is a network disk, since it connects direct to a network. As such, it s a SHARED network device
    Open a Finder window and look for the SHARED heading on the left side of the window. The Time Capsule icon should appear there. Click on the Time Caspule icon.
    A folder, representing the Time Capsule drive named "Data" (unless you have changed the name of the drive) will appear to the right
    Double click on "Data" to mount the Time Capsule drive on the desktop. You may need to click "Connect As" and enter the Time Capsule device password the first time that you do this.

  • How to run and control live cams on applets

    hi
    i want to now how can we run and control live images form a camera on to a aaplet.what technologyi used for this project . u can check the url http://www.jal.co.jp/en/live/ as a demo.plz can anyone guide me.how to start and which technologies to use,
    regards
    sheetal

    start with this:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blive+%2Bcamera&x=11&y=12

Maybe you are looking for

  • Disk Utility and Hard Drive replacement on MacBook.

    I am preparing to upgrade the hard drive on my MacBook and I was reading this document http://manuals.info.apple.com/en/MacBook13inch_HardDriveDIY.pdf and a the end after installing the hard drive and preparing to install Mac OS X the directions stat

  • Port issue with j2ee engine, http service provider

    hi gurus, on two of our standalone j2ee servers, the j2ee engine is up and running fine. from the mmc everything shows green including messager server. but when i connect to the j2ee page using browser either from the client machine or  on the server

  • Getting the desired condition type

    i have to pick the taxes from me23n--->invoice->taxes  for  PO smartform  based on tax code and the condition record no.s  valid date to  &  valid date from. im using A363 table in which im getting all the condition types for a given material & vendo

  • Multiple Line Items - PS/SD/ PP - Scenario

    Dear Experts, Please advise on the following:- There are two products, like Product A - 2 Nos, and Product  B - 3 Nos, will be manufactured for a project order. Finished product will be attached in the project structure and will be manufactured in ho

  • Code Review Tool - Ignore Whitespace

    When I view the comparison in the code review tool ignore whitespace is on by default. The problem is that it doesn't ignore all whitespace. For example, a method's parameters prior to the change had a space between the start and end of the parameter