|
From: Pierre-Antoine D.
|
Dear valgrind users,
I'm trying to profile a specific class function inside c++ code.
As far as I understood the doc, this should be possible with the
--toggle-collect switch.
However I did not manage to use it with a class function.
For example in the code below, would it be possible to start collecting
only on the AA::sloop() function ?
Trying --toggle-collect='sloop' or --toggle-collect='AA:sloop' only
produced empty output.,,,
Thanks for any help.
P.A.D
My test code :
#include <iostream>
class AA {
public:
int a;
AA(){a=0;}
void sloop(){
a++;
for(int i=0;i<10000;i++) a+=45;
loop();
std::cout << " "<<a <<std::endl;
}
void loop();
};
void AA::loop(){
for(int i=0;i<10000;i++) a = a+ a /45;
}
and the main file :
#include "test.cxx"
int main(){
AA ca;
ca.sloop();
ca.sloop();
ca.sloop();
}
|
|
From: Josef W. <Jos...@gm...> - 2007-02-09 19:14:12
|
Hi, On Friday 09 February 2007, Pierre-Antoine Delsart wrote: > Dear valgrind users, > > I'm trying to profile a specific class function inside c++ code. > As far as I understood the doc, this should be possible with the > --toggle-collect switch. > However I did not manage to use it with a class function. > > For example in the code below, would it be possible to start collecting > only on the AA::sloop() function ? > First, do not quote the function name. If there are characters which could be interpreted by the shell, either put a backslash before that character, or quote the whole argument. You can not specify parts in the middle of a function name; it has to be the full name or a prefix (see below). Also note, that for C++, the function signature is part of the symbol name. > Trying --toggle-collect='sloop' This is not a prefix; can not work. > or --toggle-collect='AA:sloop' only > produced empty output. Probably you wanted to say that you tested 'AA::sloop' (2 colons instead of 1). However, this is not the full symbol name. The full name is "AA::sloop()", including the parenthesis. But otherwise, and without the quotes, "AA::sloop" _is_ a prefix and thus, it should work according to the documentation. Unfortunately, I just saw that the documentation is outdated on this one. You can specify limited globbing patterns, and have to use "*" at the end when giving a function prefix. This was introduced already some time ago in callgrind to be able to collect only in function "func" even when there was e.g. a "func_a", too. The old (and documented behavior) would not allow this. In short: the following should be working (at least it does here): valgrind --tool=callgrind "--toggle-collect=AA::sloop()" ./test That's the full symbol. valgrind --tool=callgrind --toggle-collect=AA::sloop* ./test That's a symbol prefix specification. It should be noted that you can specify multiple "--toggle-collect" options to specify that you want to collect only inside of the functions specified. I hope this helps for now. I admit that it would be way better to have examples in the documentation, and of course, not have outdated documentation in the first place :-( Josef |
|
From: Pierre-Antoine D.
|
Hello Josef, Your clear suggestions worked very well. Indeed, it would be good to update the doc... Anyway thank you very much for your help. Cheers, P.A. Josef Weidendorfer a =E9crit : > Hi, >=20 > On Friday 09 February 2007, Pierre-Antoine Delsart wrote: >> Dear valgrind users, >> >> I'm trying to profile a specific class function inside c++ code. >> As far as I understood the doc, this should be possible with the >> --toggle-collect switch. >> However I did not manage to use it with a class function. >> >> For example in the code below, would it be possible to start collectin= g=20 >> only on the AA::sloop() function ? >> >=20 > First, do not quote the function name. If there are characters which > could be interpreted by the shell, either put a backslash before that > character, or quote the whole argument. > You can not specify parts in the middle of a function name; it has > to be the full name or a prefix (see below). > Also note, that for C++, the function signature is part of the > symbol name. >=20 >> Trying --toggle-collect=3D'sloop' >=20 > This is not a prefix; can not work. >=20 >> or --toggle-collect=3D'AA:sloop' only =20 >> produced empty output. >=20 > Probably you wanted to say that you tested 'AA::sloop' > (2 colons instead of 1). >=20 > However, this is not the full symbol name. The full > name is "AA::sloop()", including the parenthesis. > But otherwise, and without the quotes, "AA::sloop" > _is_ a prefix and thus, it should work according to the > documentation. >=20 > Unfortunately, I just saw that the documentation > is outdated on this one. >=20 > You can specify limited globbing patterns, and have to use "*" at the > end when giving a function prefix. This was introduced already > some time ago in callgrind to be able to collect only in function > "func" even when there was e.g. a "func_a", too. The old (and > documented behavior) would not allow this. >=20 > In short: the following should be working (at least it does here): >=20 > valgrind --tool=3Dcallgrind "--toggle-collect=3DAA::sloop()" ./test >=20 > That's the full symbol. >=20 > valgrind --tool=3Dcallgrind --toggle-collect=3DAA::sloop* ./test >=20 > That's a symbol prefix specification. >=20 > It should be noted that you can specify multiple "--toggle-collect" > options to specify that you want to collect only inside of the function= s > specified. >=20 > I hope this helps for now. >=20 > I admit that it would be way better to have examples in the > documentation, and of course, not have outdated documentation in > the first place :-( >=20 > Josef |
|
From: Olly B. <ol...@su...> - 2007-02-09 19:32:04
|
On 2007-02-09, Josef Weidendorfer <Jos...@gm...> wrote:
> First, do not quote the function name. If there are characters which
> could be interpreted by the shell, either put a backslash before that
> character, or quote the whole argument.
You can quote any subpart(s) of an argument to protect it from the
shell. So '--toggle-collect=sloop' and --toggle-collect='sloop' should
behave identically. For example, try:
perl -e 'print "|$ARGV[0]|\n"' -- '--toggle-collect=sloop'
perl -e 'print "|$ARGV[0]|\n"' -- --toggle-collect='sloop'
Both output: |--toggle-collect=sloop|
Cheers,
Olly
|
|
From: Josef W. <Jos...@gm...> - 2007-02-09 20:04:40
|
On Friday 09 February 2007, Olly Betts wrote: > On 2007-02-09, Josef Weidendorfer <Jos...@gm...> wrote: > > First, do not quote the function name. If there are characters which > > could be interpreted by the shell, either put a backslash before that > > character, or quote the whole argument. > > You can quote any subpart(s) of an argument to protect it from the > shell. So '--toggle-collect=sloop' and --toggle-collect='sloop' should > behave identically. For example, try: > > perl -e 'print "|$ARGV[0]|\n"' -- '--toggle-collect=sloop' > perl -e 'print "|$ARGV[0]|\n"' -- --toggle-collect='sloop' > > Both output: |--toggle-collect=sloop| Ah, thanks, I didn't know. I stand corrected. You never stop learning. Josef > > Cheers, > Olly > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users > |