473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Q: incremential redefinition by the precompiler OR workaround

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
Oct 9 '05 #1
3 1426
Ian
Colin Kiegel wrote:
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
Oct 9 '05 #2
Colin Kiegel wrote:
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
Oct 9 '05 #3
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
Oct 9 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lomat | last post by:
Hello, While compiling a file, I get following error .... ================================= /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++/type_traits.h:14 2: redefinition of...
2
by: Carlos De Matos | last post by:
Hello all, Has anyone written a project/code/document on a possible implementation for a c# precompiler? I want to build a precompiler that will modify attributed code, then submit the...
1
by: Alex | last post by:
Hello all, I have a very stupid problem that is driving me crazy...so plz if anyone ever saw this, I would like him to help me :) I have static MFC application in MSVC++ 6.0 (named Example)....
8
by: Bill Pursell | last post by:
This question must be FAQ, but I can't find it: I'm baffled by the following: $ cat a.c #define foo(x) foo##x_ #define bar(x) bar##x##_ foo() foo(1) bar()
10
by: RainerF | last post by:
Hi Folks, My Problem is: My SQL Statement Structure: SELECT TABLEA.FIELDA, TABLEA.FIELDB, TABLEA.FIELDC, TABLEA.FIELDD,
22
by: JohnQ | last post by:
Is the C++ precompiler the same as a C precompiler? If not, how much different is it? John
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.