tracing code line executions

J

Jarek Blakarz

I need a class that gathers information about what lines in the code were
executed. I want it not to generate a lot of data on the screen. Perfectly it
would keep this information in a variable and print it on demand.
In other woerds I want it to be printed only when specific conditions hold.
The best solution seems to be bit field where a specific bit is set when a
specific line of the code has been reached.

I wrote the following template class.
Please improve this class when you see some weak points of it.
I desire especially the design improvements.

I decided to use template since when I want to trace only a few lines the short
variable seems to be sufficent that consumes less memory.

thanks for help

template <typename T>
struct SLT {
SLT(void) : m_flag(0) {}
void set(unsigned int shift) { m_flag |= 1 << shift; }
void clear(void) { m_flag = 0; }
T get(void) const { return m_flag; }

private:
T m_flag;
};
 
V

Victor Bazarov

I need a class that gathers information about what lines in the code were
executed. I want it not to generate a lot of data on the screen. Perfectly it
would keep this information in a variable and print it on demand.
In other woerds I want it to be printed only when specific conditions hold.
The best solution seems to be bit field where a specific bit is set when a
specific line of the code has been reached.

I wrote the following template class.
Please improve this class when you see some weak points of it.
I desire especially the design improvements.

I decided to use template since when I want to trace only a few lines the short
variable seems to be sufficent that consumes less memory.

thanks for help

template <typename T>
struct SLT {
SLT(void) : m_flag(0) {}
void set(unsigned int shift) { m_flag |= 1 << shift; }
void clear(void) { m_flag = 0; }
T get(void) const { return m_flag; }

private:
T m_flag;
};

In order to understand the design and identify potential areas for
improvement in a class template it is necessary to see how such a
template is to be used. Please post more code to demonstrate exactly that.

And perhaps you can elaborate on your desire to create your own
mechanism for doing something for which there are already commercial and
other tools available.

V
 
J

Jorgen Grahn

This has been done, look up code coverage tools like gcov (gcc's
extension).

That was what I was going to respond, but judging from the rest of the
posting he's after something quite different. (No idea what, unfor-
tunately.)

/Jorgen
 
Ö

Öö Tiib

I need a class that gathers information about what lines in the code were
executed.

Why you need it? Are you writing a profiler?
I want it not to generate a lot of data on the screen. Perfectly it
would keep this information in a variable and print it on demand.

Typically the profilers instrument executable code using debug
information that is generated for debugger by compiler. Data is
gathered during program run (not generated on screen). Is that
what you mean?
In other woerds I want it to be printed only when specific
conditions hold. The best solution seems to be bit field
where a specific bit is set when a specific line of the code
has been reached.

That however sounds more like debugger with breakpoints with
conditions.
I wrote the following template class.
Please improve this class when you see some weak points of it.
I desire especially the design improvements.

There are lot of similar classes either ready in standard library
or freely downloadable. Most similar to yours are 'std::bitset<64>',
'std::vector<bool>' and 'boost::dynamic_bitset<>'. It is perhaps
distraction to reinvent such basic wheels if what you really want
to write is some profiler or debugger (or both).
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top