summaryrefslogtreecommitdiffstats
path: root/tdecachegrind/tdecachegrind/fixcost.cpp
blob: 1379d9e2de7cf274b64b36f0c4f0b6d784012834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * Part of KCacheGrind
 *
 * 2003, Josef Weidendorfer
 */

#include "fixcost.h"
#include "utils.h"


// FixCost

FixCost::FixCost(TracePart* part, FixPool* pool,
		 TraceFunctionSource* functionSource,
		 PositionSpec& pos,
                 TracePartFunction* partFunction,
		 FixString& s)
{
    int maxCount = part->fixSubMapping()->count();

    _part = part;
    _functionSource = functionSource;
    _pos = pos;

    _cost = (SubCost*) pool->reserve(sizeof(SubCost) * maxCount);
    s.stripSpaces();
    int i = 0;
    while(i<maxCount) {
	if (!s.stripUInt64(_cost[i])) break;
	i++;
    }
    _count = i;

    if (!pool->allocateReserved(sizeof(SubCost) * _count))
	_count = 0;

    _nextCostOfPartFunction = partFunction ?
	partFunction->setFirstFixCost(this) : 0;
}

void* FixCost::operator new(size_t size, FixPool* pool)
{
    return pool->allocate(size);
}

void FixCost::addTo(TraceCost* c)
{
    TraceSubMapping* sm = _part->fixSubMapping();

    int i, realIndex;

    for(i=0; i<_count; i++) {
	realIndex = sm->realIndex(i);
	c->addCost(realIndex, _cost[i]);
    }
}



// FixCallCost

FixCallCost::FixCallCost(TracePart* part, FixPool* pool,
			 TraceFunctionSource* functionSource,
                         unsigned int line, Addr addr,
                         TracePartCall* partCall,
                         SubCost callCount, FixString& s)
{
  if (0) tqDebug("Got FixCallCost (addr 0x%s, line %d): calls %s",
                addr.toString().ascii(), line,
		callCount.pretty().ascii());

  int maxCount = part->fixSubMapping()->count();

    _part = part;
    _functionSource = functionSource;
    _line = line;
    _addr = addr;

    _cost = (SubCost*) pool->reserve(sizeof(SubCost) * (maxCount+1));
    s.stripSpaces();
    int i = 0;
    while(i<maxCount) {
	if (!s.stripUInt64(_cost[i])) break;
	i++;
    }
    _count = i;

    if (!pool->allocateReserved(sizeof(SubCost) * (_count+1) ))
      _count = 0;
    else
      _cost[_count] = callCount;

    _nextCostOfPartCall = partCall ? partCall->setFirstFixCallCost(this) : 0;
}

void* FixCallCost::operator new(size_t size, FixPool* pool)
{
    return pool->allocate(size);
}

void FixCallCost::addTo(TraceCallCost* c)
{
    TraceSubMapping* sm = _part->fixSubMapping();

    int i, realIndex;

    for(i=0; i<_count; i++) {
	realIndex = sm->realIndex(i);
	c->addCost(realIndex, _cost[i]);
    }
    c->addCallCount(_cost[_count]);

    if (0) tqDebug("Adding from (addr 0x%s, ln %d): calls %s",
                  _addr.toString().ascii(), _line,
		  _cost[_count].pretty().ascii());
}

void FixCallCost::setMax(TraceCost* c)
{
    TraceSubMapping* sm = _part->fixSubMapping();

    int i, realIndex;

    for(i=0; i<_count; i++) {
	realIndex = sm->realIndex(i);
	c->maxCost(realIndex, _cost[i]);
    }
}


// FixJump

FixJump::FixJump(TracePart* part, FixPool* pool,
		 unsigned int line, Addr addr,
		 TracePartFunction* partFunction,
		 TraceFunctionSource* source,
		 unsigned int targetLine, Addr targetAddr,
		 TraceFunction* targetFunction,
		 TraceFunctionSource* targetSource,
		 bool isCondJump,
		 SubCost executed, SubCost followed)
{
    _part   = part;
    _source = source;
    _line   = line;
    _addr   = addr;

    _targetFunction = targetFunction;
    _targetSource   = targetSource;
    _targetLine     = targetLine;
    _targetAddr     = targetAddr;
    
    _isCondJump = isCondJump;

    int size = (isCondJump ? 2 : 1) * sizeof(SubCost);
    _cost = (SubCost*) pool->allocate(size);
    _cost[0] = executed;
    if (isCondJump) _cost[1] = followed;

    _nextJumpOfPartFunction = partFunction ?
	partFunction->setFirstFixJump(this) : 0;
}

void* FixJump::operator new(size_t size, FixPool* pool)
{
    return pool->allocate(size);
}

void FixJump::addTo(TraceJumpCost* jc)
{
    jc->addExecutedCount(_cost[0]);
    if (_isCondJump) 
	jc->addFollowedCount(_cost[1]);
}