<fieldset>
  <legend>{% trans 'Profiling' %}</legend>
  <div class="floatleft">
    <h3>{% trans 'Detailed profile' %}</h3>
    <table id="profiletable">
      <thead>
      <tr>
        <th>
          {% trans 'Order' %}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans 'State' %}
          {{ show_mysql_docu('general-thread-states') }}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans 'Time' %}
          <div class="sorticon"></div>
        </th>
      </tr>
      </thead>
      <tbody>
        {{ detailed_table|raw }}
      </tbody>
    </table>
  </div>

  <div class="floatleft">
    <h3>{% trans 'Summary by state' %}</h3>
    <table id="profilesummarytable">
      <thead>
      <tr>
        <th>
          {% trans 'State' %}
          {{ show_mysql_docu('general-thread-states') }}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans 'Total Time' %}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans '% Time' %}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans 'Calls' %}
          <div class="sorticon"></div>
        </th>
        <th>
          {% trans 'ø Time' %}
          <div class="sorticon"></div>
        </th>
      </tr>
      </thead>
      <tbody>
        {% for name, stats in states %}
          <tr>
            <td>{{ name }}</td>
            <td align="right">
              {{ format_number(stats['total_time'], 3, 1) }}s
              <span class="rawvalue hide">{{ stats['total_time'] }}</span>
            </td>
            <td align="right">
              {{ format_number(100 * (stats['total_time'] / total_time), 0, 2) }}%
            </td>
            <td align="right">{{ stats['calls'] }}</td>
            <td align="right">
              {{ format_number(stats['total_time'] / stats['calls'], 3, 1) }}s
              <span class="rawvalue hide">
                {{ (stats['total_time'] / stats['calls'])|number_format(8, '.', '') }}
              </span>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>

    <script type="text/javascript">
      url_query = '{{ url_query }}';
    </script>
  </div>
  <div class='clearfloat'></div>

  <div id="profilingChartData" class="hide">
    {{ chart_json|json_encode() }}
  </div>
  <div id="profilingchart" class="hide"></div>

  <script type="text/javascript">
    AJAX.registerOnload('sql.js', function () {
      Sql.makeProfilingChart();
      Sql.initProfilingTables();
    });
  </script>
</fieldset>
