77 if (_parsed)
return true;
80 qDebug(
"TraceEventType::parseFormula: Recursion detected.");
85 qDebug(
"TraceEventType::parseFormula: Container of this event type unknown!");
95 QRegExp rx(
"((?:\\+|\\-)?)\\s*(\\d*)\\s*\\*?\\s*(\\w+)" );
97 int factor, pos, found, matching;
105 pos = rx.
indexIn(_formula, pos);
114 costName = rx.
cap(3);
115 eventType = _set->
type(costName);
123 if (rx.
cap(1) ==
"-") factor = -factor;
124 if (factor == 0)
continue;
128 if (!_parsedFormula.
isEmpty()) {
129 _parsedFormula +=
QString(
" %1 ").
arg((factor>0) ?
'+':
'-');
132 _parsedFormula +=
"- ";
133 if ((factor!=-1) && (factor!=1))
135 _parsedFormula += costName;
138 _coefficient[eventType->
realIndex()] += factor;
142 _coefficient[i] += factor * eventType->_coefficient[i];
166 return _parsedFormula;
176 int c = _coefficient[i];
177 if (c == 0)
continue;
181 if (c>0) res +=
"+ ";
183 if (c<0) { res +=
"- "; c = -c; }
207 for (
int i = 0;i<rc;i++)
208 if (_coefficient[i] != 0)
209 res += _coefficient[i] * c->
subCost(i);
216 if (total == 0.0)
return 0;
223 for (
int i = 0;i<rc;i++) {
224 if (_coefficient[i] != 0)
225 hist[i] = _coefficient[i] * c->
subCost(i) / total;
238 if (!_knownTypes)
return 0;
251 if (!_knownTypes)
return 0;
275 if (overwriteExisting) {
293 if (!_knownTypes)
return 0;
295 return _knownTypes->
count();
300 if (!_knownTypes)
return false;
314 if (!_knownTypes)
return 0;
315 if (i<0 || i>=(
int)_knownTypes->
count())
return 0;
317 return _knownTypes->
at(i);
335 if (_real[i])
delete _real[i];
338 if (_derived[i])
delete _derived[i];
345 int pos = 0, pos2, len = types.
length();
349 while((pos<len) && types[pos].isSpace()) pos++;
352 while((pos2<len) && !types[pos2].isSpace()) pos2++;
353 if (pos2 == pos)
break;
362 qDebug() <<
"EventTypeSet::createMapping: No space for "
363 << newCount <<
" cost entries.";
364 qDebug() <<
"Increase MaxRealIndexValue in libcore/costitem.h and recompile.";
373 while((pos<len) && types[pos].isSpace()) pos++;
376 while((pos2<len) && !types[pos2].isSpace()) pos2++;
377 if (pos2 == pos)
break;
390 if (index>=0)
return index;
411 qDebug(
"WARNING: Maximum for real event types reached (on adding '%s')",
412 qPrintable(et->
name()));
415 _real[_realCount] = et;
423 qDebug(
"WARNING: Maximum for virtual event types reached (on adding '%s')",
424 qPrintable(et->
name()));
427 _derived[_derivedCount] = et;
429 return _derivedCount-1;
435 if (!t)
return false;
436 if (t->
set() !=
this)
return false;
439 if (t->
isReal())
return false;
442 for(i=0;i<_derivedCount;i++)
443 if (_derived[i] == t)
break;
446 if (i == _derivedCount)
return false;
454 if (i+1 == _derivedCount) {
464 if (t<0 || t>=_realCount)
return 0;
470 if (t<0 || t>=_derivedCount)
return 0;
478 if (t<_realCount)
return _real[t];
482 if (t<_derivedCount)
return _derived[t];
489 for (
int i=0;i<_realCount;i++)
490 if (_real[i] && (_real[i]->name() == name))
493 for (
int i=0;i<_derivedCount;i++)
494 if (_derived[i] && (_derived[i]->name() == name))
502 for (
int i=0;i<_realCount;i++)
503 if (_real[i] && (_real[i]->longName() == name))
506 for (
int i=0;i<_derivedCount;i++)
507 if (_derived[i] && (_derived[i]->longName() == name))
516 for (
int i=0;i<_realCount;i++)
517 if (_real[i] && (_real[i]->name() == name))
525 for (
int i=0;i<_realCount;i++)
526 if (_real[i] && (_real[i]->name() == name))
529 for (
int i=0;i<_derivedCount;i++)
530 if (_derived[i] && (_derived[i]->name() == name))
544 for (i=0; i<knownCount; i++) {
546 if (t->
isReal())
continue;
555 if (addDiff == 0)
break;
578 _nextUnused[i] = i+1;
584 if (count > _count) count = _count;
585 if (_isIdentity)
return count-1;
588 for(
int j=0; j<
count; j++)
589 if (maxIndex < _realIndex[j])
590 maxIndex = _realIndex[j];
596 if (!_set)
return false;
604 if (!_set)
return false;
605 if ((type<0) || (type >= _set->
realCount()))
return false;
609 _realIndex[_count] = type;
611 if (_isIdentity && (_count != type)) _isIdentity =
false;
612 if (type == _firstUnused)
613 _firstUnused = _nextUnused[type];
614 for(
int i=0;i<type;i++)
615 if (_nextUnused[i] == type)
616 _nextUnused[i]=_nextUnused[type];
QString cap(int nth) const
SubCost subCost(EventType *)
Returns a sub cost.
EventType(const QString &name, const QString &longName=QString(), const QString &formula=QString())
is a short (non-localized) identifier for the cost type, e.g.
void setEventTypeSet(EventTypeSet *m)
static const int MaxRealIndex
const T & at(int i) const
void setFormula(const QString &)
static const int InvalidIndex
int addKnownDerivedTypes()
Adds all known derived event types that can be parsed.
A index list into a EventTypeSet.
static EventType * knownDerivedType(const QString &)
EventType * typeForLong(const QString &)
static EventType * knownRealType(const QString &)
int matchedLength() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
An array of basic cost metrics for a trace item.
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
EventTypeMapping(EventTypeSet *)
QString parsedRealFormula()
int toInt(bool *ok, int base) const
static int knownTypeCount()
int removeAll(const T &value)
const QString & formula()
int maxRealIndex(int count)
Get maximal real index for the first mapping indexes.
static bool remove(const QString &)
int addReal(const QString &)
SubCost subCost(ProfileCostArray *)
EventTypeMapping * createMapping(const QString &types)
Defines a mapping from indexes into a list of costs to real event types If is false...
int realIndex(const QString &)
EventType * realType(int)
QString mid(int position, int n) const
static EventType * knownType(int)
int index(const QString &)
static void add(EventType *, bool overwriteExisting=true)
Cost event counter, simple wrapper around a 64bit entity.
const QString & longName()
A class for managing a set of event types.
void setRealIndex(int r=ProfileCostArray::MaxRealIndex)
void setLongName(const QString &n)
EventType * derivedType(int)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool append(const QString &, bool create=true)
int histCost(ProfileCostArray *c, double total, double *hist)
int count()
Get number of used indexes.