Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How To Get Cpu Usage Of A Script


1 reply to this topic

#1 BCD

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 168 posts
  • Gender:Male
  • myCENT:27.66

Posted 25 February 2010 - 12:45 PM

I need to know the CPU usage of a php script on gamma server which is currently being hosted on two servers. I can see the overall usage of the gamma server by going to stats in Cpanel (http://sitename.com:.../x3/status.html). But it doesn't give me a clear picture of how much CPU resources is being used by my script as it fluctuates a lot because of others websites hosted on the server.

Is there a way to know CPU usage of a single script? If its not possible on server, are there any alternate ways, may be php functions? Thanks for any help on this issue.

Edited by BCD, 25 February 2010 - 12:46 PM.


#2 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:86.16

Posted 25 February 2010 - 05:21 PM

Every process has their own folder located in /proc. The directory name of the process is the same as the process's ID. In other words, let's say your script's process ID is 3, its process information would be located at /proc/3. However, Linux provides a directory known as "self." The self directory located at /proc/self is used to access the currently running program. This allows the program to obtain information about itself without having to know its process ID. I, however, do not know which file or directory you would have to read from in order to obtain the current CPU usage of the process, but this should provide some insight for you.

Using PHP functions, i only know how to have PHP tell me how much memory it wasted and how long it took to execute the script. You can probably find a system tool that can retrieve the CPU usage by process ID and use exec() to retrieve the information from stdout, but i don't know what program exactly that would be.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users