Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Alon_Tal
Beginner
50 Views

recv() is Missing from Results

[cpp]The following snippet produces results which I think might be faulty. After profiling, I am not seeing any calls to recv(), neither using sampling nor using call-graph runs.

I run this tester and stream UDP traffic to it, and wait until it exits (After 20000 packets).
The results attribute the highest "self time" to cout related operations (put(), operator<<), which is unlikely, as they only get called 24 times, whereas recv() gets called thousands of times, and should be quite expensive.

My question: How can I see how much time was spent in recv()?



#include #include #include using std::cerr; using std::cout; using std::endl; int main() { int sock = -1; int retval = 0; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) { cerr << "Failed to allocate socket. Error " << sock << " (" << strerror(errno) << ")" << endl; return 1; } sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(51258); addr.sin_addr.s_addr = INADDR_ANY; socklen_t socklen = sizeof(addr); retval = bind(sock, (const sockaddr*)&addr, socklen); if (retval == -1) { cerr << "Failed to bind socket. Error " << sock << " (" << strerror(errno) << ")" << endl; return 1; } cout << "Calling recv()..." << endl; char buf[1024] = {0}; int i = 0; while (1) { retval = recv(sock, buf, sizeof(buf), 0); if (retval == -1) { cerr << "Failed to recv. Error " << sock << " (" << strerror(errno) << ")" << endl; return 1; } if (i++ % 1000 == 0) { cout << "Received " << retval << " bytes" << endl; if (i > 20000) { cout << "Stopping" << endl; break; } } } [/cpp]
0 Kudos
1 Reply
David_A_Intel1
Employee
50 Views

Sampling will not catch it unless significant time is spent in the recv() routine and call graph won't record it if it is ring0 code. Is recv() a kernel call. Also, are you sure it is not inlined by the compiler? Are you building with optimizations on or off?
Reply