You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
491 lines
13 KiB
491 lines
13 KiB
15 years ago
|
/* This file is part of KCachegrind.
|
||
|
Copyright (C) 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
|
||
|
|
||
|
KCachegrind is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation, version 2.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
15 years ago
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
15 years ago
|
*/
|
||
|
|
||
|
/*
|
||
|
* Configuration for KCachegrind
|
||
|
*/
|
||
|
|
||
|
#include <kconfig.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include "configuration.h"
|
||
|
#include "tracedata.h"
|
||
|
#include "configdlgbase.h"
|
||
|
|
||
|
#include "traceitemview.h"
|
||
|
|
||
|
//
|
||
|
// Some predefined cost types...
|
||
|
//
|
||
|
|
||
14 years ago
|
static TQStringList knownTypes()
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList l;
|
||
15 years ago
|
|
||
|
l << "Ir" << "Dr" << "Dw"
|
||
|
<< "I1mr" << "D1mr" << "D1mw"
|
||
|
<< "I2mr" << "D2mr" << "D2mw"
|
||
|
|
||
|
<< "Smp" << "Sys" << "User"
|
||
|
<< "L1m" << "L2m" << "CEst";
|
||
|
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
static TQString knownFormula(TQString name)
|
||
15 years ago
|
{
|
||
14 years ago
|
if (name =="L1m") return TQString("I1mr + D1mr + D1mw");
|
||
|
if (name =="L2m") return TQString("I2mr + D2mr + D2mw");
|
||
|
if (name =="CEst") return TQString("Ir + 10 L1m + 100 L2m");
|
||
15 years ago
|
|
||
13 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
static TQString knownLongName(TQString name)
|
||
15 years ago
|
{
|
||
|
if (name == "Ir") return i18n("Instruction Fetch");
|
||
|
if (name =="Dr") return i18n("Data Read Access");
|
||
|
if (name =="Dw") return i18n("Data Write Access");
|
||
|
if (name =="I1mr") return i18n("L1 Instr. Fetch Miss");
|
||
|
if (name =="D1mr") return i18n("L1 Data Read Miss");
|
||
|
if (name =="D1mw") return i18n("L1 Data Write Miss");
|
||
|
if (name =="I2mr") return i18n("L2 Instr. Fetch Miss");
|
||
|
if (name =="D2mr") return i18n("L2 Data Read Miss");
|
||
|
if (name =="D2mw") return i18n("L2 Data Write Miss");
|
||
|
if (name =="Smp") return i18n("Samples");
|
||
|
if (name =="Sys") return i18n("System Time");
|
||
|
if (name =="User") return i18n("User Time");
|
||
|
if (name =="L1m") return i18n("L1 Miss Sum");
|
||
|
if (name =="L2m") return i18n("L2 Miss Sum");
|
||
|
if (name =="CEst") return i18n("Cycle Estimation");
|
||
|
|
||
13 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
// Configuration
|
||
|
//
|
||
|
|
||
|
Configuration* Configuration::_config = 0;
|
||
|
|
||
|
Configuration::Configuration()
|
||
|
:_colors(517)
|
||
|
{
|
||
|
_config = 0;
|
||
|
|
||
|
_colors.setAutoDelete(true);
|
||
|
_objectSourceDirs.setAutoDelete(true);
|
||
|
|
||
|
// defaults
|
||
|
_showPercentage = true;
|
||
|
_showExpanded = false;
|
||
|
_showCycles = true;
|
||
|
_cycleCut = 0.0;
|
||
|
_percentPrecision = 2;
|
||
|
|
||
|
// max symbol count/length in tooltip/popup
|
||
|
_maxSymbolLength = 30;
|
||
|
_maxSymbolCount = 10;
|
||
|
_maxListCount = 100;
|
||
|
|
||
|
// annotation behaviour
|
||
|
_context = 3;
|
||
|
_noCostInside = 20;
|
||
|
}
|
||
|
|
||
|
Configuration* Configuration::config()
|
||
|
{
|
||
|
if (!_config)
|
||
|
_config = new Configuration();
|
||
|
|
||
|
return _config;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Configuration::saveOptions(KConfig* kconfig)
|
||
|
{
|
||
|
Configuration* c = config();
|
||
|
|
||
|
// color options
|
||
14 years ago
|
KConfigGroup colorConfig(kconfig, TQCString("CostColors"));
|
||
|
TQDictIterator<ColorSetting> it( c->_colors );
|
||
15 years ago
|
int count = 1;
|
||
|
for( ; it.current(); ++it ) {
|
||
|
if ( !(*it)->automatic ) {
|
||
13 years ago
|
colorConfig.writeEntry( TQString("Name%1").arg(count),
|
||
15 years ago
|
it.currentKey());
|
||
13 years ago
|
colorConfig.writeEntry( TQString("Color%1").arg(count),
|
||
15 years ago
|
(*it)->color);
|
||
|
//qDebug("Written Color %s (%d)", it.currentKey().ascii(), count);
|
||
|
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
colorConfig.writeEntry( "Count", count-1);
|
||
|
|
||
|
// source options
|
||
14 years ago
|
KConfigGroup sourceConfig(kconfig, TQCString("Source"));
|
||
15 years ago
|
sourceConfig.writeEntry("Dirs", c->_generalSourceDirs, ':');
|
||
14 years ago
|
TQDictIterator<TQStringList> it2( c->_objectSourceDirs );
|
||
15 years ago
|
count = 1;
|
||
|
for( ; it2.current(); ++it2 ) {
|
||
13 years ago
|
sourceConfig.writeEntry( TQString("Object%1").arg(count),
|
||
15 years ago
|
it2.currentKey());
|
||
13 years ago
|
sourceConfig.writeEntry( TQString("Dirs%1").arg(count),
|
||
15 years ago
|
*(*it2), ':');
|
||
|
count++;
|
||
|
}
|
||
|
sourceConfig.writeEntry( "Count", count-1);
|
||
|
|
||
|
// general options
|
||
14 years ago
|
KConfigGroup generalConfig(kconfig, TQCString("General"));
|
||
15 years ago
|
generalConfig.writeEntry("ShowPercentage", c->_showPercentage);
|
||
|
generalConfig.writeEntry("ShowExpanded", c->_showExpanded);
|
||
|
generalConfig.writeEntry("ShowCycles", c->_showCycles);
|
||
|
generalConfig.writeEntry("CycleCut", c->_cycleCut);
|
||
|
generalConfig.writeEntry("MaxSymbolCount", c->_maxSymbolCount);
|
||
|
generalConfig.writeEntry("MaxListCount", c->_maxListCount);
|
||
|
generalConfig.writeEntry("MaxSymbolLength", c->_maxSymbolLength);
|
||
|
generalConfig.writeEntry("PercentPrecision", c->_percentPrecision);
|
||
|
|
||
|
generalConfig.writeEntry("Context", c->_context);
|
||
|
generalConfig.writeEntry("NoCostInside", c->_noCostInside);
|
||
|
|
||
14 years ago
|
KConfigGroup ctConfig(kconfig, TQCString("CostTypes"));
|
||
15 years ago
|
int ctCount = TraceCostType::knownTypeCount();
|
||
|
ctConfig.writeEntry( "Count", ctCount);
|
||
|
for (int i=0; i<ctCount; i++) {
|
||
|
TraceCostType* t = TraceCostType::knownType(i);
|
||
13 years ago
|
ctConfig.writeEntry( TQString("Name%1").arg(i+1), t->name());
|
||
15 years ago
|
|
||
|
// Use localized key
|
||
|
TraceItemView::writeConfigEntry(&ctConfig,
|
||
13 years ago
|
TQString("Longname%1").arg(i+1).ascii(),
|
||
15 years ago
|
t->longName(),
|
||
|
knownLongName(t->name()).utf8().data() /*, true */ );
|
||
|
TraceItemView::writeConfigEntry(&ctConfig,
|
||
13 years ago
|
TQString("Formula%1").arg(i+1).ascii(),
|
||
15 years ago
|
t->formula(), knownFormula(t->name()).utf8().data());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void Configuration::readOptions(KConfig* kconfig)
|
||
|
{
|
||
|
int i, count;
|
||
|
Configuration* c = config();
|
||
|
|
||
|
// color options
|
||
|
c->_colors.clear();
|
||
|
|
||
|
// colors for default cost types:
|
||
|
// red for L2 misses, green for L1 misses, blue for normal accesses
|
||
14 years ago
|
c->color("CostType-I2mr")->color = TQColor(240, 0, 0);
|
||
|
c->color("CostType-D2mr")->color = TQColor(180,40,40);
|
||
|
c->color("CostType-D2mw")->color = TQColor(120,80,80);
|
||
15 years ago
|
|
||
14 years ago
|
c->color("CostType-I1mr")->color = TQColor(0, 240, 0);
|
||
|
c->color("CostType-D1mr")->color = TQColor(40,180,40);
|
||
|
c->color("CostType-D1mw")->color = TQColor(80,120,80);
|
||
15 years ago
|
|
||
14 years ago
|
c->color("CostType-Ir")->color = TQColor(0, 0, 240);
|
||
|
c->color("CostType-Dr")->color = TQColor(40,40,180);
|
||
|
c->color("CostType-Dw")->color = TQColor(80,80,120);
|
||
15 years ago
|
|
||
14 years ago
|
KConfigGroup colorConfig(kconfig, TQCString("CostColors"));
|
||
15 years ago
|
count = colorConfig.readNumEntry("Count", 0);
|
||
|
for (i=1;i<=count;i++) {
|
||
13 years ago
|
TQString n = colorConfig.readEntry(TQString("Name%1").arg(i));
|
||
|
TQColor color = colorConfig.readColorEntry(TQString("Color%1").arg(i));
|
||
15 years ago
|
|
||
|
if (n.isEmpty()) continue;
|
||
|
|
||
|
ColorSetting* cs = new ColorSetting;
|
||
|
cs->name = n;
|
||
|
cs->automatic = false;
|
||
|
cs->color = color;
|
||
|
|
||
|
c->_colors.insert(n, cs);
|
||
|
|
||
|
//qDebug("Read Color %s", n.ascii());
|
||
|
}
|
||
|
|
||
|
// source options
|
||
14 years ago
|
KConfigGroup sourceConfig(kconfig, TQCString("Source"));
|
||
|
TQStringList dirs;
|
||
15 years ago
|
dirs = sourceConfig.readListEntry("Dirs", ':');
|
||
|
if (dirs.count()>0) c->_generalSourceDirs = dirs;
|
||
|
count = sourceConfig.readNumEntry("Count", 0);
|
||
|
c->_objectSourceDirs.clear();
|
||
|
if (count>17) c->_objectSourceDirs.resize(count);
|
||
|
for (i=1;i<=count;i++) {
|
||
13 years ago
|
TQString n = sourceConfig.readEntry(TQString("Object%1").arg(i));
|
||
|
dirs = sourceConfig.readListEntry(TQString("Dirs%1").arg(i), ':');
|
||
15 years ago
|
|
||
|
if (n.isEmpty() || (dirs.count()==0)) continue;
|
||
|
|
||
14 years ago
|
c->_objectSourceDirs.insert(n, new TQStringList(dirs));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
// general options
|
||
14 years ago
|
KConfigGroup generalConfig(kconfig, TQCString("General"));
|
||
15 years ago
|
c->_showPercentage = generalConfig.readBoolEntry("ShowPercentage", true);
|
||
|
c->_showExpanded = generalConfig.readBoolEntry("ShowExpanded", false);
|
||
|
c->_showCycles = generalConfig.readBoolEntry("ShowCycles", true);
|
||
|
c->_cycleCut = generalConfig.readDoubleNumEntry("CycleCut", 0.0);
|
||
|
c->_maxSymbolCount = generalConfig.readNumEntry("MaxSymbolCount", 10);
|
||
|
c->_maxListCount = generalConfig.readNumEntry("MaxListCount", 100);
|
||
|
c->_maxSymbolLength = generalConfig.readNumEntry("MaxSymbolLength", 30);
|
||
|
c->_percentPrecision = generalConfig.readNumEntry("PercentPrecision", 2);
|
||
|
|
||
|
c->_context = generalConfig.readNumEntry("Context", 3);
|
||
|
c->_noCostInside = generalConfig.readNumEntry("NoCostInside", 20);
|
||
|
|
||
|
// known cost types
|
||
|
if (TraceCostType::knownTypeCount()==0) {
|
||
|
|
||
14 years ago
|
KConfigGroup ctConfig(kconfig, TQCString("CostTypes"));
|
||
15 years ago
|
int ctCount = ctConfig.readNumEntry("Count", 0);
|
||
|
if (ctCount>0) {
|
||
|
for (int i=1;i<=ctCount;i++) {
|
||
13 years ago
|
TQString n = ctConfig.readEntry(TQString("Name%1").arg(i));
|
||
|
TQString l = ctConfig.readEntry(TQString("Longname%1").arg(i));
|
||
15 years ago
|
if (l.isEmpty()) l = knownLongName(n);
|
||
13 years ago
|
TQString f = ctConfig.readEntry(TQString("Formula%1").arg(i));
|
||
15 years ago
|
if (f.isEmpty()) f = knownFormula(n);
|
||
|
|
||
|
TraceCostType::add(new TraceCostType(n, l, f));
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
// add default types
|
||
|
|
||
14 years ago
|
TQString longName, formula;
|
||
15 years ago
|
TraceCostType* ct;
|
||
14 years ago
|
TQStringList l = knownTypes();
|
||
|
for ( TQStringList::Iterator it = l.begin();
|
||
15 years ago
|
it != l.end(); ++it ) {
|
||
|
longName = knownLongName(*it);
|
||
|
formula = knownFormula(*it);
|
||
|
ct = new TraceCostType(*it, longName, formula);
|
||
|
TraceCostType::add(ct);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQColor Configuration::groupColor(TraceItem* cost)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString n;
|
||
15 years ago
|
|
||
|
if (!cost)
|
||
14 years ago
|
n = TQString("default");
|
||
15 years ago
|
else
|
||
|
n = TraceCost::typeName(cost->type()) + "-" + cost->prettyName();
|
||
|
|
||
|
return color(n)->color;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQColor Configuration::costTypeColor(TraceCostType* t)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString n;
|
||
15 years ago
|
|
||
|
if (!t)
|
||
14 years ago
|
n = TQString("CostType-default");
|
||
15 years ago
|
else
|
||
13 years ago
|
n = TQString("CostType-%1").arg(t->name());
|
||
15 years ago
|
|
||
|
return color(n)->color;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQColor Configuration::functionColor(TraceCost::CostType gt,
|
||
15 years ago
|
TraceFunction* f)
|
||
|
{
|
||
|
TraceCost* group = f;
|
||
14 years ago
|
TQString n;
|
||
15 years ago
|
|
||
|
switch(gt) {
|
||
|
case TraceCost::Object: group = f->object(); break;
|
||
|
case TraceCost::Class: group = f->cls(); break;
|
||
|
case TraceCost::File: group = f->file(); break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (group != f) {
|
||
|
// first look for manual color of a function in a group
|
||
|
n = TraceCost::typeName(group->type()) +
|
||
|
"-" + group->prettyName() +
|
||
|
"-" + f->prettyName();
|
||
|
|
||
|
ColorSetting* cs = color(n, false);
|
||
|
if (cs) return cs->color;
|
||
|
}
|
||
|
return groupColor(group);
|
||
|
}
|
||
|
|
||
14 years ago
|
Configuration::ColorSetting* Configuration::color(TQString n, bool createNew)
|
||
15 years ago
|
{
|
||
|
// qDebug("Color for %s", n.latin1());
|
||
|
|
||
|
// predefined ?
|
||
|
Configuration* c = config();
|
||
|
ColorSetting* cs = c->_colors[n];
|
||
|
if (cs || !createNew) return cs;
|
||
|
|
||
|
// automatic colors...
|
||
|
int h = 0, s = 100;
|
||
|
const char* str = n.ascii();
|
||
|
while (*str) {
|
||
|
h = (h * 37 + s* (unsigned)*str) % 256;
|
||
|
s = (s * 17 + h* (unsigned)*str) % 192;
|
||
|
str++;
|
||
|
}
|
||
|
|
||
|
//qDebug("New color for %s: H %d, S %d", n.ascii(), h, 64+s);
|
||
14 years ago
|
TQColor color = TQColor(h, 64+s, 192, TQColor::Hsv);
|
||
15 years ago
|
|
||
|
cs = new ColorSetting;
|
||
|
cs->name = n;
|
||
|
cs->automatic = true;
|
||
|
cs->color = color;
|
||
|
c->_colors.insert(n, cs);
|
||
|
|
||
|
//qDebug("new Color %s", n.ascii());
|
||
|
|
||
|
return cs;
|
||
|
}
|
||
|
|
||
|
/* Gives back a list of all Source Base Directories of Objects in
|
||
|
* current trace. If a special object is given in 2nd argument,
|
||
|
* put its Source Base in front.
|
||
|
*/
|
||
14 years ago
|
TQStringList Configuration::sourceDirs(TraceData* data, TraceObject* o)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList l = config()->_generalSourceDirs, *ol, *ol2 = 0;
|
||
15 years ago
|
TraceObjectMap::Iterator oit;
|
||
|
for ( oit = data->objectMap().begin();
|
||
|
oit != data->objectMap().end(); ++oit ) {
|
||
|
ol = config()->_objectSourceDirs[(*oit).name()];
|
||
|
if (&(*oit) == o) {
|
||
|
ol2 = ol;
|
||
|
continue;
|
||
|
}
|
||
|
if (!ol) continue;
|
||
|
|
||
|
for(unsigned int i=0;i<ol->count();i++)
|
||
|
l.prepend( (*ol)[i] );
|
||
|
}
|
||
|
if (ol2) {
|
||
|
for(unsigned int i=0;i<ol2->count();i++)
|
||
|
l.prepend( (*ol2)[i] );
|
||
|
}
|
||
|
if (0) kdDebug() << "Configuration::sourceDirs: " << l.join(":") << endl;
|
||
|
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
bool Configuration::showPercentage()
|
||
|
{
|
||
|
return config()->_showPercentage;
|
||
|
}
|
||
|
|
||
|
bool Configuration::showExpanded()
|
||
|
{
|
||
|
return config()->_showExpanded;
|
||
|
}
|
||
|
|
||
|
bool Configuration::showCycles()
|
||
|
{
|
||
|
return config()->_showCycles;
|
||
|
}
|
||
|
|
||
|
void Configuration::setShowPercentage(bool s)
|
||
|
{
|
||
|
Configuration* c = config();
|
||
|
if (c->_showPercentage == s) return;
|
||
|
|
||
|
c->_showPercentage = s;
|
||
|
}
|
||
|
|
||
|
void Configuration::setShowExpanded(bool s)
|
||
|
{
|
||
|
Configuration* c = config();
|
||
|
if (c->_showExpanded == s) return;
|
||
|
|
||
|
c->_showExpanded = s;
|
||
|
}
|
||
|
|
||
|
void Configuration::setShowCycles(bool s)
|
||
|
{
|
||
|
Configuration* c = config();
|
||
|
if (c->_showCycles == s) return;
|
||
|
|
||
|
c->_showCycles = s;
|
||
|
}
|
||
|
|
||
|
double Configuration::cycleCut()
|
||
|
{
|
||
|
return config()->_cycleCut;
|
||
|
}
|
||
|
|
||
|
int Configuration::percentPrecision()
|
||
|
{
|
||
|
return config()->_percentPrecision;
|
||
|
}
|
||
|
|
||
|
int Configuration::maxSymbolLength()
|
||
|
{
|
||
|
return config()->_maxSymbolLength;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString Configuration::shortenSymbol(TQString s)
|
||
15 years ago
|
{
|
||
|
if ((int)s.length() > maxSymbolLength())
|
||
|
s = s.left(maxSymbolLength()) + "...";
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
int Configuration::maxListCount()
|
||
|
{
|
||
|
return config()->_maxListCount;
|
||
|
}
|
||
|
|
||
|
int Configuration::maxSymbolCount()
|
||
|
{
|
||
|
return config()->_maxSymbolCount;
|
||
|
}
|
||
|
|
||
|
int Configuration::context()
|
||
|
{
|
||
|
return config()->_context;
|
||
|
}
|
||
|
|
||
|
int Configuration::noCostInside()
|
||
|
{
|
||
|
return config()->_noCostInside;
|
||
|
}
|