2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
31 #include "base/stats/events.hh"
34 #include "base/cprintf.hh"
35 #include "base/misc.hh"
36 #include "base/mysql.hh"
37 #include "base/stats/mysql.hh"
38 #include "base/stats/mysql_run.hh"
39 #include "base/str.hh"
42 #include "base/match.hh"
43 #include "sim/host.hh"
44 #include "sim/sim_object.hh"
45 #include "sim/root.hh"
51 Tick EventStart
= ULL(0x7fffffffffffffff);
53 ObjectMatch event_ignore
;
62 static const int maxsize
= 1024*1024;
64 typedef map
<string
, uint32_t> event_map_t
;
67 MySQL::Connection
&mysql
;
72 : mysql(MySqlDB
.conn()), run(MySqlDB
.run())
74 query
= new char[maxsize
+ 1];
85 void insert(const string
&stat
);
89 InsertEvent::insert(const string
&stat
)
91 assert(mysql
.connected());
93 event_map_t::iterator i
= events
.find(stat
);
95 if (i
== events
.end()) {
97 csprintf("SELECT en_id "
99 "where en_name=\"%s\"",
102 MySQL::Result result
= mysql
.store_result();
104 panic("could not get a run\n%s\n", mysql
.error
);
106 assert(result
.num_fields() == 1);
107 MySQL::Row row
= result
.fetch_row();
109 if (!to_number(row
[0], event
))
110 panic("invalid event id: %s\n", row
[0]);
113 csprintf("INSERT INTO "
114 "event_names(en_name)"
119 panic("could not get a run\n%s\n", mysql
.error
);
121 event
= mysql
.insert_id();
127 if (size
+ 1024 > maxsize
)
137 size
+= sprintf(query
+ size
, "(%u,%u,%llu)",
138 event
, run
, (unsigned long long)curTick
);
144 static const char query_header
[] = "INSERT INTO "
145 "events(ev_event, ev_run, ev_tick)"
149 MySQL::Connection
&mysql
= MySqlDB
.conn();
150 assert(mysql
.connected());
155 size
= sizeof(query_header
);
157 memcpy(query
, query_header
, size
);
161 __event(const string
&stat
)
163 static InsertEvent event
;
169 /* namespace Stats */ }