Q: incremential redefinition by the precompiler OR workaround

C

Colin Kiegel

Hi there!

My aim is to analyse a couple of code-segments. I want to know how
much time is spent at their execution. I successfuly wrapped
QueryPerformanceCounter for that purpose. But my solution needs
unique "taskIDs", as shown in the example below. I hope this scratch
is self-explanatory:

////////////////////////////////////////////////////////
// Example
////////////////////////////////////////////////////////

CMonitor monitor (/*maxCount of Tasks to monitor*/ 20);

main()
{
monitor.Enter(/*taskID*/ 0, /*taskName*/ "main");

for (int i = 0; i < 10; i++)
{
monitor.Enter(/*taskID*/ 1, /*taskName*/ "loopBody");
func(i);
monitor.LeaveLast();
}

monitor.LeaveLast();
monitor.Save(/*filename*/ "taskdata.txt");
}

func (int i)
{
monitor.Enter(/*taskID*/ 2, /*taskName*/ "func");
i = i*(i+1);
monitor.LeaveLast();
}
////////////////////////////////////////////////////////

monitor.Enter() determines whether it is the first time you Enter
that task and (in that case) initializes internal Data. Otherwise
it skips initialization for that ID.

I want to replace
/*taskID*/ 0
/*taskID*/ 1
/*taskID*/ 2
by something like
#define TASKID 0
TASKID++
TASKID++
TASKID++

I want the Precompiler to increment if that is possible - because it
would be quite efficient at runtime and convenient while programming.

As I don't expect such functionality - does anyone know a workaround?


Thank you in advance!

Colin
 
I

Ian

Colin said:
Hi there!

My aim is to analyse a couple of code-segments. I want to know how
much time is spent at their execution.

Serious suggestion, why not use the performance analysis tools provided
with your platform?

Ian
 
J

John Harrison

Colin said:
Hi there!

My aim is to analyse a couple of code-segments. I want to know how
much time is spent at their execution. I successfuly wrapped
QueryPerformanceCounter for that purpose. But my solution needs
unique "taskIDs", as shown in the example below. I hope this scratch
is self-explanatory:

////////////////////////////////////////////////////////
// Example
////////////////////////////////////////////////////////

CMonitor monitor (/*maxCount of Tasks to monitor*/ 20);

main()
{
monitor.Enter(/*taskID*/ 0, /*taskName*/ "main");

for (int i = 0; i < 10; i++)
{
monitor.Enter(/*taskID*/ 1, /*taskName*/ "loopBody");
func(i);
monitor.LeaveLast();
}

monitor.LeaveLast();
monitor.Save(/*filename*/ "taskdata.txt");
}

func (int i)
{
monitor.Enter(/*taskID*/ 2, /*taskName*/ "func");
i = i*(i+1);
monitor.LeaveLast();
}
////////////////////////////////////////////////////////

monitor.Enter() determines whether it is the first time you Enter
that task and (in that case) initializes internal Data. Otherwise
it skips initialization for that ID.

I want to replace
/*taskID*/ 0
/*taskID*/ 1
/*taskID*/ 2
by something like
#define TASKID 0
TASKID++
TASKID++
TASKID++

I want the Precompiler to increment if that is possible - because it
would be quite efficient at runtime and convenient while programming.

As I don't expect such functionality - does anyone know a workaround?


Thank you in advance!

Colin

I think the simplest idea is to use the predefined macro __LINE__ for
your task id. At least you will get a unique integer for each task id.

john
 
C

Colin Kiegel

Hi

I solved my problem - with a lot of static variables.

I changed:
> monitor.Enter(/*taskID*/ 1, /*taskName*/ "loopBody");
> func(i);
> monitor.LeaveLast();

to:

static int taskID = monitor.Register(/*taskName*/ "loopBody");
monitor.Enter(taskID);
func(i);
monitor.Leave(taskID);

that works very fine. Register() gets called only once per task.

////////////////////////////////////////////////////////
// CMonitor - Output:
////////////////////////////////////////////////////////

Number of Tasks that have been tracked = 15
Frequency of PerformanceCounter = 3579545 Hz

ProcMain
Calls 35
Total 234
Average 6

LoadMouseMap
Calls 1
Total 26520
Average 26520

MapToWorld(int, int)
Calls 3600
Total 11540
Average 3

thread-render-loop
Calls 113
Total 5504661
Average 48713

UpdateScreen
Calls 113
Total 5494120
Average 48620

//.. and so on

////////////////////////////////////////////////////////

Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top