1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_EVENTS_HPP
  26 #define SHARE_VM_UTILITIES_EVENTS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/top.hpp"
  30 
  31 // Events and EventMark provide interfaces to log events taking place in the vm.
  32 // This facility is extremly useful for post-mortem debugging. The eventlog
  33 // often provides crucial information about events leading up to the crash.
  34 //
  35 // All arguments past the format string must be passed as an intptr_t.
  36 //
  37 // To log a single event use:
  38 //    Events::log("New nmethod has been created " INTPTR_FORMAT, nm);
  39 //
  40 // To log a block of events use:
  41 //    EventMark m("GarbageCollecting %d", (intptr_t)gc_number);
  42 //
  43 // The constructor to eventlog indents the eventlog until the
  44 // destructor has been executed.
  45 //
  46 // IMPLEMENTATION RESTRICTION:
  47 //   Max 3 arguments are saved for each logged event.
  48 //
  49 
  50 class Events : AllStatic {
  51  public:
  52   // Logs an event, format as printf
  53   static void log(const char* format, ...) PRODUCT_RETURN;
  54 
  55   // Prints all events in the buffer
  56   static void print_all(outputStream* st) PRODUCT_RETURN;
  57 
  58   // Prints last number events from the event buffer
  59   static void print_last(outputStream *st, int number) PRODUCT_RETURN;
  60 };
  61 
  62 class EventMark : public StackObj {
  63  public:
  64   // log a begin event, format as printf
  65   EventMark(const char* format, ...) PRODUCT_RETURN;
  66   // log an end event
  67   ~EventMark() PRODUCT_RETURN;
  68 };
  69 
  70 int print_all_events(outputStream *st);
  71 
  72 #endif // SHARE_VM_UTILITIES_EVENTS_HPP