< 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  *


 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;
 159     _records[index].data.printv(format, ap);
 160   }
 161 
 162   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 163     va_list ap;
 164     va_start(ap, format);
 165     logv(thread, format, ap);
 166     va_end(ap);
 167   }
 168 
 169 };


 265     out->print_cr("No events");
 266     out->cr();
 267     return;
 268   }
 269 
 270   if (_count < _length) {
 271     for (int i = 0; i < _count; i++) {
 272       print(out, _records[i]);
 273     }
 274   } else {
 275     for (int i = _index; i < _length; i++) {
 276       print(out, _records[i]);
 277     }
 278     for (int i = 0; i < _index; i++) {
 279       print(out, _records[i]);
 280     }
 281   }
 282   out->cr();
 283 }
 284 
 285 // Implement a printing routine for the StringLogMessage
 286 template <>
 287 inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
 288   out->print_raw(lm);
 289   out->cr();
 290 }
 291 
 292 // Place markers for the beginning and end up of a set of events.
 293 // These end up in the default log.
 294 class EventMark : public StackObj {
 295   StringLogMessage _buffer;
 296 
 297  public:
 298   // log a begin event, format as printf
 299   EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 300   // log an end event
 301   ~EventMark();
 302 };
 303 
 304 #endif // SHARE_VM_UTILITIES_EVENTS_HPP
   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  *


 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 text messages.
 147 class StringEventLog : public EventLogBase<FormatBufferDynamic> {
 148  public:
 149   StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<FormatBufferDynamic>(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;
 159     _records[index].data.printv(format, ap);
 160   }
 161 
 162   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 163     va_list ap;
 164     va_start(ap, format);
 165     logv(thread, format, ap);
 166     va_end(ap);
 167   }
 168 
 169 };


 265     out->print_cr("No events");
 266     out->cr();
 267     return;
 268   }
 269 
 270   if (_count < _length) {
 271     for (int i = 0; i < _count; i++) {
 272       print(out, _records[i]);
 273     }
 274   } else {
 275     for (int i = _index; i < _length; i++) {
 276       print(out, _records[i]);
 277     }
 278     for (int i = 0; i < _index; i++) {
 279       print(out, _records[i]);
 280     }
 281   }
 282   out->cr();
 283 }
 284 
 285 // Implement a printing routine for the FormatBufferDynamic
 286 template <>
 287 inline void EventLogBase<FormatBufferDynamic>::print(outputStream* out, FormatBufferDynamic& lm) {
 288   out->print_raw(lm);
 289   out->cr();
 290 }
 291 
 292 // Place markers for the beginning and end up of a set of events.
 293 // These end up in the default log.
 294 class EventMark : public StackObj {
 295   StringLogMessage _buffer;
 296 
 297  public:
 298   // log a begin event, format as printf
 299   EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 300   // log an end event
 301   ~EventMark();
 302 };
 303 
 304 #endif // SHARE_VM_UTILITIES_EVENTS_HPP
< prev index next >