Cory Watson ha scritto:
On 9/19/07, Marcello Romani <[EMAIL PROTECTED]> wrote:
Again on querylog vs. catalyst...

I've setup a minimal app to test the querylog stuff, but, I can't get
any results, i.e. the statistics obtained from querylog are always zero.

The attached file contains the entire app; here I show the most relevant
files.

Not being familiar with the Model, I've just looked at the code and it
seems pretty simple, creating a QueryLog instance for each schema.

You didn't show how you were getting the information OUT of QueryLog.
The docs for the model contain an example of such.  The first mistake
I could imagine is creating a new schema and then asking it for
QueryLog info.  If it's different from the schema you used in your app
then the log would be empty.


First of all, thanks for the response and for your tip.

I get the info out of querylog by putting it into the stash and by calling its methods from the same template used in the docs of the schema module (the only difference being I don't call c.model('FilmDB') every time in the template, but only once in the controller).

The controller is QueryLog.pm and the template is querylog/index.tt. Both files are included in the tar.gz archive.

I copy/paste them here for convenience.

Thanks again.


Controller/QueryLog.pm:
=======================
package TestQueryLog::Controller::QueryLog;

use strict;
use warnings;
use base 'Catalyst::Controller';

sub index : Private {
    my ( $self, $c ) = @_;

    $c->stash->{querylog} = $c->model('Main')->querylog();

    return;
}

1;


querylog/index.tt:
==================
<div class="featurebox">
  <h3>Query Log Report</h3>
  [% SET total = querylog.time_elapsed | format('%0.6f') %]
  <div>Total SQL Time: [% total | format('%0.6f') %] seconds</div>
  [% SET qcount = querylog.count %]
  <div>Total Queries: [% qcount %]</div>
  [% IF qcount %]
    <div>
      Avg Statement Time:
      [% (querylog.time_elapsed / qcount) | format('%0.6f') %]
      seconds.</div>
      <div>
        <table class="table1">
           <thead>
             <tr>
               <th colspan="3">5 Slowest Queries</th>
             </tr>
           </thead>
           <tbody>
             <tr>
               <th>Time</th>
               <th>%</th>
               <th>SQL</th>
             </tr>
             [% SET i = 0 %]
               [% FOREACH q = querylog_analyzer.get_sorted_queries %]
                 <tr class="[% IF loop.count % 2 %]odd[% END %]">
                   <th class="sub">
                     [% q.time_elapsed | format('%0.6f') %]
                   </th>
                   <td>
                     [% ((q.time_elapsed / total ) * 100 )
                       | format('%i') %]%
                   </td>
                   <td>[% q.sql %] : ([% q.params.join(', ') %])</td>
                 </tr>
                 [% IF i == 5 %]
                   [% LAST %]
                 [% END %]
                 [% SET i = i + 1 %]
               [% END %]
             </tbody>
          </table>
      </div>
  [% END %]
</div>


--
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com

_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to