events.hpp revision 3240
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This code is free software; you can redistribute it and/or modify it
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * under the terms of the GNU General Public License version 2 only, as
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * published by the Free Software Foundation.
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * This code is distributed in the hope that it will be useful, but WITHOUT
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * version 2 for more details (a copy is included in the LICENSE file that
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * accompanied this code).
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * You should have received a copy of the GNU General Public License version
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * 2 along with this work; if not, write to the Free Software Foundation,
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0cbe448914be61d0f92b1e9d3adaeba87d25639dEvan Hunt * or visit www.oracle.com if you need additional information or have any
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews * questions.
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// Events and EventMark provide interfaces to log events taking place in the vm.
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// This facility is extremly useful for post-mortem debugging. The eventlog
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// often provides crucial information about events leading up to the crash.
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// Abstractly the logs can record whatever they way but normally they
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// would record at least a timestamp and the current Thread, along
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// with whatever data they need in a ring buffer. Commonly fixed
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// length text messages are recorded for simplicity but other
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// strategies could be used. Several logs are provided by default but
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// new instances can be created as needed.
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// The base event log dumping class that is registered for dumping at
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// crash time. This is a very generic interface that is mainly here
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// for completeness. Normally the templated EventLogBase would be
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews// subclassed to provide different log types.
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews friend class Events;
EventLog();
template <class X> class EventRecord {
double timestamp;
X data;
const char* _name;
int _length;
int _index;
int _count;
_count(0),
_index(0),
double fetch_timestamp() {
int compute_log_index() {
_index++;
return index;
bool should_log() {
StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
if (!should_log()) return;
friend class EventLog;
static void print();
static void init();
if (LogEvents) {
if (LogEvents) {
if (LogEvents) {
if (_count == 0) {
for (int i = 0; i < _count; i++) {
for (int i = 0; i < _index; i++) {
~EventMark();