< prev index next >

src/hotspot/share/utilities/events.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, 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  *


 118   // Print the contents of the log
 119   void print_log_on(outputStream* out);
 120 
 121  private:
 122   void print_log_impl(outputStream* out);
 123 
 124   // Print a single element.  A templated implementation might need to
 125   // be declared by subclasses.
 126   void print(outputStream* out, T& e);
 127 
 128   void print(outputStream* out, EventRecord<T>& e) {
 129     out->print("Event: %.3f ", e.timestamp);
 130     if (e.thread != NULL) {
 131       out->print("Thread " INTPTR_FORMAT " ", p2i(e.thread));
 132     }
 133     print(out, e.data);
 134   }
 135 };
 136 
 137 // A simple wrapper class for fixed size text messages.
 138 class StringLogMessage : public FormatBuffer<256> {
 139  public:
 140   // Wrap this buffer in a stringStream.
 141   stringStream stream() {
 142     return stringStream(_buf, size());
 143   }
 144 };
 145 
 146 // A simple ring buffer of fixed size text messages.
 147 class StringEventLog : public EventLogBase<StringLogMessage> {
 148  public:
 149   StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 150 
 151   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 152     if (!should_log()) return;
 153 
 154     double timestamp = fetch_timestamp();
 155     MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
 156     int index = compute_log_index();
 157     _records[index].thread = thread;
 158     _records[index].timestamp = timestamp;


   1 /*
   2  * Copyright (c) 1997, 2018, 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  *


 118   // Print the contents of the log
 119   void print_log_on(outputStream* out);
 120 
 121  private:
 122   void print_log_impl(outputStream* out);
 123 
 124   // Print a single element.  A templated implementation might need to
 125   // be declared by subclasses.
 126   void print(outputStream* out, T& e);
 127 
 128   void print(outputStream* out, EventRecord<T>& e) {
 129     out->print("Event: %.3f ", e.timestamp);
 130     if (e.thread != NULL) {
 131       out->print("Thread " INTPTR_FORMAT " ", p2i(e.thread));
 132     }
 133     print(out, e.data);
 134   }
 135 };
 136 
 137 // A simple wrapper class for fixed size text messages.
 138 class StringLogMessage : public FormatBufferEx<1024> {
 139  public:
 140   // Wrap this buffer in a stringStream.
 141   stringStream stream() {
 142     return stringStream(_buf, size());
 143   }
 144 };
 145 
 146 // A simple ring buffer of fixed size text messages.
 147 class StringEventLog : public EventLogBase<StringLogMessage> {
 148  public:
 149   StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 150 
 151   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 152     if (!should_log()) return;
 153 
 154     double timestamp = fetch_timestamp();
 155     MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
 156     int index = compute_log_index();
 157     _records[index].thread = thread;
 158     _records[index].timestamp = timestamp;


< prev index next >