|
| 1 | +/* |
| 2 | +* This file is part of the ISIS IBEX application. |
| 3 | +* Copyright (C) 2012-2024 Science & Technology Facilities Council. |
| 4 | +* All rights reserved. |
| 5 | +* |
| 6 | +* This program is distributed in the hope that it will be useful. |
| 7 | +* This program and the accompanying materials are made available under the |
| 8 | +* terms of the Eclipse Public License v1.0 which accompanies this distribution. |
| 9 | +* EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM |
| 10 | +* AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES |
| 11 | +* OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details. |
| 12 | +* |
| 13 | +* You should have received a copy of the Eclipse Public License v1.0 |
| 14 | +* along with this program; if not, you can obtain a copy from |
| 15 | +* https://www.eclipse.org/org/documents/epl-v10.php or |
| 16 | +* http://opensource.org/licenses/eclipse-1.0.php |
| 17 | +*/ |
| 18 | +package uk.ac.stfc.isis.ibex.utilities; |
| 19 | + |
| 20 | +import java.util.Properties; |
| 21 | + |
| 22 | +import net.bytebuddy.agent.VirtualMachine; |
| 23 | +import net.bytebuddy.agent.VirtualMachine.ForHotSpot; |
| 24 | +import net.bytebuddy.agent.VirtualMachine.ForOpenJ9; |
| 25 | + |
| 26 | +/** |
| 27 | + * This piece of code extracts the port on which the debugger is running. |
| 28 | + * Input required: Process Id of the running application. |
| 29 | + * |
| 30 | + * 1. Resolve the following dependencies in your class path: |
| 31 | + * .m2/repository/net/bytebuddy/byte-buddy/1.14.11/byte-buddy-1.14.11.jar |
| 32 | + * .m2/repository/net/bytebuddy/byte-buddy-agent/1.14.11/byte-buddy-agent-1.14.11.jar |
| 33 | + * .m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar |
| 34 | + * .m2/repository/net/java/dev/jna/jna-platform/5.12.1/jna-platform-5.12.1.jar |
| 35 | + * |
| 36 | + * 2. Change the variable processId to the process Id of the application. |
| 37 | + * You can check the Task Manager or add the following java code in your program to get the process Id: |
| 38 | + * System.out.println(String.format("Process Id: " + String.valueOf(ProcessHandle.current().pid()))); |
| 39 | + * |
| 40 | + * 3. You may also run using eclipse and configure the process Id as a run time argument |
| 41 | + * |
| 42 | + * @author Controls team |
| 43 | + * |
| 44 | + */ |
| 45 | +public class GetVMInfo { |
| 46 | + |
| 47 | + public static void main(String[] args) { |
| 48 | + String processId = "19999"; |
| 49 | + if (0 < args.length) { |
| 50 | + processId = args[args.length - 1]; |
| 51 | + System.out.println("Input processId: " + processId); |
| 52 | + } |
| 53 | + try { |
| 54 | + VirtualMachine jvm = ForHotSpot.attach(processId); |
| 55 | + Properties properties = jvm.getAgentProperties(); |
| 56 | + System.out.println(properties.toString()); |
| 57 | + System.out.println(properties.getProperty("sun.jdwp.listenerAddress")); |
| 58 | + } catch (Exception e) { |
| 59 | + System.out.println(e.getLocalizedMessage()); |
| 60 | + try { |
| 61 | + VirtualMachine jvm = ForOpenJ9.attach(processId); |
| 62 | + Properties properties = jvm.getAgentProperties(); |
| 63 | + System.out.println(properties.toString()); |
| 64 | + } catch (Exception e1) { |
| 65 | + System.out.println(e1.getLocalizedMessage()); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments