<commit_before>#include "metricsTreeView.h"
#include <sstream>
#include <iomanip>
using namespace kokrotviz;


MetricsTreeView::ModelColumnRecord::ModelColumnRecord() 
{
    add(mNameColumn);
    add(mTimeColumn);
    add(mMemoryColumn);
}

MetricsTreeView::MetricsTreeView() : mColumnRecord()
{
    mTreeStore = Gtk::TreeStore::create(mColumnRecord);
}

void MetricsTreeView::clear()
{
    mTreeStore->clear();
}

void MetricsTreeView::addMetric(kok_metric_type Type, double Time, int Mem)
{
    bool isMicro = Type > KOKROTDBG_METRIC_MICRO_BASE;
    Gtk::TreeModel::Row parent = (isMicro ? *mMicrocosmItem : *mMacrocosmItem);
    double refTime = (isMicro ? mTotalMicroTime : mTotalMacroTime);
    int refMem = (isMicro ? mTotalMicroMemory : mTotalMacroMemory);

    double timePercent = 100.0 * Time / refTime, memPercent = 100.0 * Mem / refMem;

#define DEFINE_CATEGORY(cat, str) \
    case cat: { \
        category = (str); \
    } break

    std::string category = "Unknown";
    switch (Type) {
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_CUMULATIVE_TABLE_COMPUTATION, "Cumulative table computation");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_BINARIZATION, "Image binarization");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_FINDER_CANDIDATE_SEARCH, "Finder candidate search");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_FINDER_SQUARE_PROCESSING, "Finder pattern processing");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_CODE_LOCATION_HYPOTHESIZATION, "Hypothesizing of code locations") ;
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_ALLOCATION_OVERHEAD, "Memory allocation");
        default: break;
    }

    Gtk::TreeModel::iterator prow = mTreeStore->append(parent.children());
    Gtk::TreeModel::Row row = *prow;

    row[mColumnRecord.mNameColumn] = category;
    row[mColumnRecord.mMemoryColumn] = Glib::ustring(formatMemory(Mem, memPercent));
    row[mColumnRecord.mTimeColumn] = Glib::ustring(formatTime(Time, timePercent));
<commit_msg>Make KokrotViz aware of timing categories<commit_after>#include "metricsTreeView.h"
#include <sstream>
#include <iomanip>
using namespace kokrotviz;


MetricsTreeView::ModelColumnRecord::ModelColumnRecord() 
{
    add(mNameColumn);
    add(mTimeColumn);
    add(mMemoryColumn);
}

MetricsTreeView::MetricsTreeView() : mColumnRecord()
{
    mTreeStore = Gtk::TreeStore::create(mColumnRecord);
}

void MetricsTreeView::clear()
{
    mTreeStore->clear();
}

void MetricsTreeView::addMetric(kok_metric_type Type, double Time, int Mem)
{
    bool isMicro = Type > KOKROTDBG_METRIC_MICRO_BASE;
    Gtk::TreeModel::Row parent = (isMicro ? *mMicrocosmItem : *mMacrocosmItem);
    double refTime = (isMicro ? mTotalMicroTime : mTotalMacroTime);
    int refMem = (isMicro ? mTotalMicroMemory : mTotalMacroMemory);

    double timePercent = 100.0 * Time / refTime, memPercent = 100.0 * Mem / refMem;

#define DEFINE_CATEGORY(cat, str) \
    case cat: { \
        category = (str); \
    } break

    std::string category = "Unknown";
    switch (Type) {
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_CUMULATIVE_TABLE_COMPUTATION, "Cumulative table computation");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_BINARIZATION, "Image binarization");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_FINDER_CANDIDATE_SEARCH, "Finder candidate search");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_FINDER_SQUARE_PROCESSING, "Finder pattern processing");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_CODE_LOCATION_HYPOTHESIZATION, "Hypothesizing of code locations") ;
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MACRO_ALLOCATION_OVERHEAD, "Memory allocation");

        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MICRO_CODE_PROJECTION, "Code projection");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MICRO_CODE_BINARIZATION, "Code binarization");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MICRO_CODE_REORIENTATION, "Code reorientation");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MICRO_SAMPLING_GRID_BUILD, "Sampling grid building");
        DEFINE_CATEGORY(
                KOKROTDBG_METRIC_MICRO_FINAL_READ, "Final QR code read");
        default: break;
    }

    Gtk::TreeModel::iterator prow = mTreeStore->append(parent.children());
    Gtk::TreeModel::Row row = *prow;

    row[mColumnRecord.mNameColumn] = category;
    row[mColumnRecord.mMemoryColumn] = Glib::ustring(formatMemory(Mem, memPercent));
    row[mColumnRecord.mTimeColumn] = Glib::ustring(formatTime(Time, timePercent));

{'fraction_non_alphanumeric': 0.0972605648757698, 'fraction_numerical': 0.0033977489912932683, 'mean_word_length': 3.7672064777327936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7037002', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1589, 'n_words': 254}