Output: Make OutputDirectory::create() be able to create binary files.
[gem5.git] / src / base / annotate.cc
1 /*
2 * Copyright (c) 2006 The Regents of The University of Michigan
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 * Authors: Ali Saidi
29 */
30
31 #include "base/annotate.hh"
32 #include "base/callback.hh"
33 #include "base/output.hh"
34 #include "base/trace.hh"
35 #include "sim/core.hh"
36 #include "sim/sim_exit.hh"
37 #include "sim/system.hh"
38
39
40
41 class AnnotateDumpCallback : public Callback
42 {
43 public:
44 virtual void process();
45 };
46
47 void
48 AnnotateDumpCallback::process()
49 {
50 Annotate::annotations.dump();
51 }
52
53 namespace Annotate {
54
55
56 Annotate annotations;
57
58 Annotate::Annotate()
59 {
60 registerExitCallback(new AnnotateDumpCallback);
61 }
62
63 void
64 Annotate::add(System *sys, Addr stack, uint32_t sm, uint32_t st,
65 uint32_t wm, uint32_t ws)
66 {
67 AnnotateData *an;
68
69 an = new AnnotateData;
70 an->time = curTick;
71
72 std::map<System*, std::string>::iterator i = nameCache.find(sys);
73 if (i == nameCache.end()) {
74 nameCache[sys] = sys->name();
75 }
76
77 an->system = nameCache[sys];
78 an->stack = stack;
79 an->stateMachine = sm;
80 an->curState = st;
81 an->waitMachine = wm;
82 an->waitState = ws;
83
84 data.push_back(an);
85 if (an->waitMachine)
86 DPRINTF(Annotate, "Annotating: %s(%#llX) %d:%d waiting on %d:%d\n",
87 an->system, an->stack, an->stateMachine, an->curState,
88 an->waitMachine, an->waitState);
89 else
90 DPRINTF(Annotate, "Annotating: %s(%#llX) %d:%d beginning\n", an->system,
91 an->stack, an->stateMachine, an->curState);
92
93 DPRINTF(Annotate, "Now %d events on list\n", data.size());
94
95 }
96
97 void
98 Annotate::dump()
99 {
100
101 std::list<AnnotateData*>::iterator i;
102
103 i = data.begin();
104
105 if (i == data.end())
106 return;
107
108 std::ostream *os = simout.create("annotate.dat");
109
110 AnnotateData *an;
111
112 while (i != data.end()) {
113 DPRINTF(Annotate, "Writing\n", data.size());
114 an = *i;
115 ccprintf(*os, "%d %s(%#llX) %d %d %d %d\n", an->time, an->system,
116 an->stack, an->stateMachine, an->curState, an->waitMachine,
117 an->waitState);
118 i++;
119 }
120 }
121
122 } //namespace Annotate