28 /*
29 *
30 * <p><b>This is NOT part of any API supported by Sun Microsystems.
31 * If you write code that depends on this, you do so at your own
32 * risk. This code and its internal interfaces are subject to change
33 * or deletion without notice.</b>
34 *
35 */
36
37 /**
38 * A utility package for the java(1), javaw(1) launchers.
39 * The following are helper methods that the native launcher uses
40 * to perform checks etc. using JNI, see src/share/bin/java.c
41 */
42 import java.io.File;
43 import java.io.IOException;
44 import java.io.PrintStream;
45 import java.io.UnsupportedEncodingException;
46 import java.lang.module.Configuration;
47 import java.lang.module.ModuleDescriptor;
48 import java.lang.module.ModuleDescriptor.Requires;
49 import java.lang.module.ModuleDescriptor.Exports;
50 import java.lang.module.ModuleDescriptor.Opens;
51 import java.lang.module.ModuleDescriptor.Provides;
52 import java.lang.module.ModuleFinder;
53 import java.lang.module.ModuleReference;
54 import java.lang.module.ResolvedModule;
55 import java.lang.reflect.InvocationTargetException;
56 import java.lang.reflect.Method;
57 import java.lang.reflect.Modifier;
58 import java.math.BigDecimal;
59 import java.math.RoundingMode;
60 import java.net.URI;
61 import java.nio.charset.Charset;
62 import java.nio.file.DirectoryStream;
63 import java.nio.file.Files;
64 import java.nio.file.Path;
65 import java.text.Normalizer;
66 import java.text.MessageFormat;
67 import java.util.ArrayList;
68 import java.util.Collections;
69 import java.util.Comparator;
70 import java.util.Iterator;
71 import java.util.List;
72 import java.util.Locale;
73 import java.util.Locale.Category;
74 import java.util.Optional;
75 import java.util.Properties;
76 import java.util.ResourceBundle;
77 import java.util.Set;
78 import java.util.TreeSet;
79 import java.util.jar.Attributes;
80 import java.util.jar.JarFile;
81 import java.util.jar.Manifest;
82 import java.util.stream.Collectors;
83 import java.util.stream.Stream;
84
85 import jdk.internal.misc.VM;
86 import jdk.internal.module.ModuleBootstrap;
308 // print columns of 8
309 if ((i + 1) % 8 == 0) {
310 ostream.println();
311 ostream.print(INDENT + INDENT);
312 }
313 }
314 }
315
316 public static void printSystemMetrics() {
317 Metrics c = Container.metrics();
318
319 ostream.println("Operating System Metrics:");
320
321 if (c == null) {
322 ostream.println(INDENT + "No metrics available for this platform");
323 return;
324 }
325
326 ostream.println(INDENT + "Provider: " + c.getProvider());
327 ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount());
328 ostream.println(INDENT + "CPU Period: " + c.getCpuPeriod() +
329 (c.getCpuPeriod() == -1 ? "" : "us"));
330 ostream.println(INDENT + "CPU Quota: " + c.getCpuQuota() +
331 (c.getCpuQuota() == -1 ? "" : "us"));
332 ostream.println(INDENT + "CPU Shares: " + c.getCpuShares());
333
334 int cpus[] = c.getCpuSetCpus();
335 ostream.println(INDENT + "List of Processors, "
336 + cpus.length + " total: ");
337
338 ostream.print(INDENT);
339 for (int i = 0; i < cpus.length; i++) {
340 ostream.print(cpus[i] + " ");
341 }
342 if (cpus.length > 0) {
343 ostream.println("");
344 }
345
346 cpus = c.getEffectiveCpuSetCpus();
347 ostream.println(INDENT + "List of Effective Processors, "
348 + cpus.length + " total: ");
349
350 ostream.print(INDENT);
351 for (int i = 0; i < cpus.length; i++) {
352 ostream.print(cpus[i] + " ");
353 }
354 if (cpus.length > 0) {
355 ostream.println("");
356 }
357
358 int mems[] = c.getCpuSetMems();
359 ostream.println(INDENT + "List of Memory Nodes, "
360 + mems.length + " total: ");
361
362 ostream.print(INDENT);
363 for (int i = 0; i < mems.length; i++) {
364 ostream.print(mems[i] + " ");
365 }
366 if (mems.length > 0) {
367 ostream.println("");
368 }
369
370 mems = c.getEffectiveCpuSetMems();
371 ostream.println(INDENT + "List of Available Memory Nodes, "
372 + mems.length + " total: ");
373
374 ostream.print(INDENT);
375 for (int i = 0; i < mems.length; i++) {
376 ostream.print(mems[i] + " ");
377 }
378 if (mems.length > 0) {
379 ostream.println("");
380 }
381
382 ostream.println(INDENT + "CPUSet Memory Pressure Enabled: "
383 + c.isCpuSetMemoryPressureEnabled());
384
385 long limit = c.getMemoryLimit();
386 ostream.println(INDENT + "Memory Limit: " +
387 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
388
389 limit = c.getMemorySoftLimit();
390 ostream.println(INDENT + "Memory Soft Limit: " +
391 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
392
393 limit = c.getMemoryAndSwapLimit();
394 ostream.println(INDENT + "Memory & Swap Limit: " +
395 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
396
397 limit = c.getKernelMemoryLimit();
398 ostream.println(INDENT + "Kernel Memory Limit: " +
399 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
400
401 limit = c.getTcpMemoryLimit();
402 ostream.println(INDENT + "TCP Memory Limit: " +
403 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
404
405 ostream.println(INDENT + "Out Of Memory Killer Enabled: "
406 + c.isMemoryOOMKillEnabled());
407
408 ostream.println("");
409 }
410
411 private enum SizePrefix {
412
413 KILO(1024, "K"),
414 MEGA(1024 * 1024, "M"),
415 GIGA(1024 * 1024 * 1024, "G"),
416 TERA(1024L * 1024L * 1024L * 1024L, "T");
417 long size;
418 String abbrev;
419
420 SizePrefix(long size, String abbrev) {
421 this.size = size;
422 this.abbrev = abbrev;
423 }
424
425 private static String scale(long v, SizePrefix prefix) {
426 return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
427 2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
428 }
|
28 /*
29 *
30 * <p><b>This is NOT part of any API supported by Sun Microsystems.
31 * If you write code that depends on this, you do so at your own
32 * risk. This code and its internal interfaces are subject to change
33 * or deletion without notice.</b>
34 *
35 */
36
37 /**
38 * A utility package for the java(1), javaw(1) launchers.
39 * The following are helper methods that the native launcher uses
40 * to perform checks etc. using JNI, see src/share/bin/java.c
41 */
42 import java.io.File;
43 import java.io.IOException;
44 import java.io.PrintStream;
45 import java.io.UnsupportedEncodingException;
46 import java.lang.module.Configuration;
47 import java.lang.module.ModuleDescriptor;
48 import java.lang.module.ModuleDescriptor.Exports;
49 import java.lang.module.ModuleDescriptor.Opens;
50 import java.lang.module.ModuleDescriptor.Provides;
51 import java.lang.module.ModuleDescriptor.Requires;
52 import java.lang.module.ModuleFinder;
53 import java.lang.module.ModuleReference;
54 import java.lang.module.ResolvedModule;
55 import java.lang.reflect.InvocationTargetException;
56 import java.lang.reflect.Method;
57 import java.lang.reflect.Modifier;
58 import java.math.BigDecimal;
59 import java.math.RoundingMode;
60 import java.net.URI;
61 import java.nio.charset.Charset;
62 import java.nio.file.DirectoryStream;
63 import java.nio.file.Files;
64 import java.nio.file.Path;
65 import java.text.MessageFormat;
66 import java.text.Normalizer;
67 import java.util.ArrayList;
68 import java.util.Collections;
69 import java.util.Comparator;
70 import java.util.Iterator;
71 import java.util.List;
72 import java.util.Locale;
73 import java.util.Locale.Category;
74 import java.util.Optional;
75 import java.util.Properties;
76 import java.util.ResourceBundle;
77 import java.util.Set;
78 import java.util.TreeSet;
79 import java.util.jar.Attributes;
80 import java.util.jar.JarFile;
81 import java.util.jar.Manifest;
82 import java.util.stream.Collectors;
83 import java.util.stream.Stream;
84
85 import jdk.internal.misc.VM;
86 import jdk.internal.module.ModuleBootstrap;
308 // print columns of 8
309 if ((i + 1) % 8 == 0) {
310 ostream.println();
311 ostream.print(INDENT + INDENT);
312 }
313 }
314 }
315
316 public static void printSystemMetrics() {
317 Metrics c = Container.metrics();
318
319 ostream.println("Operating System Metrics:");
320
321 if (c == null) {
322 ostream.println(INDENT + "No metrics available for this platform");
323 return;
324 }
325
326 ostream.println(INDENT + "Provider: " + c.getProvider());
327 ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount());
328 ostream.println(formatCpuVal(c.getCpuPeriod(), INDENT + "CPU Period: "));
329 ostream.println(formatCpuVal(c.getCpuQuota(), INDENT + "CPU Quota: "));
330 ostream.println(formatCpuVal(c.getCpuShares(), INDENT + "CPU Shares: "));
331
332 int cpus[] = c.getCpuSetCpus();
333 if (cpus != null) {
334 ostream.println(INDENT + "List of Processors, "
335 + cpus.length + " total: ");
336
337 ostream.print(INDENT);
338 for (int i = 0; i < cpus.length; i++) {
339 ostream.print(cpus[i] + " ");
340 }
341 if (cpus.length > 0) {
342 ostream.println("");
343 }
344 } else {
345 ostream.println(INDENT + "List of Processors: N/A");
346 }
347
348 cpus = c.getEffectiveCpuSetCpus();
349 if (cpus != null) {
350 ostream.println(INDENT + "List of Effective Processors, "
351 + cpus.length + " total: ");
352
353 ostream.print(INDENT);
354 for (int i = 0; i < cpus.length; i++) {
355 ostream.print(cpus[i] + " ");
356 }
357 if (cpus.length > 0) {
358 ostream.println("");
359 }
360 } else {
361 ostream.println(INDENT + "List of Effective Processors: N/A");
362 }
363
364 int mems[] = c.getCpuSetMems();
365 if (mems != null) {
366 ostream.println(INDENT + "List of Memory Nodes, "
367 + mems.length + " total: ");
368
369 ostream.print(INDENT);
370 for (int i = 0; i < mems.length; i++) {
371 ostream.print(mems[i] + " ");
372 }
373 if (mems.length > 0) {
374 ostream.println("");
375 }
376 } else {
377 ostream.println(INDENT + "List of Memory Nodes: N/A");
378 }
379
380 mems = c.getEffectiveCpuSetMems();
381 if (mems != null) {
382 ostream.println(INDENT + "List of Available Memory Nodes, "
383 + mems.length + " total: ");
384
385 ostream.print(INDENT);
386 for (int i = 0; i < mems.length; i++) {
387 ostream.print(mems[i] + " ");
388 }
389 if (mems.length > 0) {
390 ostream.println("");
391 }
392 } else {
393 ostream.println(INDENT + "List of Available Memory Nodes: N/A");
394 }
395
396 ostream.println(formatBoolean(c.isCpuSetMemoryPressureEnabled(),
397 INDENT + "CPUSet Memory Pressure Enabled: "));
398
399 long limit = c.getMemoryLimit();
400 ostream.println(formatLimitString(limit, INDENT + "Memory Limit: "));
401
402 limit = c.getMemorySoftLimit();
403 ostream.println(formatLimitString(limit, INDENT + "Memory Soft Limit: "));
404
405 limit = c.getMemoryAndSwapLimit();
406 ostream.println(formatLimitString(limit, INDENT + "Memory & Swap Limit: "));
407
408 limit = c.getKernelMemoryLimit();
409 ostream.println(formatLimitString(limit, INDENT + "Kernel Memory Limit: "));
410
411 limit = c.getTcpMemoryLimit();
412 ostream.println(formatLimitString(limit, INDENT + "TCP Memory Limit: "));
413
414 ostream.println(formatBoolean(c.isMemoryOOMKillEnabled(),
415 INDENT + "Out Of Memory Killer Enabled: "));
416
417 ostream.println("");
418 }
419
420 private static String formatLimitString(long limit, String prefix) {
421 if (limit >= 0) {
422 return prefix + SizePrefix.scaleValue(limit);
423 } else if (limit == Metrics.LONG_RETVAL_NOT_SUPPORTED) {
424 return prefix + "N/A";
425 } else {
426 return prefix + "Unlimited";
427 }
428 }
429
430 private static String formatCpuVal(long cpuVal, String prefix) {
431 if (cpuVal >= 0) {
432 return prefix + cpuVal + "us";
433 } else if (cpuVal == Metrics.LONG_RETVAL_NOT_SUPPORTED) {
434 return prefix + "N/A";
435 } else {
436 return prefix + cpuVal;
437 }
438 }
439
440 private static String formatBoolean(Boolean value, String prefix) {
441 if (value == Metrics.BOOL_RETVAL_NOT_SUPPORTED) {
442 return prefix + "N/A";
443 } else {
444 return prefix + value;
445 }
446 }
447
448 private enum SizePrefix {
449
450 KILO(1024, "K"),
451 MEGA(1024 * 1024, "M"),
452 GIGA(1024 * 1024 * 1024, "G"),
453 TERA(1024L * 1024L * 1024L * 1024L, "T");
454 long size;
455 String abbrev;
456
457 SizePrefix(long size, String abbrev) {
458 this.size = size;
459 this.abbrev = abbrev;
460 }
461
462 private static String scale(long v, SizePrefix prefix) {
463 return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
464 2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
465 }
|