< prev index next >

src/hotspot/share/utilities/events.hpp

Print this page
rev 52913 : 8204551: Event descriptions are truncated in logs
Reviewed-by: coleenp, andrew


 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 };


 140 
 141 // A simple ring buffer of fixed size text messages.
 142 class StringEventLog : public EventLogBase<StringLogMessage> {

 143  public:
 144   StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 145 
 146   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 147     if (!should_log()) return;
 148 
 149     double timestamp = fetch_timestamp();
 150     MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
 151     int index = compute_log_index();
 152     _records[index].thread = thread;
 153     _records[index].timestamp = timestamp;
 154     _records[index].data.printv(format, ap);
 155   }
 156 
 157   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 158     va_list ap;
 159     va_start(ap, format);
 160     logv(thread, format, ap);
 161     va_end(ap);
 162   }
 163 
 164 };


 165 
 166 
 167 
 168 class Events : AllStatic {
 169   friend class EventLog;
 170 
 171  private:
 172   static EventLog* _logs;
 173 
 174   // A log for generic messages that aren't well categorized.
 175   static StringEventLog* _messages;
 176 
 177   // A log for internal exception related messages, like internal
 178   // throws and implicit exceptions.
 179   static StringEventLog* _exceptions;
 180 
 181   // Deoptization related messages
 182   static StringEventLog* _deopt_messages;
 183 
 184   // Redefinition related messages
 185   static StringEventLog* _redefinitions;
 186 
 187  public:
 188   static void print_all(outputStream* out);
 189 
 190   // Dump all events to the tty
 191   static void print();
 192 
 193   // Logs a generic message with timestamp and format as printf.
 194   static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 195 
 196   // Log exception related message
 197   static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 198 
 199   static void log_redefinition(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);


 263   }
 264 
 265   if (_count < _length) {
 266     for (int i = 0; i < _count; i++) {
 267       print(out, _records[i]);
 268     }
 269   } else {
 270     for (int i = _index; i < _length; i++) {
 271       print(out, _records[i]);
 272     }
 273     for (int i = 0; i < _index; i++) {
 274       print(out, _records[i]);
 275     }
 276   }
 277   out->cr();
 278 }
 279 
 280 // Implement a printing routine for the StringLogMessage
 281 template <>
 282 inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {







 283   out->print_raw(lm);
 284   out->cr();
 285 }
 286 
 287 // Place markers for the beginning and end up of a set of events.
 288 // These end up in the default log.
 289 class EventMark : public StackObj {
 290   StringLogMessage _buffer;
 291 
 292  public:
 293   // log a begin event, format as printf
 294   EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 295   // log an end event
 296   ~EventMark();
 297 };
 298 
 299 #endif // SHARE_VM_UTILITIES_EVENTS_HPP


 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 template <size_t bufsz>
 139 class FormatStringLogMessage : public FormatBuffer<bufsz> {
 140 };
 141 typedef FormatStringLogMessage<256> StringLogMessage;
 142 typedef FormatStringLogMessage<512> ExtendedStringLogMessage;
 143 
 144 // A simple ring buffer of fixed size text messages.
 145 template <size_t bufsz>
 146 class FormatStringEventLog : public EventLogBase< FormatStringLogMessage<bufsz> > {
 147  public:
 148   FormatStringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase< FormatStringLogMessage<bufsz> >(name, count) {}
 149 
 150   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 151     if (!this->should_log()) return;
 152 
 153     double timestamp = this->fetch_timestamp();
 154     MutexLockerEx ml(&this->_mutex, Mutex::_no_safepoint_check_flag);
 155     int index = this->compute_log_index();
 156     this->_records[index].thread = thread;
 157     this->_records[index].timestamp = timestamp;
 158     this->_records[index].data.printv(format, ap);
 159   }
 160 
 161   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 162     va_list ap;
 163     va_start(ap, format);
 164     this->logv(thread, format, ap);
 165     va_end(ap);
 166   }
 167 
 168 };
 169 typedef FormatStringEventLog<256> StringEventLog;
 170 typedef FormatStringEventLog<512> ExtendedStringEventLog;
 171 
 172 
 173 
 174 class Events : AllStatic {
 175   friend class EventLog;
 176 
 177  private:
 178   static EventLog* _logs;
 179 
 180   // A log for generic messages that aren't well categorized.
 181   static StringEventLog* _messages;
 182 
 183   // A log for internal exception related messages, like internal
 184   // throws and implicit exceptions.
 185   static ExtendedStringEventLog* _exceptions;
 186 
 187   // Deoptization related messages
 188   static StringEventLog* _deopt_messages;
 189 
 190   // Redefinition related messages
 191   static StringEventLog* _redefinitions;
 192 
 193  public:
 194   static void print_all(outputStream* out);
 195 
 196   // Dump all events to the tty
 197   static void print();
 198 
 199   // Logs a generic message with timestamp and format as printf.
 200   static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 201 
 202   // Log exception related message
 203   static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 204 
 205   static void log_redefinition(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);


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