Profiler.cc (6897:cfeb3d9563dd) Profiler.cc (7002:48a19d52d939)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 This file has been modified by Kevin Moore and Dan Nussbaum of the
31 Scalable Systems Research Group at Sun Microsystems Laboratories
32 (http://research.sun.com/scalable/) to support the Adaptive
33 Transactional Memory Test Platform (ATMTP).
34
35 Please send email to atmtp-interest@sun.com with feedback, questions, or
36 to request future announcements about ATMTP.
37
38 ----------------------------------------------------------------------
39
40 File modification date: 2008-02-23
41
42 ----------------------------------------------------------------------
43*/
44
45/*
46 * Profiler.cc
47 *
48 * Description: See Profiler.hh
49 *
50 * $Id$
51 *
52 */
53
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 This file has been modified by Kevin Moore and Dan Nussbaum of the
31 Scalable Systems Research Group at Sun Microsystems Laboratories
32 (http://research.sun.com/scalable/) to support the Adaptive
33 Transactional Memory Test Platform (ATMTP).
34
35 Please send email to atmtp-interest@sun.com with feedback, questions, or
36 to request future announcements about ATMTP.
37
38 ----------------------------------------------------------------------
39
40 File modification date: 2008-02-23
41
42 ----------------------------------------------------------------------
43*/
44
45/*
46 * Profiler.cc
47 *
48 * Description: See Profiler.hh
49 *
50 * $Id$
51 *
52 */
53
54// Allows use of times() library call, which determines virtual runtime
55#include <sys/resource.h>
56#include <sys/times.h>
57
54#include "mem/ruby/profiler/Profiler.hh"
55#include "mem/ruby/profiler/AddressProfiler.hh"
56#include "mem/ruby/system/System.hh"
57#include "mem/ruby/network/Network.hh"
58#include "mem/gems_common/PrioHeap.hh"
59#include "mem/protocol/CacheMsg.hh"
60#include "mem/protocol/Protocol.hh"
61#include "mem/gems_common/util.hh"
62#include "mem/gems_common/Map.hh"
63#include "mem/ruby/common/Debug.hh"
64#include "mem/protocol/MachineType.hh"
65
66#include "mem/ruby/system/System.hh"
67
58#include "mem/ruby/profiler/Profiler.hh"
59#include "mem/ruby/profiler/AddressProfiler.hh"
60#include "mem/ruby/system/System.hh"
61#include "mem/ruby/network/Network.hh"
62#include "mem/gems_common/PrioHeap.hh"
63#include "mem/protocol/CacheMsg.hh"
64#include "mem/protocol/Protocol.hh"
65#include "mem/gems_common/util.hh"
66#include "mem/gems_common/Map.hh"
67#include "mem/ruby/common/Debug.hh"
68#include "mem/protocol/MachineType.hh"
69
70#include "mem/ruby/system/System.hh"
71
68// Allows use of times() library call, which determines virtual runtime
69#include <sys/times.h>
70
71extern std::ostream * debug_cout_ptr;
72
73static double process_memory_total();
74static double process_memory_resident();
75
76Profiler::Profiler(const Params *p)
77 : SimObject(p)
78{
79 m_requestProfileMap_ptr = new Map<string, int>;
80
81 m_inst_profiler_ptr = NULL;
82 m_address_profiler_ptr = NULL;
83
84 m_real_time_start_time = time(NULL); // Not reset in clearStats()
85 m_stats_period = 1000000; // Default
86 m_periodic_output_file_ptr = &cerr;
87
88 m_hot_lines = p->hot_lines;
89 m_all_instructions = p->all_instructions;
90
91 m_num_of_sequencers = p->num_of_sequencers;
92
93 m_hot_lines = false;
94 m_all_instructions = false;
95
96 m_address_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
97 m_address_profiler_ptr -> setHotLines(m_hot_lines);
98 m_address_profiler_ptr -> setAllInstructions(m_all_instructions);
99
100 if (m_all_instructions) {
101 m_inst_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
102 m_inst_profiler_ptr -> setHotLines(m_hot_lines);
103 m_inst_profiler_ptr -> setAllInstructions(m_all_instructions);
104 }
105}
106
107Profiler::~Profiler()
108{
109 if (m_periodic_output_file_ptr != &cerr) {
110 delete m_periodic_output_file_ptr;
111 }
112
113 delete m_requestProfileMap_ptr;
114}
115
116void Profiler::wakeup()
117{
118 // FIXME - avoid the repeated code
119
120 Vector<integer_t> perProcCycleCount;
121 perProcCycleCount.setSize(m_num_of_sequencers);
122
123 for(int i=0; i < m_num_of_sequencers; i++) {
124 perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
125 // The +1 allows us to avoid division by zero
126 }
127
128 integer_t total_misses = m_perProcTotalMisses.sum();
129 integer_t simics_cycles_executed = perProcCycleCount.sum();
130 integer_t transactions_started = m_perProcStartTransaction.sum();
131 integer_t transactions_ended = m_perProcEndTransaction.sum();
132
133 (*m_periodic_output_file_ptr) << "ruby_cycles: "
134 << g_eventQueue_ptr->getTime()-m_ruby_start
135 << endl;
136
137 (*m_periodic_output_file_ptr) << "total_misses: "
138 << total_misses
139 << " "
140 << m_perProcTotalMisses
141 << endl;
142
143 (*m_periodic_output_file_ptr) << "simics_cycles_executed: "
144 << simics_cycles_executed
145 << " "
146 << perProcCycleCount
147 << endl;
148
149 (*m_periodic_output_file_ptr) << "transactions_started: "
150 << transactions_started
151 << " "
152 << m_perProcStartTransaction
153 << endl;
154
155 (*m_periodic_output_file_ptr) << "transactions_ended: "
156 << transactions_ended
157 << " "
158 << m_perProcEndTransaction
159 << endl;
160
161 (*m_periodic_output_file_ptr) << "mbytes_resident: "
162 << process_memory_resident()
163 << endl;
164
165 (*m_periodic_output_file_ptr) << "mbytes_total: "
166 << process_memory_total()
167 << endl;
168
169 if (process_memory_total() > 0) {
170 (*m_periodic_output_file_ptr) << "resident_ratio: "
171 << process_memory_resident()/process_memory_total()
172 << endl;
173 }
174
175 (*m_periodic_output_file_ptr) << "miss_latency: "
176 << m_allMissLatencyHistogram
177 << endl;
178
179 *m_periodic_output_file_ptr << endl;
180
181 if (m_all_instructions) {
182 m_inst_profiler_ptr->printStats(*m_periodic_output_file_ptr);
183 }
184
185 //g_system_ptr->getNetwork()->printStats(*m_periodic_output_file_ptr);
186 g_eventQueue_ptr->scheduleEvent(this, m_stats_period);
187}
188
189void Profiler::setPeriodicStatsFile(const string& filename)
190{
191 cout << "Recording periodic statistics to file '" << filename << "' every "
192 << m_stats_period << " Ruby cycles" << endl;
193
194 if (m_periodic_output_file_ptr != &cerr) {
195 delete m_periodic_output_file_ptr;
196 }
197
198 m_periodic_output_file_ptr = new ofstream(filename.c_str());
199 g_eventQueue_ptr->scheduleEvent(this, 1);
200}
201
202void Profiler::setPeriodicStatsInterval(integer_t period)
203{
204 cout << "Recording periodic statistics every " << m_stats_period
205 << " Ruby cycles" << endl;
206
207 m_stats_period = period;
208 g_eventQueue_ptr->scheduleEvent(this, 1);
209}
210
211void Profiler::printConfig(ostream& out) const
212{
213 out << endl;
214 out << "Profiler Configuration" << endl;
215 out << "----------------------" << endl;
216 out << "periodic_stats_period: " << m_stats_period << endl;
217}
218
219void Profiler::print(ostream& out) const
220{
221 out << "[Profiler]";
222}
223
224void Profiler::printStats(ostream& out, bool short_stats)
225{
226 out << endl;
227 if (short_stats) {
228 out << "SHORT ";
229 }
230 out << "Profiler Stats" << endl;
231 out << "--------------" << endl;
232
233 time_t real_time_current = time(NULL);
234 double seconds = difftime(real_time_current, m_real_time_start_time);
235 double minutes = seconds/60.0;
236 double hours = minutes/60.0;
237 double days = hours/24.0;
238 Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start;
239
240 if (!short_stats) {
241 out << "Elapsed_time_in_seconds: " << seconds << endl;
242 out << "Elapsed_time_in_minutes: " << minutes << endl;
243 out << "Elapsed_time_in_hours: " << hours << endl;
244 out << "Elapsed_time_in_days: " << days << endl;
245 out << endl;
246 }
247
248 // print the virtual runtimes as well
249 struct tms vtime;
250 times(&vtime);
251 seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0;
252 minutes = seconds / 60.0;
253 hours = minutes / 60.0;
254 days = hours / 24.0;
255 out << "Virtual_time_in_seconds: " << seconds << endl;
256 out << "Virtual_time_in_minutes: " << minutes << endl;
257 out << "Virtual_time_in_hours: " << hours << endl;
258 out << "Virtual_time_in_days: " << days << endl;
259 out << endl;
260
261 out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl;
262 out << "Ruby_start_time: " << m_ruby_start << endl;
263 out << "Ruby_cycles: " << ruby_cycles << endl;
264 out << endl;
265
266 if (!short_stats) {
267 out << "mbytes_resident: " << process_memory_resident() << endl;
268 out << "mbytes_total: " << process_memory_total() << endl;
269 if (process_memory_total() > 0) {
270 out << "resident_ratio: "
271 << process_memory_resident()/process_memory_total() << endl;
272 }
273 out << endl;
274
275 }
276
277 Vector<integer_t> perProcCycleCount;
278 Vector<double> perProcCyclesPerTrans;
279 Vector<double> perProcMissesPerTrans;
280
281
282 perProcCycleCount.setSize(m_num_of_sequencers);
283 perProcCyclesPerTrans.setSize(m_num_of_sequencers);
284 perProcMissesPerTrans.setSize(m_num_of_sequencers);
285
286 for(int i=0; i < m_num_of_sequencers; i++) {
287 perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
288 // The +1 allows us to avoid division by zero
289
290 int trans = m_perProcEndTransaction[i];
291 if (trans == 0) {
292 perProcCyclesPerTrans[i] = 0;
293 perProcMissesPerTrans[i] = 0;
294 } else {
295 perProcCyclesPerTrans[i] = ruby_cycles / double(trans);
296 perProcMissesPerTrans[i] = m_perProcTotalMisses[i] / double(trans);
297 }
298 }
299
300 integer_t total_misses = m_perProcTotalMisses.sum();
301 integer_t user_misses = m_perProcUserMisses.sum();
302 integer_t supervisor_misses = m_perProcSupervisorMisses.sum();
303 integer_t simics_cycles_executed = perProcCycleCount.sum();
304 integer_t transactions_started = m_perProcStartTransaction.sum();
305 integer_t transactions_ended = m_perProcEndTransaction.sum();
306
307 double cycles_per_transaction = (transactions_ended != 0) ? (m_num_of_sequencers * double(ruby_cycles)) / double(transactions_ended) : 0;
308 double misses_per_transaction = (transactions_ended != 0) ? double(total_misses) / double(transactions_ended) : 0;
309
310 out << "Total_misses: " << total_misses << endl;
311 out << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
312 out << "user_misses: " << user_misses << " " << m_perProcUserMisses << endl;
313 out << "supervisor_misses: " << supervisor_misses << " " << m_perProcSupervisorMisses << endl;
314 out << endl;
315 out << "ruby_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
316 out << endl;
317 out << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
318 out << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
319 out << "cycles_per_transaction: " << cycles_per_transaction << " " << perProcCyclesPerTrans << endl;
320 out << "misses_per_transaction: " << misses_per_transaction << " " << perProcMissesPerTrans << endl;
321
322 out << endl;
323
324 out << endl;
325
326 if (!short_stats) {
327 out << "Busy Controller Counts:" << endl;
328 for(int i=0; i < MachineType_NUM; i++) {
329 for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
330 MachineID machID;
331 machID.type = (MachineType)i;
332 machID.num = j;
333 out << machID << ":" << m_busyControllerCount[i][j] << " ";
334 if ((j+1)%8 == 0) {
335 out << endl;
336 }
337 }
338 out << endl;
339 }
340 out << endl;
341
342 out << "Busy Bank Count:" << m_busyBankCount << endl;
343 out << endl;
344
345 out << "sequencer_requests_outstanding: " << m_sequencer_requests << endl;
346 out << endl;
347 }
348
349 if (!short_stats) {
350 out << "All Non-Zero Cycle Demand Cache Accesses" << endl;
351 out << "----------------------------------------" << endl;
352 out << "miss_latency: " << m_allMissLatencyHistogram << endl;
353 for(int i=0; i<m_missLatencyHistograms.size(); i++) {
354 if (m_missLatencyHistograms[i].size() > 0) {
355 out << "miss_latency_" << RubyRequestType(i) << ": " << m_missLatencyHistograms[i] << endl;
356 }
357 }
358 for(int i=0; i<m_machLatencyHistograms.size(); i++) {
359 if (m_machLatencyHistograms[i].size() > 0) {
360 out << "miss_latency_" << GenericMachineType(i) << ": " << m_machLatencyHistograms[i] << endl;
361 }
362 }
363
364 out << endl;
365
366 out << "All Non-Zero Cycle SW Prefetch Requests" << endl;
367 out << "------------------------------------" << endl;
368 out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl;
369 for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
370 if (m_SWPrefetchLatencyHistograms[i].size() > 0) {
371 out << "prefetch_latency_" << CacheRequestType(i) << ": " << m_SWPrefetchLatencyHistograms[i] << endl;
372 }
373 }
374 for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
375 if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) {
376 out << "prefetch_latency_" << GenericMachineType(i) << ": " << m_SWPrefetchMachLatencyHistograms[i] << endl;
377 }
378 }
379 out << "prefetch_latency_L2Miss:" << m_SWPrefetchL2MissLatencyHistogram << endl;
380
381 if (m_all_sharing_histogram.size() > 0) {
382 out << "all_sharing: " << m_all_sharing_histogram << endl;
383 out << "read_sharing: " << m_read_sharing_histogram << endl;
384 out << "write_sharing: " << m_write_sharing_histogram << endl;
385
386 out << "all_sharing_percent: "; m_all_sharing_histogram.printPercent(out); out << endl;
387 out << "read_sharing_percent: "; m_read_sharing_histogram.printPercent(out); out << endl;
388 out << "write_sharing_percent: "; m_write_sharing_histogram.printPercent(out); out << endl;
389
390 int64 total_miss = m_cache_to_cache + m_memory_to_cache;
391 out << "all_misses: " << total_miss << endl;
392 out << "cache_to_cache_misses: " << m_cache_to_cache << endl;
393 out << "memory_to_cache_misses: " << m_memory_to_cache << endl;
394 out << "cache_to_cache_percent: " << 100.0 * (double(m_cache_to_cache) / double(total_miss)) << endl;
395 out << "memory_to_cache_percent: " << 100.0 * (double(m_memory_to_cache) / double(total_miss)) << endl;
396 out << endl;
397 }
398
399 if (m_outstanding_requests.size() > 0) {
400 out << "outstanding_requests: "; m_outstanding_requests.printPercent(out); out << endl;
401 out << endl;
402 }
403 }
404
405 if (!short_stats) {
406 out << "Request vs. RubySystem State Profile" << endl;
407 out << "--------------------------------" << endl;
408 out << endl;
409
410 Vector<string> requestProfileKeys = m_requestProfileMap_ptr->keys();
411 requestProfileKeys.sortVector();
412
413 for(int i=0; i<requestProfileKeys.size(); i++) {
414 int temp_int = m_requestProfileMap_ptr->lookup(requestProfileKeys[i]);
415 double percent = (100.0*double(temp_int))/double(m_requests);
416 while (requestProfileKeys[i] != "") {
417 out << setw(10) << string_split(requestProfileKeys[i], ':');
418 }
419 out << setw(11) << temp_int;
420 out << setw(14) << percent << endl;
421 }
422 out << endl;
423
424 out << "filter_action: " << m_filter_action_histogram << endl;
425
426 if (!m_all_instructions) {
427 m_address_profiler_ptr->printStats(out);
428 }
429
430 if (m_all_instructions) {
431 m_inst_profiler_ptr->printStats(out);
432 }
433
434 out << endl;
435 out << "Message Delayed Cycles" << endl;
436 out << "----------------------" << endl;
437 out << "Total_delay_cycles: " << m_delayedCyclesHistogram << endl;
438 out << "Total_nonPF_delay_cycles: " << m_delayedCyclesNonPFHistogram << endl;
439 for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) {
440 out << " virtual_network_" << i << "_delay_cycles: " << m_delayedCyclesVCHistograms[i] << endl;
441 }
442
443 printResourceUsage(out);
444 }
445
446}
447
448void Profiler::printResourceUsage(ostream& out) const
449{
450 out << endl;
451 out << "Resource Usage" << endl;
452 out << "--------------" << endl;
453
454 integer_t pagesize = getpagesize(); // page size in bytes
455 out << "page_size: " << pagesize << endl;
456
457 rusage usage;
458 getrusage (RUSAGE_SELF, &usage);
459
460 out << "user_time: " << usage.ru_utime.tv_sec << endl;
461 out << "system_time: " << usage.ru_stime.tv_sec << endl;
462 out << "page_reclaims: " << usage.ru_minflt << endl;
463 out << "page_faults: " << usage.ru_majflt << endl;
464 out << "swaps: " << usage.ru_nswap << endl;
465 out << "block_inputs: " << usage.ru_inblock << endl;
466 out << "block_outputs: " << usage.ru_oublock << endl;
467}
468
469void Profiler::clearStats()
470{
471 m_ruby_start = g_eventQueue_ptr->getTime();
472
473 m_cycles_executed_at_start.setSize(m_num_of_sequencers);
474 for (int i=0; i < m_num_of_sequencers; i++) {
475 if (g_system_ptr == NULL) {
476 m_cycles_executed_at_start[i] = 0;
477 } else {
478 m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i);
479 }
480 }
481
482 m_perProcTotalMisses.setSize(m_num_of_sequencers);
483 m_perProcUserMisses.setSize(m_num_of_sequencers);
484 m_perProcSupervisorMisses.setSize(m_num_of_sequencers);
485 m_perProcStartTransaction.setSize(m_num_of_sequencers);
486 m_perProcEndTransaction.setSize(m_num_of_sequencers);
487
488 for(int i=0; i < m_num_of_sequencers; i++) {
489 m_perProcTotalMisses[i] = 0;
490 m_perProcUserMisses[i] = 0;
491 m_perProcSupervisorMisses[i] = 0;
492 m_perProcStartTransaction[i] = 0;
493 m_perProcEndTransaction[i] = 0;
494 }
495
496 m_busyControllerCount.setSize(MachineType_NUM); // all machines
497 for(int i=0; i < MachineType_NUM; i++) {
498 m_busyControllerCount[i].setSize(MachineType_base_count((MachineType)i));
499 for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
500 m_busyControllerCount[i][j] = 0;
501 }
502 }
503 m_busyBankCount = 0;
504
505 m_delayedCyclesHistogram.clear();
506 m_delayedCyclesNonPFHistogram.clear();
507 m_delayedCyclesVCHistograms.setSize(RubySystem::getNetwork()->getNumberOfVirtualNetworks());
508 for (int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++) {
509 m_delayedCyclesVCHistograms[i].clear();
510 }
511
512 m_missLatencyHistograms.setSize(RubyRequestType_NUM);
513 for(int i=0; i<m_missLatencyHistograms.size(); i++) {
514 m_missLatencyHistograms[i].clear(200);
515 }
516 m_machLatencyHistograms.setSize(GenericMachineType_NUM+1);
517 for(int i=0; i<m_machLatencyHistograms.size(); i++) {
518 m_machLatencyHistograms[i].clear(200);
519 }
520 m_allMissLatencyHistogram.clear(200);
521
522 m_SWPrefetchLatencyHistograms.setSize(CacheRequestType_NUM);
523 for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
524 m_SWPrefetchLatencyHistograms[i].clear(200);
525 }
526 m_SWPrefetchMachLatencyHistograms.setSize(GenericMachineType_NUM+1);
527 for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
528 m_SWPrefetchMachLatencyHistograms[i].clear(200);
529 }
530 m_allSWPrefetchLatencyHistogram.clear(200);
531
532 m_sequencer_requests.clear();
533 m_read_sharing_histogram.clear();
534 m_write_sharing_histogram.clear();
535 m_all_sharing_histogram.clear();
536 m_cache_to_cache = 0;
537 m_memory_to_cache = 0;
538
539 // clear HashMaps
540 m_requestProfileMap_ptr->clear();
541
542 // count requests profiled
543 m_requests = 0;
544
545 m_outstanding_requests.clear();
546 m_outstanding_persistent_requests.clear();
547
548 // Flush the prefetches through the system - used so that there are no outstanding requests after stats are cleared
549 //g_eventQueue_ptr->triggerAllEvents();
550
551 // update the start time
552 m_ruby_start = g_eventQueue_ptr->getTime();
553}
554
555void Profiler::addAddressTraceSample(const CacheMsg& msg, NodeID id)
556{
557 if (msg.getType() != CacheRequestType_IFETCH) {
558
559 // Note: The following line should be commented out if you want to
560 // use the special profiling that is part of the GS320 protocol
561
562 // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be profiled by the AddressProfiler
563 m_address_profiler_ptr->addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), msg.getType(), msg.getAccessMode(), id, false);
564 }
565}
566
567void Profiler::profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner)
568{
569 Set set_contacted(owner);
570 if (type == AccessType_Write) {
571 set_contacted.addSet(sharers);
572 }
573 set_contacted.remove(requestor);
574 int number_contacted = set_contacted.count();
575
576 if (type == AccessType_Write) {
577 m_write_sharing_histogram.add(number_contacted);
578 } else {
579 m_read_sharing_histogram.add(number_contacted);
580 }
581 m_all_sharing_histogram.add(number_contacted);
582
583 if (number_contacted == 0) {
584 m_memory_to_cache++;
585 } else {
586 m_cache_to_cache++;
587 }
588
589}
590
591void Profiler::profileMsgDelay(int virtualNetwork, int delayCycles) {
592 assert(virtualNetwork < m_delayedCyclesVCHistograms.size());
593 m_delayedCyclesHistogram.add(delayCycles);
594 m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles);
595 if (virtualNetwork != 0) {
596 m_delayedCyclesNonPFHistogram.add(delayCycles);
597 }
598}
599
600// profiles original cache requests including PUTs
601void Profiler::profileRequest(const string& requestStr)
602{
603 m_requests++;
604
605 if (m_requestProfileMap_ptr->exist(requestStr)) {
606 (m_requestProfileMap_ptr->lookup(requestStr))++;
607 } else {
608 m_requestProfileMap_ptr->add(requestStr, 1);
609 }
610}
611
612void Profiler::startTransaction(int cpu)
613{
614 m_perProcStartTransaction[cpu]++;
615}
616
617void Profiler::endTransaction(int cpu)
618{
619 m_perProcEndTransaction[cpu]++;
620}
621
622void Profiler::controllerBusy(MachineID machID)
623{
624 m_busyControllerCount[(int)machID.type][(int)machID.num]++;
625}
626
627void Profiler::profilePFWait(Time waitTime)
628{
629 m_prefetchWaitHistogram.add(waitTime);
630}
631
632void Profiler::bankBusy()
633{
634 m_busyBankCount++;
635}
636
637// non-zero cycle demand request
638void Profiler::missLatency(Time t, RubyRequestType type)
639{
640 m_allMissLatencyHistogram.add(t);
641 m_missLatencyHistograms[type].add(t);
642}
643
644// non-zero cycle prefetch request
645void Profiler::swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach)
646{
647 m_allSWPrefetchLatencyHistogram.add(t);
648 m_SWPrefetchLatencyHistograms[type].add(t);
649 m_SWPrefetchMachLatencyHistograms[respondingMach].add(t);
650 if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) {
651 m_SWPrefetchL2MissLatencyHistogram.add(t);
652 }
653}
654
655void Profiler::profileTransition(const string& component, NodeID version, Address addr,
656 const string& state, const string& event,
657 const string& next_state, const string& note)
658{
659 const int EVENT_SPACES = 20;
660 const int ID_SPACES = 3;
661 const int TIME_SPACES = 7;
662 const int COMP_SPACES = 10;
663 const int STATE_SPACES = 6;
664
665 if ((g_debug_ptr->getDebugTime() > 0) &&
666 (g_eventQueue_ptr->getTime() >= g_debug_ptr->getDebugTime())) {
667 (* debug_cout_ptr).flags(ios::right);
668 (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
669 (* debug_cout_ptr) << setw(ID_SPACES) << version << " ";
670 (* debug_cout_ptr) << setw(COMP_SPACES) << component;
671 (* debug_cout_ptr) << setw(EVENT_SPACES) << event << " ";
672
673 (* debug_cout_ptr).flags(ios::right);
674 (* debug_cout_ptr) << setw(STATE_SPACES) << state;
675 (* debug_cout_ptr) << ">";
676 (* debug_cout_ptr).flags(ios::left);
677 (* debug_cout_ptr) << setw(STATE_SPACES) << next_state;
678
679 (* debug_cout_ptr) << " " << addr << " " << note;
680
681 (* debug_cout_ptr) << endl;
682 }
683}
684
685// Helper function
686static double process_memory_total()
687{
688 const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
689 ifstream proc_file;
690 proc_file.open("/proc/self/statm");
691 int total_size_in_pages = 0;
692 int res_size_in_pages = 0;
693 proc_file >> total_size_in_pages;
694 proc_file >> res_size_in_pages;
695 return double(total_size_in_pages)*MULTIPLIER; // size in megabytes
696}
697
698static double process_memory_resident()
699{
700 const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
701 ifstream proc_file;
702 proc_file.open("/proc/self/statm");
703 int total_size_in_pages = 0;
704 int res_size_in_pages = 0;
705 proc_file >> total_size_in_pages;
706 proc_file >> res_size_in_pages;
707 return double(res_size_in_pages)*MULTIPLIER; // size in megabytes
708}
709
710void Profiler::rubyWatch(int id){
711 //int rn_g1 = 0;//SIMICS_get_register_number(id, "g1");
712 uint64 tr = 0;//SIMICS_read_register(id, rn_g1);
713 Address watch_address = Address(tr);
714 const int ID_SPACES = 3;
715 const int TIME_SPACES = 7;
716
717 (* debug_cout_ptr).flags(ios::right);
718 (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
719 (* debug_cout_ptr) << setw(ID_SPACES) << id << " "
720 << "RUBY WATCH "
721 << watch_address
722 << endl;
723
724 if(!m_watch_address_list_ptr->exist(watch_address)){
725 m_watch_address_list_ptr->add(watch_address, 1);
726 }
727}
728
729bool Profiler::watchAddress(Address addr){
730 if (m_watch_address_list_ptr->exist(addr))
731 return true;
732 else
733 return false;
734}
735
736int64 Profiler::getTotalTransactionsExecuted() const {
737 return m_perProcEndTransaction.sum();
738}
739
740
741Profiler *
742RubyProfilerParams::create()
743{
744 return new Profiler(this);
745}
72extern std::ostream * debug_cout_ptr;
73
74static double process_memory_total();
75static double process_memory_resident();
76
77Profiler::Profiler(const Params *p)
78 : SimObject(p)
79{
80 m_requestProfileMap_ptr = new Map<string, int>;
81
82 m_inst_profiler_ptr = NULL;
83 m_address_profiler_ptr = NULL;
84
85 m_real_time_start_time = time(NULL); // Not reset in clearStats()
86 m_stats_period = 1000000; // Default
87 m_periodic_output_file_ptr = &cerr;
88
89 m_hot_lines = p->hot_lines;
90 m_all_instructions = p->all_instructions;
91
92 m_num_of_sequencers = p->num_of_sequencers;
93
94 m_hot_lines = false;
95 m_all_instructions = false;
96
97 m_address_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
98 m_address_profiler_ptr -> setHotLines(m_hot_lines);
99 m_address_profiler_ptr -> setAllInstructions(m_all_instructions);
100
101 if (m_all_instructions) {
102 m_inst_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
103 m_inst_profiler_ptr -> setHotLines(m_hot_lines);
104 m_inst_profiler_ptr -> setAllInstructions(m_all_instructions);
105 }
106}
107
108Profiler::~Profiler()
109{
110 if (m_periodic_output_file_ptr != &cerr) {
111 delete m_periodic_output_file_ptr;
112 }
113
114 delete m_requestProfileMap_ptr;
115}
116
117void Profiler::wakeup()
118{
119 // FIXME - avoid the repeated code
120
121 Vector<integer_t> perProcCycleCount;
122 perProcCycleCount.setSize(m_num_of_sequencers);
123
124 for(int i=0; i < m_num_of_sequencers; i++) {
125 perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
126 // The +1 allows us to avoid division by zero
127 }
128
129 integer_t total_misses = m_perProcTotalMisses.sum();
130 integer_t simics_cycles_executed = perProcCycleCount.sum();
131 integer_t transactions_started = m_perProcStartTransaction.sum();
132 integer_t transactions_ended = m_perProcEndTransaction.sum();
133
134 (*m_periodic_output_file_ptr) << "ruby_cycles: "
135 << g_eventQueue_ptr->getTime()-m_ruby_start
136 << endl;
137
138 (*m_periodic_output_file_ptr) << "total_misses: "
139 << total_misses
140 << " "
141 << m_perProcTotalMisses
142 << endl;
143
144 (*m_periodic_output_file_ptr) << "simics_cycles_executed: "
145 << simics_cycles_executed
146 << " "
147 << perProcCycleCount
148 << endl;
149
150 (*m_periodic_output_file_ptr) << "transactions_started: "
151 << transactions_started
152 << " "
153 << m_perProcStartTransaction
154 << endl;
155
156 (*m_periodic_output_file_ptr) << "transactions_ended: "
157 << transactions_ended
158 << " "
159 << m_perProcEndTransaction
160 << endl;
161
162 (*m_periodic_output_file_ptr) << "mbytes_resident: "
163 << process_memory_resident()
164 << endl;
165
166 (*m_periodic_output_file_ptr) << "mbytes_total: "
167 << process_memory_total()
168 << endl;
169
170 if (process_memory_total() > 0) {
171 (*m_periodic_output_file_ptr) << "resident_ratio: "
172 << process_memory_resident()/process_memory_total()
173 << endl;
174 }
175
176 (*m_periodic_output_file_ptr) << "miss_latency: "
177 << m_allMissLatencyHistogram
178 << endl;
179
180 *m_periodic_output_file_ptr << endl;
181
182 if (m_all_instructions) {
183 m_inst_profiler_ptr->printStats(*m_periodic_output_file_ptr);
184 }
185
186 //g_system_ptr->getNetwork()->printStats(*m_periodic_output_file_ptr);
187 g_eventQueue_ptr->scheduleEvent(this, m_stats_period);
188}
189
190void Profiler::setPeriodicStatsFile(const string& filename)
191{
192 cout << "Recording periodic statistics to file '" << filename << "' every "
193 << m_stats_period << " Ruby cycles" << endl;
194
195 if (m_periodic_output_file_ptr != &cerr) {
196 delete m_periodic_output_file_ptr;
197 }
198
199 m_periodic_output_file_ptr = new ofstream(filename.c_str());
200 g_eventQueue_ptr->scheduleEvent(this, 1);
201}
202
203void Profiler::setPeriodicStatsInterval(integer_t period)
204{
205 cout << "Recording periodic statistics every " << m_stats_period
206 << " Ruby cycles" << endl;
207
208 m_stats_period = period;
209 g_eventQueue_ptr->scheduleEvent(this, 1);
210}
211
212void Profiler::printConfig(ostream& out) const
213{
214 out << endl;
215 out << "Profiler Configuration" << endl;
216 out << "----------------------" << endl;
217 out << "periodic_stats_period: " << m_stats_period << endl;
218}
219
220void Profiler::print(ostream& out) const
221{
222 out << "[Profiler]";
223}
224
225void Profiler::printStats(ostream& out, bool short_stats)
226{
227 out << endl;
228 if (short_stats) {
229 out << "SHORT ";
230 }
231 out << "Profiler Stats" << endl;
232 out << "--------------" << endl;
233
234 time_t real_time_current = time(NULL);
235 double seconds = difftime(real_time_current, m_real_time_start_time);
236 double minutes = seconds/60.0;
237 double hours = minutes/60.0;
238 double days = hours/24.0;
239 Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start;
240
241 if (!short_stats) {
242 out << "Elapsed_time_in_seconds: " << seconds << endl;
243 out << "Elapsed_time_in_minutes: " << minutes << endl;
244 out << "Elapsed_time_in_hours: " << hours << endl;
245 out << "Elapsed_time_in_days: " << days << endl;
246 out << endl;
247 }
248
249 // print the virtual runtimes as well
250 struct tms vtime;
251 times(&vtime);
252 seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0;
253 minutes = seconds / 60.0;
254 hours = minutes / 60.0;
255 days = hours / 24.0;
256 out << "Virtual_time_in_seconds: " << seconds << endl;
257 out << "Virtual_time_in_minutes: " << minutes << endl;
258 out << "Virtual_time_in_hours: " << hours << endl;
259 out << "Virtual_time_in_days: " << days << endl;
260 out << endl;
261
262 out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl;
263 out << "Ruby_start_time: " << m_ruby_start << endl;
264 out << "Ruby_cycles: " << ruby_cycles << endl;
265 out << endl;
266
267 if (!short_stats) {
268 out << "mbytes_resident: " << process_memory_resident() << endl;
269 out << "mbytes_total: " << process_memory_total() << endl;
270 if (process_memory_total() > 0) {
271 out << "resident_ratio: "
272 << process_memory_resident()/process_memory_total() << endl;
273 }
274 out << endl;
275
276 }
277
278 Vector<integer_t> perProcCycleCount;
279 Vector<double> perProcCyclesPerTrans;
280 Vector<double> perProcMissesPerTrans;
281
282
283 perProcCycleCount.setSize(m_num_of_sequencers);
284 perProcCyclesPerTrans.setSize(m_num_of_sequencers);
285 perProcMissesPerTrans.setSize(m_num_of_sequencers);
286
287 for(int i=0; i < m_num_of_sequencers; i++) {
288 perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
289 // The +1 allows us to avoid division by zero
290
291 int trans = m_perProcEndTransaction[i];
292 if (trans == 0) {
293 perProcCyclesPerTrans[i] = 0;
294 perProcMissesPerTrans[i] = 0;
295 } else {
296 perProcCyclesPerTrans[i] = ruby_cycles / double(trans);
297 perProcMissesPerTrans[i] = m_perProcTotalMisses[i] / double(trans);
298 }
299 }
300
301 integer_t total_misses = m_perProcTotalMisses.sum();
302 integer_t user_misses = m_perProcUserMisses.sum();
303 integer_t supervisor_misses = m_perProcSupervisorMisses.sum();
304 integer_t simics_cycles_executed = perProcCycleCount.sum();
305 integer_t transactions_started = m_perProcStartTransaction.sum();
306 integer_t transactions_ended = m_perProcEndTransaction.sum();
307
308 double cycles_per_transaction = (transactions_ended != 0) ? (m_num_of_sequencers * double(ruby_cycles)) / double(transactions_ended) : 0;
309 double misses_per_transaction = (transactions_ended != 0) ? double(total_misses) / double(transactions_ended) : 0;
310
311 out << "Total_misses: " << total_misses << endl;
312 out << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
313 out << "user_misses: " << user_misses << " " << m_perProcUserMisses << endl;
314 out << "supervisor_misses: " << supervisor_misses << " " << m_perProcSupervisorMisses << endl;
315 out << endl;
316 out << "ruby_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
317 out << endl;
318 out << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
319 out << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
320 out << "cycles_per_transaction: " << cycles_per_transaction << " " << perProcCyclesPerTrans << endl;
321 out << "misses_per_transaction: " << misses_per_transaction << " " << perProcMissesPerTrans << endl;
322
323 out << endl;
324
325 out << endl;
326
327 if (!short_stats) {
328 out << "Busy Controller Counts:" << endl;
329 for(int i=0; i < MachineType_NUM; i++) {
330 for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
331 MachineID machID;
332 machID.type = (MachineType)i;
333 machID.num = j;
334 out << machID << ":" << m_busyControllerCount[i][j] << " ";
335 if ((j+1)%8 == 0) {
336 out << endl;
337 }
338 }
339 out << endl;
340 }
341 out << endl;
342
343 out << "Busy Bank Count:" << m_busyBankCount << endl;
344 out << endl;
345
346 out << "sequencer_requests_outstanding: " << m_sequencer_requests << endl;
347 out << endl;
348 }
349
350 if (!short_stats) {
351 out << "All Non-Zero Cycle Demand Cache Accesses" << endl;
352 out << "----------------------------------------" << endl;
353 out << "miss_latency: " << m_allMissLatencyHistogram << endl;
354 for(int i=0; i<m_missLatencyHistograms.size(); i++) {
355 if (m_missLatencyHistograms[i].size() > 0) {
356 out << "miss_latency_" << RubyRequestType(i) << ": " << m_missLatencyHistograms[i] << endl;
357 }
358 }
359 for(int i=0; i<m_machLatencyHistograms.size(); i++) {
360 if (m_machLatencyHistograms[i].size() > 0) {
361 out << "miss_latency_" << GenericMachineType(i) << ": " << m_machLatencyHistograms[i] << endl;
362 }
363 }
364
365 out << endl;
366
367 out << "All Non-Zero Cycle SW Prefetch Requests" << endl;
368 out << "------------------------------------" << endl;
369 out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl;
370 for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
371 if (m_SWPrefetchLatencyHistograms[i].size() > 0) {
372 out << "prefetch_latency_" << CacheRequestType(i) << ": " << m_SWPrefetchLatencyHistograms[i] << endl;
373 }
374 }
375 for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
376 if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) {
377 out << "prefetch_latency_" << GenericMachineType(i) << ": " << m_SWPrefetchMachLatencyHistograms[i] << endl;
378 }
379 }
380 out << "prefetch_latency_L2Miss:" << m_SWPrefetchL2MissLatencyHistogram << endl;
381
382 if (m_all_sharing_histogram.size() > 0) {
383 out << "all_sharing: " << m_all_sharing_histogram << endl;
384 out << "read_sharing: " << m_read_sharing_histogram << endl;
385 out << "write_sharing: " << m_write_sharing_histogram << endl;
386
387 out << "all_sharing_percent: "; m_all_sharing_histogram.printPercent(out); out << endl;
388 out << "read_sharing_percent: "; m_read_sharing_histogram.printPercent(out); out << endl;
389 out << "write_sharing_percent: "; m_write_sharing_histogram.printPercent(out); out << endl;
390
391 int64 total_miss = m_cache_to_cache + m_memory_to_cache;
392 out << "all_misses: " << total_miss << endl;
393 out << "cache_to_cache_misses: " << m_cache_to_cache << endl;
394 out << "memory_to_cache_misses: " << m_memory_to_cache << endl;
395 out << "cache_to_cache_percent: " << 100.0 * (double(m_cache_to_cache) / double(total_miss)) << endl;
396 out << "memory_to_cache_percent: " << 100.0 * (double(m_memory_to_cache) / double(total_miss)) << endl;
397 out << endl;
398 }
399
400 if (m_outstanding_requests.size() > 0) {
401 out << "outstanding_requests: "; m_outstanding_requests.printPercent(out); out << endl;
402 out << endl;
403 }
404 }
405
406 if (!short_stats) {
407 out << "Request vs. RubySystem State Profile" << endl;
408 out << "--------------------------------" << endl;
409 out << endl;
410
411 Vector<string> requestProfileKeys = m_requestProfileMap_ptr->keys();
412 requestProfileKeys.sortVector();
413
414 for(int i=0; i<requestProfileKeys.size(); i++) {
415 int temp_int = m_requestProfileMap_ptr->lookup(requestProfileKeys[i]);
416 double percent = (100.0*double(temp_int))/double(m_requests);
417 while (requestProfileKeys[i] != "") {
418 out << setw(10) << string_split(requestProfileKeys[i], ':');
419 }
420 out << setw(11) << temp_int;
421 out << setw(14) << percent << endl;
422 }
423 out << endl;
424
425 out << "filter_action: " << m_filter_action_histogram << endl;
426
427 if (!m_all_instructions) {
428 m_address_profiler_ptr->printStats(out);
429 }
430
431 if (m_all_instructions) {
432 m_inst_profiler_ptr->printStats(out);
433 }
434
435 out << endl;
436 out << "Message Delayed Cycles" << endl;
437 out << "----------------------" << endl;
438 out << "Total_delay_cycles: " << m_delayedCyclesHistogram << endl;
439 out << "Total_nonPF_delay_cycles: " << m_delayedCyclesNonPFHistogram << endl;
440 for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) {
441 out << " virtual_network_" << i << "_delay_cycles: " << m_delayedCyclesVCHistograms[i] << endl;
442 }
443
444 printResourceUsage(out);
445 }
446
447}
448
449void Profiler::printResourceUsage(ostream& out) const
450{
451 out << endl;
452 out << "Resource Usage" << endl;
453 out << "--------------" << endl;
454
455 integer_t pagesize = getpagesize(); // page size in bytes
456 out << "page_size: " << pagesize << endl;
457
458 rusage usage;
459 getrusage (RUSAGE_SELF, &usage);
460
461 out << "user_time: " << usage.ru_utime.tv_sec << endl;
462 out << "system_time: " << usage.ru_stime.tv_sec << endl;
463 out << "page_reclaims: " << usage.ru_minflt << endl;
464 out << "page_faults: " << usage.ru_majflt << endl;
465 out << "swaps: " << usage.ru_nswap << endl;
466 out << "block_inputs: " << usage.ru_inblock << endl;
467 out << "block_outputs: " << usage.ru_oublock << endl;
468}
469
470void Profiler::clearStats()
471{
472 m_ruby_start = g_eventQueue_ptr->getTime();
473
474 m_cycles_executed_at_start.setSize(m_num_of_sequencers);
475 for (int i=0; i < m_num_of_sequencers; i++) {
476 if (g_system_ptr == NULL) {
477 m_cycles_executed_at_start[i] = 0;
478 } else {
479 m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i);
480 }
481 }
482
483 m_perProcTotalMisses.setSize(m_num_of_sequencers);
484 m_perProcUserMisses.setSize(m_num_of_sequencers);
485 m_perProcSupervisorMisses.setSize(m_num_of_sequencers);
486 m_perProcStartTransaction.setSize(m_num_of_sequencers);
487 m_perProcEndTransaction.setSize(m_num_of_sequencers);
488
489 for(int i=0; i < m_num_of_sequencers; i++) {
490 m_perProcTotalMisses[i] = 0;
491 m_perProcUserMisses[i] = 0;
492 m_perProcSupervisorMisses[i] = 0;
493 m_perProcStartTransaction[i] = 0;
494 m_perProcEndTransaction[i] = 0;
495 }
496
497 m_busyControllerCount.setSize(MachineType_NUM); // all machines
498 for(int i=0; i < MachineType_NUM; i++) {
499 m_busyControllerCount[i].setSize(MachineType_base_count((MachineType)i));
500 for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
501 m_busyControllerCount[i][j] = 0;
502 }
503 }
504 m_busyBankCount = 0;
505
506 m_delayedCyclesHistogram.clear();
507 m_delayedCyclesNonPFHistogram.clear();
508 m_delayedCyclesVCHistograms.setSize(RubySystem::getNetwork()->getNumberOfVirtualNetworks());
509 for (int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++) {
510 m_delayedCyclesVCHistograms[i].clear();
511 }
512
513 m_missLatencyHistograms.setSize(RubyRequestType_NUM);
514 for(int i=0; i<m_missLatencyHistograms.size(); i++) {
515 m_missLatencyHistograms[i].clear(200);
516 }
517 m_machLatencyHistograms.setSize(GenericMachineType_NUM+1);
518 for(int i=0; i<m_machLatencyHistograms.size(); i++) {
519 m_machLatencyHistograms[i].clear(200);
520 }
521 m_allMissLatencyHistogram.clear(200);
522
523 m_SWPrefetchLatencyHistograms.setSize(CacheRequestType_NUM);
524 for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
525 m_SWPrefetchLatencyHistograms[i].clear(200);
526 }
527 m_SWPrefetchMachLatencyHistograms.setSize(GenericMachineType_NUM+1);
528 for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
529 m_SWPrefetchMachLatencyHistograms[i].clear(200);
530 }
531 m_allSWPrefetchLatencyHistogram.clear(200);
532
533 m_sequencer_requests.clear();
534 m_read_sharing_histogram.clear();
535 m_write_sharing_histogram.clear();
536 m_all_sharing_histogram.clear();
537 m_cache_to_cache = 0;
538 m_memory_to_cache = 0;
539
540 // clear HashMaps
541 m_requestProfileMap_ptr->clear();
542
543 // count requests profiled
544 m_requests = 0;
545
546 m_outstanding_requests.clear();
547 m_outstanding_persistent_requests.clear();
548
549 // Flush the prefetches through the system - used so that there are no outstanding requests after stats are cleared
550 //g_eventQueue_ptr->triggerAllEvents();
551
552 // update the start time
553 m_ruby_start = g_eventQueue_ptr->getTime();
554}
555
556void Profiler::addAddressTraceSample(const CacheMsg& msg, NodeID id)
557{
558 if (msg.getType() != CacheRequestType_IFETCH) {
559
560 // Note: The following line should be commented out if you want to
561 // use the special profiling that is part of the GS320 protocol
562
563 // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be profiled by the AddressProfiler
564 m_address_profiler_ptr->addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), msg.getType(), msg.getAccessMode(), id, false);
565 }
566}
567
568void Profiler::profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner)
569{
570 Set set_contacted(owner);
571 if (type == AccessType_Write) {
572 set_contacted.addSet(sharers);
573 }
574 set_contacted.remove(requestor);
575 int number_contacted = set_contacted.count();
576
577 if (type == AccessType_Write) {
578 m_write_sharing_histogram.add(number_contacted);
579 } else {
580 m_read_sharing_histogram.add(number_contacted);
581 }
582 m_all_sharing_histogram.add(number_contacted);
583
584 if (number_contacted == 0) {
585 m_memory_to_cache++;
586 } else {
587 m_cache_to_cache++;
588 }
589
590}
591
592void Profiler::profileMsgDelay(int virtualNetwork, int delayCycles) {
593 assert(virtualNetwork < m_delayedCyclesVCHistograms.size());
594 m_delayedCyclesHistogram.add(delayCycles);
595 m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles);
596 if (virtualNetwork != 0) {
597 m_delayedCyclesNonPFHistogram.add(delayCycles);
598 }
599}
600
601// profiles original cache requests including PUTs
602void Profiler::profileRequest(const string& requestStr)
603{
604 m_requests++;
605
606 if (m_requestProfileMap_ptr->exist(requestStr)) {
607 (m_requestProfileMap_ptr->lookup(requestStr))++;
608 } else {
609 m_requestProfileMap_ptr->add(requestStr, 1);
610 }
611}
612
613void Profiler::startTransaction(int cpu)
614{
615 m_perProcStartTransaction[cpu]++;
616}
617
618void Profiler::endTransaction(int cpu)
619{
620 m_perProcEndTransaction[cpu]++;
621}
622
623void Profiler::controllerBusy(MachineID machID)
624{
625 m_busyControllerCount[(int)machID.type][(int)machID.num]++;
626}
627
628void Profiler::profilePFWait(Time waitTime)
629{
630 m_prefetchWaitHistogram.add(waitTime);
631}
632
633void Profiler::bankBusy()
634{
635 m_busyBankCount++;
636}
637
638// non-zero cycle demand request
639void Profiler::missLatency(Time t, RubyRequestType type)
640{
641 m_allMissLatencyHistogram.add(t);
642 m_missLatencyHistograms[type].add(t);
643}
644
645// non-zero cycle prefetch request
646void Profiler::swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach)
647{
648 m_allSWPrefetchLatencyHistogram.add(t);
649 m_SWPrefetchLatencyHistograms[type].add(t);
650 m_SWPrefetchMachLatencyHistograms[respondingMach].add(t);
651 if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) {
652 m_SWPrefetchL2MissLatencyHistogram.add(t);
653 }
654}
655
656void Profiler::profileTransition(const string& component, NodeID version, Address addr,
657 const string& state, const string& event,
658 const string& next_state, const string& note)
659{
660 const int EVENT_SPACES = 20;
661 const int ID_SPACES = 3;
662 const int TIME_SPACES = 7;
663 const int COMP_SPACES = 10;
664 const int STATE_SPACES = 6;
665
666 if ((g_debug_ptr->getDebugTime() > 0) &&
667 (g_eventQueue_ptr->getTime() >= g_debug_ptr->getDebugTime())) {
668 (* debug_cout_ptr).flags(ios::right);
669 (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
670 (* debug_cout_ptr) << setw(ID_SPACES) << version << " ";
671 (* debug_cout_ptr) << setw(COMP_SPACES) << component;
672 (* debug_cout_ptr) << setw(EVENT_SPACES) << event << " ";
673
674 (* debug_cout_ptr).flags(ios::right);
675 (* debug_cout_ptr) << setw(STATE_SPACES) << state;
676 (* debug_cout_ptr) << ">";
677 (* debug_cout_ptr).flags(ios::left);
678 (* debug_cout_ptr) << setw(STATE_SPACES) << next_state;
679
680 (* debug_cout_ptr) << " " << addr << " " << note;
681
682 (* debug_cout_ptr) << endl;
683 }
684}
685
686// Helper function
687static double process_memory_total()
688{
689 const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
690 ifstream proc_file;
691 proc_file.open("/proc/self/statm");
692 int total_size_in_pages = 0;
693 int res_size_in_pages = 0;
694 proc_file >> total_size_in_pages;
695 proc_file >> res_size_in_pages;
696 return double(total_size_in_pages)*MULTIPLIER; // size in megabytes
697}
698
699static double process_memory_resident()
700{
701 const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
702 ifstream proc_file;
703 proc_file.open("/proc/self/statm");
704 int total_size_in_pages = 0;
705 int res_size_in_pages = 0;
706 proc_file >> total_size_in_pages;
707 proc_file >> res_size_in_pages;
708 return double(res_size_in_pages)*MULTIPLIER; // size in megabytes
709}
710
711void Profiler::rubyWatch(int id){
712 //int rn_g1 = 0;//SIMICS_get_register_number(id, "g1");
713 uint64 tr = 0;//SIMICS_read_register(id, rn_g1);
714 Address watch_address = Address(tr);
715 const int ID_SPACES = 3;
716 const int TIME_SPACES = 7;
717
718 (* debug_cout_ptr).flags(ios::right);
719 (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
720 (* debug_cout_ptr) << setw(ID_SPACES) << id << " "
721 << "RUBY WATCH "
722 << watch_address
723 << endl;
724
725 if(!m_watch_address_list_ptr->exist(watch_address)){
726 m_watch_address_list_ptr->add(watch_address, 1);
727 }
728}
729
730bool Profiler::watchAddress(Address addr){
731 if (m_watch_address_list_ptr->exist(addr))
732 return true;
733 else
734 return false;
735}
736
737int64 Profiler::getTotalTransactionsExecuted() const {
738 return m_perProcEndTransaction.sum();
739}
740
741
742Profiler *
743RubyProfilerParams::create()
744{
745 return new Profiler(this);
746}