2011-08-20 98 views
1

我有一个程序使用gloox库连接到xmpp服务器。如果我直接运行程序,连接总是成功。但是,该程序的CPU使用率很高。所以我转向valgrind寻求帮助。但是如果我用valgrind(--tool = callgrind)运行程序,连接总是超时。我不得不承认我是valgrind的新手,但为什么会这样呢?在valgrind中运行程序时的连接超时

+0

Valgrind是由它的性质缓慢。连接上的超时值是多少?这是不可能的,但可以想象,你可能会击中它。游戏中可能还有别的东西。你有没有尝试tcpdump来检查引擎盖下发生了什么? – Flexo

回答

0

Valgrind对已执行代码进行了大量转换,使其运行速度比本机慢10-50倍。所以很可能连接超时。您可以使用strace下的异形程序运行Valgrind,以通过错误代码找到此连接。

0

后,我遇到了类似的问题和额外的调试,它在解析XML的XMPP节时归结为一个问题。 在我们的例子中,问题出现在使用使用long2string的util.h函数int2string的xpath解析器中。

在正常执行

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

给出2,但下的valgrind给1和突破都记录下来。

我们更换功能

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

通过

#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); 
    }