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 == sizeof(MetaWord)) {
346 print("%*" PRIuPTR " words", width, byte_size / sizeof(MetaWord));
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 }
|
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 }
|