You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Jan Lehnardt <ja...@apache.org> on 2008/07/03 14:52:55 UTC

CouchDB code coverage and profiling

Heya,
as suggest by Joe I ran Erlang's cover, cprof and
fprof tools on CouchDB.

cover:
The cover module will tell us, for each source file
how often a line was executed. Lines with a count
of 0 (zero), are never called and might be good
candidates for being nuked.

The results for each module can be found here:
http://people.apache.org/~jan/couchdb/cover/

I started the cover module, ran the browser test
suite once and then generated the result files. So
this only covers what the test suite covers.

You might notice quite a few 0-count lines:

grep -c '0..' *.html
cjson_cover.html:158
couch_btree_cover.html:183
couch_db_cover.html:143
couch_db_update_notifier_cover.html:16
couch_doc_cover.html:48
couch_event_sup_cover.html:12
couch_file_cover.html:37
couch_ft_query_cover.html:28
couch_httpd_cover.html:228
couch_key_tree_cover.html:21
couch_log_cover.html:35
couch_query_servers_cover.html:66
couch_rep_cover.html:54
couch_server_cover.html:52
couch_server_sup_cover.html:63
couch_stream_cover.html:53
couch_util_cover.html:84
couch_view_cover.html:120

How to run this yourself:
1) install CouchDB
2) Start CouchDB with ./bin/couchdb -i
3) In the resulting Erlang shell, run this:
1> cover:start().
4) Copy the CouchDB source files into the
installation:
$ cp -r couchdb-0.8-incubating/src/couchdb lib/couchdb/erlang/lib/ 
couch-0.8.0-incubating/src
5) Recompile the sources for profiling support
2> cover:compile_directory("lib/couchdb/erlang/lib/couch-0.8.0- 
incubating/src").
(adjust the path as needed).
4) Run the test suite or whatever you
want to test
5) In the Erlang console again:
3> lists:foreach(fun(Elm) -> cover:analyse_to_file(Elm,  
atom_to_list(Elm) ++ "_cover.html", [html]) end, cover:modules()).
6) stop or suspend CouchDB (ctrl-c / ctrl-z / q(). ...)
7) Look at all the *.html files in the current directory

cprof:
cprof counts the number of times a function
is called. Again, this is gathered only by
running the test suite.

The result can be found here:
http://people.apache.org/~jan/couchdb/cprof/

How to run this yourself:
1) Install CouchDB
2) Add this line to the bin/couchdb file on
line 216:
         -eval \"cprof:start()\" \
3) Start CouchDB with ./bin/couchdb -i
4) Run the browser test suite or whatever
you want to test
5) On the Erlang console that was opened with
./bin/couchdb -i
1> cprof:pause().
2> cprof:analyse().

fprof:
This gives us an idea how much time was spent
in each function. Again, this is gathered only by
running the test suite. Time can be wall clock time
and cpu time. This is wall clock time. If you like to
see CPU time, I can run that well.

The result can be found here:
http://people.apache.org/~jan/couchdb/fprof/

How to run this yourself:
1) Install CouchDB
2) Add these lines to the bin/couchdb file on
line 216 and 217:
         -eval \"fprof:start()\" \
         -eval \"fprof:trace(start, \"fprof.trace\")\" \
3) Start CouchDB with ./bin/couchdb -i
4) Run the browser test suite or whatever
you want to test
5) On the Erlang console that was opened with
./bin/couchdb -i:
1> fprof:trace(stop).
2> fprof:profile(). % This takes QUITE some time and appears
to run only on a single CPU/core. What's wrong with that?
3> fprof:analyse().

--

It'd be nice if we could integrate the generation of these
statistics into the installation somehow. For example
the optional installation of the src directory, so users
and developers can easily do a c(module). on the Erlang
shell for testing new stuff. Or do a "make profile" to get
profiling results and all that. Any ideas on how to do that?
Noah?

Cheers
Jan
--

Re: CouchDB code coverage and profiling

Posted by Jan Lehnardt <ja...@apache.org>.
Hello again,
I ran the eprof tool as well and it came up
with the following statistics:
http://people.apache.org/~jan/couchdb/eprof/eprof.log

This is again just running the test suite.

With a bit of trial and error I found out that I can
only profile the following modules:

eprof:profile([couch_server, couch_server_sup, couch_view,  
couch_httpd]).

This might not lead to good results. Any pointers
on how to do this right would be nice :)

Cheers
Jan
--

On Jul 3, 2008, at 14:52, Jan Lehnardt wrote:

> Heya,
> as suggest by Joe I ran Erlang's cover, cprof and
> fprof tools on CouchDB.
>
> cover:
> The cover module will tell us, for each source file
> how often a line was executed. Lines with a count
> of 0 (zero), are never called and might be good
> candidates for being nuked.
>
> The results for each module can be found here:
> http://people.apache.org/~jan/couchdb/cover/
>
> I started the cover module, ran the browser test
> suite once and then generated the result files. So
> this only covers what the test suite covers.
>
> You might notice quite a few 0-count lines:
>
> grep -c '0..' *.html
> cjson_cover.html:158
> couch_btree_cover.html:183
> couch_db_cover.html:143
> couch_db_update_notifier_cover.html:16
> couch_doc_cover.html:48
> couch_event_sup_cover.html:12
> couch_file_cover.html:37
> couch_ft_query_cover.html:28
> couch_httpd_cover.html:228
> couch_key_tree_cover.html:21
> couch_log_cover.html:35
> couch_query_servers_cover.html:66
> couch_rep_cover.html:54
> couch_server_cover.html:52
> couch_server_sup_cover.html:63
> couch_stream_cover.html:53
> couch_util_cover.html:84
> couch_view_cover.html:120
>
> How to run this yourself:
> 1) install CouchDB
> 2) Start CouchDB with ./bin/couchdb -i
> 3) In the resulting Erlang shell, run this:
> 1> cover:start().
> 4) Copy the CouchDB source files into the
> installation:
> $ cp -r couchdb-0.8-incubating/src/couchdb lib/couchdb/erlang/lib/ 
> couch-0.8.0-incubating/src
> 5) Recompile the sources for profiling support
> 2> cover:compile_directory("lib/couchdb/erlang/lib/couch-0.8.0- 
> incubating/src").
> (adjust the path as needed).
> 4) Run the test suite or whatever you
> want to test
> 5) In the Erlang console again:
> 3> lists:foreach(fun(Elm) -> cover:analyse_to_file(Elm,  
> atom_to_list(Elm) ++ "_cover.html", [html]) end, cover:modules()).
> 6) stop or suspend CouchDB (ctrl-c / ctrl-z / q(). ...)
> 7) Look at all the *.html files in the current directory
>
> cprof:
> cprof counts the number of times a function
> is called. Again, this is gathered only by
> running the test suite.
>
> The result can be found here:
> http://people.apache.org/~jan/couchdb/cprof/
>
> How to run this yourself:
> 1) Install CouchDB
> 2) Add this line to the bin/couchdb file on
> line 216:
>        -eval \"cprof:start()\" \
> 3) Start CouchDB with ./bin/couchdb -i
> 4) Run the browser test suite or whatever
> you want to test
> 5) On the Erlang console that was opened with
> ./bin/couchdb -i
> 1> cprof:pause().
> 2> cprof:analyse().
>
> fprof:
> This gives us an idea how much time was spent
> in each function. Again, this is gathered only by
> running the test suite. Time can be wall clock time
> and cpu time. This is wall clock time. If you like to
> see CPU time, I can run that well.
>
> The result can be found here:
> http://people.apache.org/~jan/couchdb/fprof/
>
> How to run this yourself:
> 1) Install CouchDB
> 2) Add these lines to the bin/couchdb file on
> line 216 and 217:
>        -eval \"fprof:start()\" \
>        -eval \"fprof:trace(start, \"fprof.trace\")\" \
> 3) Start CouchDB with ./bin/couchdb -i
> 4) Run the browser test suite or whatever
> you want to test
> 5) On the Erlang console that was opened with
> ./bin/couchdb -i:
> 1> fprof:trace(stop).
> 2> fprof:profile(). % This takes QUITE some time and appears
> to run only on a single CPU/core. What's wrong with that?
> 3> fprof:analyse().
>
> --
>
> It'd be nice if we could integrate the generation of these
> statistics into the installation somehow. For example
> the optional installation of the src directory, so users
> and developers can easily do a c(module). on the Erlang
> shell for testing new stuff. Or do a "make profile" to get
> profiling results and all that. Any ideas on how to do that?
> Noah?
>
> Cheers
> Jan
> --
>


Re: CouchDB code coverage and profiling

Posted by Noah Slater <ns...@apache.org>.
On Thu, Jul 03, 2008 at 08:08:15PM +0200, Jan Lehnardt wrote:
> I can come up with a more thought out proposal if you like :)

Sure, well, I think we're in agreement.

Just give me a shout when the hooks are in place and I'll get to work.

Best,

-- 
Noah Slater, http://people.apache.org/~nslater/

Re: CouchDB code coverage and profiling

Posted by Jan Lehnardt <ja...@apache.org>.
On Jul 3, 2008, at 16:07, Noah Slater wrote:

> On Thu, Jul 03, 2008 at 03:47:09PM +0200, Jan Lehnardt wrote:
>> Yeah, I don't know what the right place is, but it'd be nice if it  
>> was easy
>> for a developer or tester to access. A flag will do for profiling,  
>> but not for
>> the coverage (unless we implicitly recompile CouchDB which I don't  
>> think is a
>> good idea).
>>
>> What about installing the source dir with the beam files? It  
>> appears to be not
>> uncommon in the free software Erlang world to have a module-x.y.z/ 
>> ebin for the
>> beam files and module-x.z.y/src for the sources.
>
> Okay, you have a point. Perhaps something like:
>
>  ./configure --with-profiling --with-coverage
>
> This would be more elegant that cluttering up `couchdb` or similar.

Ah no, you got that wrong (or I explained it badly :)
coverage needs a different build, so --with-coverage makes sense.

Profiling does not need a recompilation and would best
served (IMHO) as couchdb --profile-function-calls and --profile- 
function-times
or however that would be integrated into the command.

couchdb --profile=function-calls --profile=function-call-times
--profile=function-fall-times-cpu or have some way to pass
options down to the profiler, you get the idea, some way of
specifying at runtime how to profile CouchDB.

I can come up with a more thought out proposal if you like :)

The other? Opinions on that?

Cheers
Jan
--


>
>
> As for the ebin/src, sure, though we originally did that but one of  
> my Debian
> Erlang mentors suggested that it wasn't necessary, so I took it out.
>
> Best,
>
> -- 
> Noah Slater, http://people.apache.org/~nslater/
>


Re: CouchDB code coverage and profiling

Posted by Noah Slater <ns...@apache.org>.
On Thu, Jul 03, 2008 at 03:47:09PM +0200, Jan Lehnardt wrote:
> Yeah, I don't know what the right place is, but it'd be nice if it was easy
> for a developer or tester to access. A flag will do for profiling, but not for
> the coverage (unless we implicitly recompile CouchDB which I don't think is a
> good idea).
>
> What about installing the source dir with the beam files? It appears to be not
> uncommon in the free software Erlang world to have a module-x.y.z/ebin for the
> beam files and module-x.z.y/src for the sources.

Okay, you have a point. Perhaps something like:

  ./configure --with-profiling --with-coverage

This would be more elegant that cluttering up `couchdb` or similar.

As for the ebin/src, sure, though we originally did that but one of my Debian
Erlang mentors suggested that it wasn't necessary, so I took it out.

Best,

-- 
Noah Slater, http://people.apache.org/~nslater/

Re: CouchDB code coverage and profiling

Posted by Jan Lehnardt <ja...@apache.org>.
Heya Noah.
On Jul 3, 2008, at 15:15, Noah Slater wrote:

> On Thu, Jul 03, 2008 at 02:52:55PM +0200, Jan Lehnardt wrote:
>> It'd be nice if we could integrate the generation of these  
>> statistics into the
>> installation somehow. For example the optional installation of the  
>> src
>> directory, so users and developers can easily do a c(module). on  
>> the Erlang
>> shell for testing new stuff. Or do a "make profile" to get  
>> profiling results
>> and all that. Any ideas on how to do that?  Noah?
>
> My initial thoughts are that the build system is not the best place  
> for this.
>
> How about:
>
> * A special flag to `couchdb` that triggers profiling
> * A special script in the source directory that will profile CouchDB  
> for you

Yeah, I don't know what the right place is, but it'd be nice if it was
easy for a developer or tester to access. A flag will do for profiling,
but not for the coverage (unless we implicitly recompile CouchDB which
I don't think is a good idea).

What about installing the source dir with the beam files? It appears
to be not uncommon in the free software Erlang world to have a
module-x.y.z/ebin for the beam files and module-x.z.y/src for the
sources.

Cheers
Jan
--

Re: CouchDB code coverage and profiling

Posted by Noah Slater <ns...@apache.org>.
On Thu, Jul 03, 2008 at 02:52:55PM +0200, Jan Lehnardt wrote:
> It'd be nice if we could integrate the generation of these statistics into the
> installation somehow. For example the optional installation of the src
> directory, so users and developers can easily do a c(module). on the Erlang
> shell for testing new stuff. Or do a "make profile" to get profiling results
> and all that. Any ideas on how to do that?  Noah?

My initial thoughts are that the build system is not the best place for this.

How about:

 * A special flag to `couchdb` that triggers profiling
 * A special script in the source directory that will profile CouchDB for you

Best,

-- 
Noah Slater, http://people.apache.org/~nslater/