Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JSnap.java
41161 views
/*1* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.tools;2526import java.io.*;27import java.util.*;28import java.util.stream.*;29import sun.jvm.hotspot.debugger.JVMDebugger;30import sun.jvm.hotspot.runtime.*;3132public class JSnap extends Tool {3334private boolean all;3536public JSnap() {37super();38}3940public JSnap(JVMDebugger d) {41super(d);42}4344public void run() {45final PrintStream out = System.out;46if (PerfMemory.initialized()) {47PerfDataPrologue prologue = PerfMemory.prologue();48if (prologue.accessible()) {49PerfMemory.iterate(new PerfMemory.PerfDataEntryVisitor() {50public boolean visit(PerfDataEntry pde) {51if (all || pde.supported()) {52out.print(pde.name());53out.print('=');54out.println(pde.valueAsString());55}56// goto next entry57return true;58}59});60} else {61out.println("PerfMemory is not accessible");62}63} else {64out.println("PerfMemory is not initialized");65}66}6768@Override69protected void printFlagsUsage() {70System.out.println(" -a\tto print all performance counters");71super.printFlagsUsage();72}7374public static void main(String[] args) {75JSnap js = new JSnap();76js.all = Arrays.stream(args)77.anyMatch(s -> s.equals("-a"));7879if (js.all) {80args = Arrays.stream(args)81.filter(s -> !s.equals("-a"))82.collect(Collectors.toList())83.toArray(new String[0]);84}8586js.execute(args);87}88}899091