开发者

connection timeout when running a program in valgrind

开发者 https://www.devze.com 2023-03-30 01:12 出处:网络
I have a program that uses the gloox library to connect to an xmpp server. Connection always succeeds if I run the program directly. H开发者_Python百科owever, the program is having high cpu usage. So

I have a program that uses the gloox library to connect to an xmpp server. Connection always succeeds if I run the program directly. H开发者_Python百科owever, the program is having high cpu usage. So I turned to valgrind for help. But if I run the program with valgrind (--tool=callgrind), the connection always times out. I have to admit I'm new to valgrind, but why is this happening?


Valgrind does a number of transformations of executed code, making it run 10-50 times slower than natively. So it is likely that connection times out. You can run Valgrind with profiled program under strace to locate this connection by error codes.


If your original problem is a high cpu with gloox, I'm almost sure that your program polls every 10 milliseconds for new xmpp messages. Run your program with recv(-1) instead of recv(10) for example.

http://camaya.net/glooxlist/dev/msg01191.html


After I run into a similar problem and extra debugging, it comes down to a problem when parsing the xmpp xml stanza. In our case, the problem was with the xpath parser that uses an util.h function int2string that use long2string.

Under normal execution

int len = (int)( log( (double)( 10 ) ) / log( (double) 10 ) ) + 1; 

gives 2 but gives 1 under valgrind and break everything down.

We replaced the function

static inline const std::string int2string( int value )
    {
      return long2string( value );
    }

by

#include <sstream>
static inline const std::string int2string( int value )
    {
      /* ADDON*/
      //when we call long2string, it does weird cmath log stuff and with computer precision,
      //the result may be different from an environnement to another. eg: when using valgrind
      std::ostringstream s;
      s << value;
      return s.str();
      /* ADDON */
      //return long2string( value );
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消