< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page
rev 49895 : [mq]: 8201572-improve-metaspace-reporting


 189   if (count < 0)  return;
 190   if (SP_USE_TABS && count >= 8) {
 191     int target = position() + count;
 192     while (count >= 8) {
 193       this->write("\t", 1);
 194       count -= 8;
 195     }
 196     count = target - position();
 197   }
 198   while (count > 0) {
 199     int nw = (count > 8) ? 8 : count;
 200     this->write("        ", nw);
 201     count -= nw;
 202   }
 203 }
 204 
 205 void outputStream::cr() {
 206   this->write("\n", 1);
 207 }
 208 




 209 void outputStream::stamp() {
 210   if (! _stamp.is_updated()) {
 211     _stamp.update(); // start at 0 on first call to stamp()
 212   }
 213 
 214   // outputStream::stamp() may get called by ostream_abort(), use snprintf
 215   // to avoid allocating large stack buffer in print().
 216   char buf[40];
 217   jio_snprintf(buf, sizeof(buf), "%.3f", _stamp.seconds());
 218   print_raw(buf);
 219 }
 220 
 221 void outputStream::stamp(bool guard,
 222                          const char* prefix,
 223                          const char* suffix) {
 224   if (!guard) {
 225     return;
 226   }
 227   print_raw(prefix);
 228   stamp();


 282     if (i % 2 == 0) {
 283       print(" ");
 284     }
 285     if (i < len) {
 286       print("%02x", ((unsigned char*)data)[i]);
 287     } else {
 288       print("  ");
 289     }
 290     if ((i + 1) % 16 == 0) {
 291       if (with_ascii) {
 292         print("  ");
 293         for (size_t j = 0; j < 16; ++j) {
 294           size_t idx = i + j - 15;
 295           if (idx < len) {
 296             char c = ((char*)data)[idx];
 297             print("%c", c >= 32 && c <= 126 ? c : '.');
 298           }
 299         }
 300       }
 301       cr();


















































































 302     }
 303   }
 304 }
 305 
 306 stringStream::stringStream(size_t initial_size) : outputStream() {
 307   buffer_length = initial_size;
 308   buffer        = NEW_RESOURCE_ARRAY(char, buffer_length);
 309   buffer_pos    = 0;
 310   buffer_fixed  = false;
 311   DEBUG_ONLY(rm = Thread::current()->current_resource_mark();)
 312 }
 313 
 314 // useful for output to fixed chunks of memory, such as performance counters
 315 stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() {
 316   buffer_length = fixed_buffer_size;
 317   buffer        = fixed_buffer;
 318   buffer_pos    = 0;
 319   buffer_fixed  = true;
 320 }
 321 




 189   if (count < 0)  return;
 190   if (SP_USE_TABS && count >= 8) {
 191     int target = position() + count;
 192     while (count >= 8) {
 193       this->write("\t", 1);
 194       count -= 8;
 195     }
 196     count = target - position();
 197   }
 198   while (count > 0) {
 199     int nw = (count > 8) ? 8 : count;
 200     this->write("        ", nw);
 201     count -= nw;
 202   }
 203 }
 204 
 205 void outputStream::cr() {
 206   this->write("\n", 1);
 207 }
 208 
 209 void outputStream::cr_indent() {
 210   cr(); indent();
 211 }
 212 
 213 void outputStream::stamp() {
 214   if (! _stamp.is_updated()) {
 215     _stamp.update(); // start at 0 on first call to stamp()
 216   }
 217 
 218   // outputStream::stamp() may get called by ostream_abort(), use snprintf
 219   // to avoid allocating large stack buffer in print().
 220   char buf[40];
 221   jio_snprintf(buf, sizeof(buf), "%.3f", _stamp.seconds());
 222   print_raw(buf);
 223 }
 224 
 225 void outputStream::stamp(bool guard,
 226                          const char* prefix,
 227                          const char* suffix) {
 228   if (!guard) {
 229     return;
 230   }
 231   print_raw(prefix);
 232   stamp();


 286     if (i % 2 == 0) {
 287       print(" ");
 288     }
 289     if (i < len) {
 290       print("%02x", ((unsigned char*)data)[i]);
 291     } else {
 292       print("  ");
 293     }
 294     if ((i + 1) % 16 == 0) {
 295       if (with_ascii) {
 296         print("  ");
 297         for (size_t j = 0; j < 16; ++j) {
 298           size_t idx = i + j - 15;
 299           if (idx < len) {
 300             char c = ((char*)data)[idx];
 301             print("%c", c >= 32 && c <= 126 ? c : '.');
 302           }
 303         }
 304       }
 305       cr();
 306     }
 307   }
 308 }
 309 
 310 // Print a human readable size.
 311 // byte_size: size, in bytes, to be printed.
 312 // scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
 313 //         or 0, which means the best scale is choosen dynamically.
 314 // width: printing width.
 315 void outputStream::print_human_readable_size(size_t byte_size, size_t scale, int width)  {
 316   if (scale == 0) {
 317     // Dynamic mode. Choose scale for this value.
 318     if (byte_size == 0) {
 319       // Zero values are printed as bytes.
 320       scale = 1;
 321     } else {
 322       if (byte_size >= G) {
 323         scale = G;
 324       } else if (byte_size >= M) {
 325         scale = M;
 326       } else if (byte_size >= K) {
 327         scale = K;
 328       } else {
 329         scale = 1;
 330       }
 331     }
 332     return print_human_readable_size(byte_size, scale, width);
 333   }
 334 
 335 #ifdef ASSERT
 336   assert(scale == 1 || scale == BytesPerWord || scale == K || scale == M || scale == G, "Invalid scale");
 337   // Special case: printing wordsize should only be done with word-sized values
 338   if (scale == BytesPerWord) {
 339     assert(byte_size % BytesPerWord == 0, "not word sized");
 340   }
 341 #endif
 342 
 343   if (scale == 1) {
 344     print("%*" PRIuPTR " bytes", width, byte_size);
 345   } else if (scale == BytesPerWord) {
 346     print("%*" PRIuPTR " words", width, byte_size / BytesPerWord);
 347   } else {
 348     const char* display_unit = "";
 349     switch(scale) {
 350       case 1: display_unit = "bytes"; break;
 351       case BytesPerWord: display_unit = "words"; break;
 352       case K: display_unit = "KB"; break;
 353       case M: display_unit = "MB"; break;
 354       case G: display_unit = "GB"; break;
 355       default:
 356         ShouldNotReachHere();
 357     }
 358     float display_value = (float) byte_size / scale;
 359     // Since we use width to display a number with two trailing digits, increase it a bit.
 360     width += 3;
 361     // Prevent very small but non-null values showing up as 0.00.
 362     if (byte_size > 0 && display_value < 0.01f) {
 363       print("%*s %s", width, "<0.01", display_unit);
 364     } else {
 365       print("%*.2f %s", width, display_value, display_unit);
 366     }
 367   }
 368 }
 369 
 370 // Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values
 371 // larger than 99% but not 100% are displayed as ">100%".
 372 void outputStream::print_percentage(size_t total, size_t part) {
 373   if (total == 0) {
 374     print("  ?%%");
 375   } else if (part == 0) {
 376     print("  0%%");
 377   } else if (part == total) {
 378     print("100%%");
 379   } else {
 380     // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
 381     float p = ((float)part / total) * 100.0f;
 382     if (p < 1.0f) {
 383       print(" <1%%");
 384     } else if (p > 99.0f){
 385       print(">99%%");
 386     } else {
 387       print("%3.0f%%", p);
 388     }
 389   }
 390 }
 391 
 392 stringStream::stringStream(size_t initial_size) : outputStream() {
 393   buffer_length = initial_size;
 394   buffer        = NEW_RESOURCE_ARRAY(char, buffer_length);
 395   buffer_pos    = 0;
 396   buffer_fixed  = false;
 397   DEBUG_ONLY(rm = Thread::current()->current_resource_mark();)
 398 }
 399 
 400 // useful for output to fixed chunks of memory, such as performance counters
 401 stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() {
 402   buffer_length = fixed_buffer_size;
 403   buffer        = fixed_buffer;
 404   buffer_pos    = 0;
 405   buffer_fixed  = true;
 406 }
 407 


< prev index next >