Jump to content
xisto Community
BCD

How To Get Cpu Usage Of A Script

Recommended Posts

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://forums.xisto.com/no_longer_exists/). 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 (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.