0

May be this question is noobish but I am not well versed with unix environment and profiling.

I want to profile a server code written in C running on Ubuntu as a service (I start it with service command). Once it is started it listens for request and then performs some operation.

I am not able to understand how exactly to do the profiling using the tools like gprof, valgrind and sprof.

I have tried all three but not able to generate any log.

I tried valgrind but it just executes, doesn't wait for the actual request to come.

Used gprof and sprof but no files are being generated.

I looked at several examples on SO and other sites but they talk about a sample code which generates an executable which is then run.

I really need some help now.

Thanks

user3275095
  • 1,605
  • 4
  • 24
  • 36
  • Can you run it under GDB (in a debug build)? Then a method that leads you to whatever speedups there are is [*this*](http://stackoverflow.com/a/378024/23771). – Mike Dunlavey Oct 10 '15 at 20:08
  • Thanks. I had seen your post already and it was really too much for me. Frankly, I am not an expert and not at all comfortable with GDB. :) But, I try. Anyways, I fixed few things which improved the performance but I am not sure how and there's a problem with GDB, the core is generated but when I run bt full it shows nothing. – user3275095 Oct 11 '15 at 03:36
  • When I use GDB, I type Control-C to halt the program. Then in GDB I type "thread 1" to put it on the main thread. Then I type "bt" and it shows the stack trace where it was halted. I study that to see what it is doing. After I understand that, I type "c" so it will continue executing. Then I type Control-C all over again. If the program completes before I get a chance to interrupt it, I put in a temporary outer loop so it executes over and over. That's on Windows - Unix should be about the same. – Mike Dunlavey Oct 11 '15 at 13:00
  • I'll try this once I am able to find the cause of not getting anything in the GDB. Thanks for you help. – user3275095 Oct 11 '15 at 16:41
  • user3275095, you can try some modern profiler like `perf` (linux) - `perf top -p PID` where PID is pid of your service; or `perf record -p PID`, serve some requests, then Ctrl-C in `perf` console and `perf report`. – osgx Jan 09 '16 at 04:49

0 Answers0