[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/dtools/bench_chart/ -> bench_chart_charts.inc (source)

   1  <?php
   2  
   3  /**
   4   * Chart reports page
   5   */
   6  function bench_chart_charts() {
   7      $output = '';
   8  
   9      $last_arg = end(arg()); // check for last argument (custom chart request)
  10      if (strlen($last_arg) == 32) {
  11          $path = db_result(db_query('SELECT path FROM {bench_chart} WHERE md5(path) = \'%s\' AND count > 0', $last_arg));
  12          $chart = _charts_system_generate(
  13              t('Hook execution time for path: @path', array('@path' => $path)),
  14              "SELECT CONCAT(ROUND(AVG(totaltime)/1000,2),'s') AS count, hook AS name
  15              FROM {bench_chart}
  16              WHERE path = '$path'
  17              GROUP BY hook
  18              ORDER BY count DESC
  19              LIMIT 10",
  20              'pie3D'
  21          );
  22          $output .= "<div id='charts-chart'>$chart</div>";
  23          $chart = _charts_system_generate(
  24              t('Hook execution count for path: @path', array('@path' => $path)),
  25              "SELECT count AS count, hook AS name
  26              FROM {bench_chart}
  27              WHERE path = '$path'
  28              GROUP BY hook
  29              ORDER BY count DESC
  30              LIMIT 10",
  31              'pie3D'
  32          );
  33          $output .= "<div id='charts-chart'>$chart</div>";
  34      } else  {
  35          $res_paths = db_query('SELECT path FROM {bench_chart} WHERE count = 0 GROUP BY path ORDER BY totaltime DESC LIMIT 3');
  36          if ($res_paths) {
  37              while ($path = db_fetch_object($res_paths)) {
  38                  $path->path = db_escape_string($path->path);
  39                  $chart = _charts_system_generate(
  40                      t('Execution time of hook modules for path: @path', array('@path' => $path->path)),
  41                      'SELECT CONCAT(ROUND(AVG(time)/1000,2),"s") AS count, hook AS name
  42                      FROM {bench_chart}
  43                      GROUP BY hook
  44                      ORDER BY time DESC
  45                      LIMIT 10',
  46                      'pie3D'
  47                  );
  48                  $output .= "<div id='charts-chart'>$chart</div>";
  49              }
  50          }
  51      }
  52  
  53          $chart = _charts_system_generate(
  54              t('Average hook execution time'),
  55              'SELECT CONCAT(ROUND(AVG(time)/1000,2),"s") AS count, hook AS name
  56              FROM {bench_chart}
  57              WHERE count > 0
  58              GROUP BY hook
  59              ORDER BY count DESC
  60              LIMIT 10',
  61              'pie3D'
  62          );
  63      $output .= "<div id='charts-chart'>$chart</div>";
  64  
  65          $chart = _charts_system_generate(
  66              t('Average hook execution count'),
  67              'SELECT count AS count, hook AS name
  68              FROM {bench_chart}
  69              WHERE count > 0
  70              GROUP BY hook
  71              ORDER BY count DESC
  72              LIMIT 10',
  73              'pie3D'
  74          );
  75      $output .= "<div id='charts-chart'>$chart</div>";
  76  
  77      $res_paths = db_query('SELECT path FROM {bench_chart} WHERE count > 0 GROUP BY path');
  78      if ($res_paths) {
  79      while ($path = db_fetch_object($res_paths)) {
  80              $path->path = db_escape_string($path->path);
  81              $chart = _charts_system_generate(
  82                  t('Execution time for path: @path', array('@path' => $path->path)),
  83                  "SELECT CONCAT(ROUND(AVG(totaltime)/1000,2),'s') AS count, hook AS name
  84                  FROM {bench_chart}
  85                  WHERE path = '$path->path' AND count > 0
  86                  GROUP BY hook
  87                  ORDER BY totaltime",
  88                  'line2D'
  89              );
  90              $output .= "<div id='charts-chart'>$chart</div>";
  91  
  92              $path_md5 = md5($path->path);
  93              $gen_url = "admin/reports/charts/hook_stat/$path_md5";
  94              $text = t('Generate hook stats for page: @path', array('@path' => $path->path));
  95              $text = t('Generate module stats for page: @path', array('@path' => $path->path));
  96              $output .= '<br><br>'.l($text, $gen_url);
  97      }
  98      }
  99  
 100    return '<div id="charts-system">'. $output .'</div>';
 101  }
 102  
 103  /**
 104   * Generate some charts using a pre defined method.
 105   *
 106   * @param $title
 107   *   String. The chart title
 108   * @param $sql
 109   *   String. The SQL statement to be executed
 110   * @param $callback
 111   *   String (optional). When a string is given, use it as the
 112   *   parser of the results from SQL. Its important when the
 113   *   results are coded in to DB to ocupy less space, and should
 114   *   be decoded.
 115   * @return
 116   *   String. The HTML chart when all data is fine or a blank string
 117   */
 118  function _charts_system_generate($title, $sql, $type, $callback = NULL) {
 119    $results = db_query($sql);
 120  
 121    while ($result = db_fetch_array($results)) {
 122      if (!empty($callback)) {
 123        $result['name'] = $callback($result['name']);
 124      }
 125      switch ($type) {
 126          case 'line2D':
 127              $data[] = array(
 128                '#value'  => $result['count'],
 129                '#label'  => $result['name']
 130              );
 131              break;
 132          default:
 133              $data[] = array(
 134                '#value'  => $result['count'],
 135                '#label'  => $result['name'] .': '. $result['count']
 136              );
 137          break;
 138      }
 139    }
 140  
 141    if (!empty($data)) {
 142      $settings = variable_get('charts_settings', array());
 143      $chart[0] = $data;
 144      $chart['#title']    = $title;
 145      if ($type) {
 146      $chart['#type']     = $type;
 147      $chart['#width']     = empty($settings['#width']) ? 600 : $settings['#width'];
 148      $chart['#height']     = empty($settings['#height']) ? 200 : $settings['#height'];
 149      }
 150  
 151      return charts_chart($chart);
 152    }
 153  
 154    return '';
 155  }
 156  
 157  /**
 158   * menu()'s callback
 159   */
 160  function bench_chart_show_form() {
 161      $example = array(
 162      '#type'     => 'pie3D', // Display a 3D pie chart
 163      '#color'    => 'f0f0f0', // Background color, in RRGGBB format
 164      '#title'    => t('Example'), // Chart title
 165  
 166      array(5, 10, 25, 60),
 167      );
 168  $example = array(
 169    '#type'     => 'pie3D', // Display a 3D pie chart
 170    '#color'    => 'f0f0f0', // Background color, in RRGGBB format
 171    '#title'    => t('Example'), // Chart title
 172    array(
 173      array('#value' => 60, '#label' => t('60%')),
 174      array('#value' => 25, '#label' => t('25%')),
 175      array('#value' => 10, '#label' => t('10%')),
 176      array('#value' => 5,  '#label' => t('5%')),
 177    ),
 178  );
 179      return charts_chart($example);
 180  }
 181  
 182  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7