wiki:ProfilingGprof

This is a brief instruction on doing profiling job with gprof tool. This instruction will show you how to profile BIND 10 step by step. Knowing how to install and run bind10 is the prerequisite for this profiling wiki. I will take b10-resolver as the example to show you how to do it.

Environment or system setup

First, please make sure GNU compiler (include gcc and g++) is installed in your OS, and your GNU compiler supports “-pg” option. Then check whether the gprof tool is installed. If not, please install it.

If you know nothing about gprof and want to get more info about it, it is recommended to read the following webpage first: http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html

If you want to get profiling charting instead of flat data, you should download and install Graphviz and the “gprof2dot.py” tool in your OS.

Building

Assign “-pg” to CXXFLAGS environment variable (run the command "export CXXFLAGS=-pg" on bash) before configuring the build of BIND 10, then no other special build action.

Running

First of all, modify the codes in /PREFIX/sbin/bind10 to add “spawn_env[ 'GMON_OUT_PREFIX' ] = self.args[0]” to _spawn function as followed:

[test@test tmp]$ diff bind10 bind10-new
      def _spawn(self):
          if self.dev_null_stdout:
              spawn_stdout = self.dev_null
          else:
              spawn_stdout = None
          if self.dev_null_stderr:
              spawn_stderr = self.dev_null
          else:
              spawn_stderr = None
          # Environment variables for the child process will be a copy of those
          # of the boss process with any additional specific variables given
          # on construction (self.env).
          spawn_env = copy.deepcopy(os.environ)
          spawn_env.update(self.env)
          spawn_env['PATH'] = LIBEXECPATH + ':' + spawn_env['PATH']
+         spawn_env['GMON_OUT_PREFIX'] = self.args[0]
          self.process = subprocess.Popen(self.args,
                                          stdin=subprocess.PIPE,
                                          stdout=spawn_stdout,
                                          stderr=spawn_stderr,
                                          close_fds=True,
                                          env=spawn_env,
                                          preexec_fn=self._preexec_work)
          self.pid = self.process.pid

      # spawn() and respawn() are the same for now, but in the future they
      # may have different functionality
      def spawn(self):
          self._spawn()

Then run the BIND 10 components as documented in the BIND 10 User's Guide. Take for example, if you want to the profile the b10-resolver, please do the following things:

bindctl
> config add Boss/components b10-resolver
> config set Boss/components/b10-resolver/special resolver
> config set Boss/components/b10-resolver/kind needed
> config set Boss/components/b10-resolver/priority 10
> config commit

If query operations complete in b10-resolver, then close BIND 10 as followed:

bindctl
> Boss shutdown

Then the b10-resolver.PID profiling file will be created in the current directory.

Profiling

Take b10-resolver as the example. the b10-resolver.PID will be produced in the current directory. And the b10-resolver.PID file is the profiling file for the “b10-resolver” binary executable file in /PREFIX/libexec/bind10-devel/ directory. You can use gprof tool to view the profiling data. If you want to check the flat profile, please do the following thing:

gprof -b /PREFIX/libexec/bind10-devel/b10-resolver ./ b10-resolver.PID

If you want to check the call graph, please do the following step:

gprof -p /PREFIX/libexec/bind10-devel/b10-resolver ./ b10-resolver.PID

If you want to get the profiling charting, please do the following step:

gprof -p /PREFIX/libexec/bind10-devel/b10-resolver ./ b10-resolver.PID | gprof2dot.py|dot –Tpng –o b10-resolver.png

Then the b10-resolver.png is the profiling charting which you want.

Last modified 6 years ago Last modified on Feb 7, 2012, 8:33:20 AM