473,387 Members | 1,899 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,387 software developers and data experts.

Need help building a software profiler.

78
Hi guys. i'm trying to build a software profiler in C++. What i want for now is to get a C code as input to my program, and produce a that code but added to it some stuff.
An example is getting input "x;" and putting output "x; stmt[0]++;"
This allows me to know how many times a statement in this code as been executed.
The strategy is to insert a stmt[i]++; anywhere i see a ';', but i'm afraid it won't work if i encounter a ';' found in the for loop parameters. And if i want to solve this and check if this statement ends with a new line, then place a "stmt[i]++", i'll be missing out on lines which include more than one statement such as "x; y;" (on the same line).

Can anyone suggest a possible solution? I've been thinking about it for hours, but i'm unable to solve this problem.

Thank you.
Apr 15 '07 #1
4 1544
Savage
1,764 Expert 1GB
Hi guys. i'm trying to build a software profiler in C++. What i want for now is to get a C code as input to my program, and produce a that code but added to it some stuff.
An example is getting input "x;" and putting output "x; stmt[0]++;"
This allows me to know how many times a statement in this code as been executed.
The strategy is to insert a stmt[i]++; anywhere i see a ';', but i'm afraid it won't work if i encounter a ';' found in the for loop parameters. And if i want to solve this and check if this statement ends with a new line, then place a "stmt[i]++", i'll be missing out on lines which include more than one statement such as "x; y;" (on the same line).

Can anyone suggest a possible solution? I've been thinking about it for hours, but i'm unable to solve this problem.

Thank you.
Hi,

if it contains more than one statement in one line then how about to search the line for:
Expand|Select|Wrap|Line Numbers
  1. for(
and if it contains it you will need to skip all ';' until you get to ;).
and then after every ';' add a stmt[i]++;

Savage
Apr 15 '07 #2
JosAH
11,448 Expert 8TB
Hi,

if it contains more than one statement in one line then how about to search the line for:
Expand|Select|Wrap|Line Numbers
  1. for(
and if it contains it you will need to skip all ';' until you get to ;).
and then after every ';' add a stmt[i]++;

Savage
At least you have to do that after preprocessing; have a look at this sick little puppy:
Expand|Select|Wrap|Line Numbers
  1. #define for(x) while(1)
  2. ...
  3. for (ever;and;ever)
  4. ...
Note that the preprocessor doesn't know about reserved words nor anything
at all about the C (or C++) language.

kind regards,

Jos
Apr 15 '07 #3
Sebouh
78
Hi,

if it contains more than one statement in one line then how about to search the line for:
Expand|Select|Wrap|Line Numbers
  1. for(
and if it contains it you will need to skip all ';' until you get to ;).
and then after every ';' add a stmt[i]++;

Savage
Yeh i think that would work.
Thanks mate. Now to deal with adding { for every 1 lined for loop.
Apr 15 '07 #4
JosAH
11,448 Expert 8TB
Yeh i think that would work.
Thanks mate. Now to deal with adding { for every 1 lined for loop.
Note my reply just above yours though ... If you want a bullet proof profiler better
start reading about coff and elf object file formats then which contain statement
and line information for compiled C (or C++) code. The compiler itself has done
its evil deeds and optimization tricks then already so it can't fool you anymore.

kind regards,

Jos
Apr 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
3
by: jw56578 | last post by:
Where is the information coming from that is displayed in query profiler. Is it the command that is retrieved before it is processed, or is it what is actually processed.
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
3
by: Maansi Gupta | last post by:
Platform - Windows 2000 Professional , VC .NET 7.1 Hello, I have recently ported my source code from Visual Studio 6.0 to .NET 7.1 Previously with Visual Studio 6.0 I was using the profiler...
5
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested....
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: anweshadash | last post by:
Using SQL Profiler: (Ref: http://msdn2.microsoft.com/en-us/library/ms181091.aspx) Sometimes it’s very beneficial to use sql profiler. Let’s have an idea about that and how to use that by...
3
by: Gordon | last post by:
Has anybody had any success compiling a PHP build for Leopard, specifically for Leopard running on a 64 bit Intel architecture? I have been using the Entropy builds up to now but there has been 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.