[Info-vax] High resolution per-process CPU consumption statistics

Arne Vajhøj arne at vajhoej.dk
Tue Mar 31 13:25:49 EDT 2020


On 3/28/2020 6:46 PM, Mark Daniel wrote:
> On 29/3/20 9:01 am, Mark Daniel wrote:
>> The actual code keeps a history (array) of up-to 8 code-points (of 
>> which the following output snippet showd two in use).  The actual 
>> routine is too complex to post here but here are examples of some of 
>> the numbers coming out.

> Embedded in the WASD server.

>> unsigned __int64 WatchRPCC
>> (
>> NETIO_STRUCT *ioptr,
>> int index,
>> char *module,
>> int line
>> )

After reading this thread I decided to play around a little.

What I ended up with was a bit different.

* include clockstack.h in all relevant files
* put FUNC_ENTER in start of functions
* put FUNC_EXIT at end of functions (all ends!)
* put DUMP_STATS where one want results
* build with USE_CLOCKSTACK if timing wanted (without it no code gets added)

Example:

#include <stdio.h>

#ifdef _WIN32
#include <windows.h>
#define sleep(n) Sleep(n*1000)
#else
#include <unistd.h>
#endif

#include "clockstack.h"

void f1(void);
void f2(void);
void f3(void);
void f4(void);

int main(int argc, char *argv[])
{
     FUNC_ENTER
     f1();
     FUNC_EXIT
     DUMP_STATS
     printf("Done\n");
     return 0;
}

void f1(void)
{
     FUNC_ENTER
     f2();
     sleep(1);
     FUNC_EXIT
}


void f2(void)
{
     FUNC_ENTER
     f3();
     sleep(2);
     FUNC_EXIT
}

void f3(void)
{
     int i;
     FUNC_ENTER
     for(i = 0; i < 4; i++)
     {
         f4();
     }
     sleep(3);
     FUNC_EXIT
}

void f4(void)
{
     FUNC_ENTER
     sleep(1);
     FUNC_EXIT
}

output:

$ cc test
$ link test
$ run test
Done
$ cxx clockstack.cpp
$ cc/define="USE_CLOCKSTACK" test
$ cxxlink test+clockstack
$ run test
Total time:
f1: 100.0%
main: 100.0%
f2: 90.0%
f3: 70.0%
f4: 40.0%
Used time:
f4: 40.0%
f3: 30.0%
f2: 20.0%
f1: 10.0%
main: 0.0%
Done

Not anything special - just a .H file and about 100 lines of code.

Unfortunately C++ code. I am lazy and it was just way easier to do the
plumbing in C++ than in C.

Arne



More information about the Info-vax mailing list