LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   CPU instructions per process (https://www.linuxquestions.org/questions/linux-server-73/cpu-instructions-per-process-787283/)

melkoraton 02-05-2010 02:03 PM

CPU instructions per process
 
Hi :D
Is there a way to show or count how many CPU instructions a particular process is using or uses?
In my work we develop a web application and I'm responsible of maintaining the web server.
The app lets you handle data online so each client that uses the web application has a folder associated to it, where his data is stored. (/var/www/html/test) for example.
The idea is to get how many CPU instructions the httpd process for that particular folder is having. Is there a way to do this?
Thanks in advance, and sorry for the complicated explanation :D

Web31337 02-05-2010 02:04 PM

define CPU instructions?

melkoraton 02-05-2010 02:30 PM

Like x86 for example, instructions from the instruction set of the CPU.
Examples:
goto
add
substract
etc

Like assembler... very low lvl

Web31337 02-05-2010 02:44 PM

who knows. some tens of thousands per second? why does that bother you? if performance is critical in your environment, consider using other webserver than apache httpd: that is too slow.
say, nginx.
p.s. there are no 'goto' and 'substract' in x86 assembly. jmp and sub perhaps are the one you meant.

noden 02-06-2010 11:04 PM

Quote:

Originally Posted by melkoraton (Post 3854173)
Like x86 for example, instructions from the instruction set of the CPU.
Examples:
goto
add
substract
etc

Like assembler... very low lvl

I dont think that would be allowed by the kernel without running it in a debugger.
But it would be an insanely high amount. The CPU also do more than one instruction at one time depending on the amount of ALUs in the CPU.
Some instructions take several cycles to perform though.
Getting that kind of data would load the CPU more than running apache itself. :)
I would reccomend just keeping track of the normal average CPU usage for that process.

salasi 02-07-2010 01:48 PM

Quote:

Originally Posted by melkoraton (Post 3854173)
Like assembler... very low lvl

I'm sorry, but it is more difficult than that; there are instructions that are pre-fetched but never used, there are instructions that are brought into cache, but never used (actually, it is way more complicated than that, because of the cache levels) there are instructions that are decoded but never executed, there are instructions that are provisionally executed but are withdrawn, and there are instructions that are executed...of course, the executions that are executed take very different amount of time depending on whether they were already in cache, which cache they were in and the actual instructions themselves.

Of course, the time taken will be vastly more influenced by whether the app is swapped in or out than by plus or minus a few instructions, and the time to do anything with the data will also be way more influenced by how the data write interacts with the i/o scheduler (where are you with elevator seeks?), but that may or may not be a problem to you, because you could consider that time to be transparent if its all queued up and happening in the background.

Now, what did you want to know, particularly given that I have oversimplified everything in order to answer in a finite time?

melkoraton 02-07-2010 09:56 PM

well I was expecting answers like this. A weird client wanted that specific data... I simply thought it was impossible to get that info because its way to low lvl and way too difficult to get..
Like I said there is no way around they asked for that data particulary...
Anyways thanks a lot for the replies :D

salasi 02-08-2010 06:13 AM

Quote:

Originally Posted by melkoraton (Post 3856210)
A weird client wanted that specific data...

I'm guessing that this client is a human, or collection of humans, rather than one half of a client/server computer program collection.

Quote:

I simply thought it was impossible to get that info because its way to low lvl and way too difficult to get..
Like I said there is no way around they asked for that data particulary...
No, but you may be able to measure how much time a sequence of instructions takes, and if you can define a worthwhile sequence of instructions (or, alternatively, measure the percentage of time that a thread takes) that may get you the information that the client really wants, rather than what has been asked for.

aspire1 02-09-2010 04:31 PM

Are you sure they don't mean how much cpu time on average ( or something like that ) is each process using? Otherwise, give them an assembly language printout of your code, an instruction set manual for the cpu, a calculator and wish them a fond farewell :)

salasi 02-10-2010 04:53 AM

Quote:

Originally Posted by aspire1 (Post 3858303)
Are you sure they don't mean how much cpu time on average...

That may well satisfy their real requirement, but it is entirely up to the OP whether he tells that this is an alternative possibility or whether he (she?) just leaves it at something like 'What you have asked for isn't really possible or useful.'

Quote:

Otherwise, give them an assembly language printout of your code, an instruction set manual for the cpu, a calculator and wish them a fond farewell
There is effectively no danger that they get anything useful from that process....however, there is a danger that they, in order to achieve a result, do it wrong (usually, processes like this, which are a PITA and both political and useless are given to the most disposable of assets to perform, and that doesn't help in getting a useful answer, but an answer may come out all the same) and as a result of doing it wrong come to some conclusion about what changes you have to make to your code, and that might be problematic.

I mean, if they were to decide on the basis of false cycle counting that, in order to cope with the increase in traffic that they have predicted (and you can argue whether this is more imaginary than the cycle counting, or not) that you have to re-write your code in a different language, would you think that this was a good outcome?

The other conclusion that they might come to is 'we don't need to upgrade hardware until we get to xxxxx hits per hour' and this can also be problematic if they do need a hardware upgrade at some lower hit level and they are sitting on 'proof' that they do not need to do it.

chrism01 02-10-2010 06:52 PM

Definitely need to ask the client what they are trying to achieve/measure, but at the higher level. Counting cpu instructions is unrealistic.


All times are GMT -5. The time now is 04:07 PM.