Merge remote-tracking branch 'origin/master' into channel-server

pull/1490/merge^2
gongdewei 4 years ago
commit 2be609ec72

@ -195,15 +195,12 @@ public class TelnetConsole {
* arthas client
* process()arthas-boot使System.exit()
*
* @param telnetConsole
* @param cli
* @param args
* @param eotEventCallback Ctrl+D signals an End of Transmission (EOT) event
* @return status code
* @throws IOException
* @throws InterruptedException
*/
public static int process(String[] args, ActionListener eotEventCallback) throws IOException, InterruptedException {
public static int process(String[] args, ActionListener eotEventCallback) throws IOException {
// support mingw/cygw jline color
if (OSUtils.isCygwinOrMinGW()) {
System.setProperty("jline.terminal", System.getProperty("jline.terminal", "jline.UnixTerminal"));

@ -29,10 +29,16 @@ import com.taobao.middleware.cli.annotations.Summary;
* @author hengyunabc 2019-09-02
*
*/
// @formatter:off
@Name("vmoption")
@Summary("Display, and update the vm diagnostic options.")
@Description("\nExamples:\n" + " vmoption\n" + " vmoption PrintGCDetails\n" + " vmoption PrintGCDetails true\n"
+ Constants.WIKI + Constants.WIKI_HOME + "vmoption")
@Description("\nExamples:\n" +
" vmoption\n" +
" vmoption PrintGC\n" +
" vmoption PrintGC true\n" +
" vmoption PrintGCDetails true\n" +
Constants.WIKI + Constants.WIKI_HOME + "vmoption")
//@formatter:on
public class VMOptionCommand extends AnnotatedCommand {
private static final Logger logger = LoggerFactory.getLogger(VMOptionCommand.class);

@ -1,6 +1,8 @@
package com.taobao.arthas.core.command.monitor200;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.CodeSource;
import java.text.SimpleDateFormat;
@ -14,6 +16,7 @@ import java.util.concurrent.TimeUnit;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.taobao.arthas.common.IOUtils;
import com.taobao.arthas.common.OSUtils;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.command.model.ProfilerModel;
@ -30,6 +33,7 @@ import com.taobao.middleware.cli.annotations.Name;
import com.taobao.middleware.cli.annotations.Option;
import com.taobao.middleware.cli.annotations.Summary;
import arthas.VmTool;
import one.profiler.AsyncProfiler;
import one.profiler.Counter;
@ -243,6 +247,23 @@ public class ProfilerCommand extends AnnotatedCommand {
if (libPath != null) {
// load from arthas directory
// 尝试把lib文件复制到临时文件里避免多次attach时出现 Native Library already loaded in another classloader
FileOutputStream tmpLibOutputStream = null;
FileInputStream libInputStream = null;
try {
File tmpLibFile = File.createTempFile(VmTool.JNI_LIBRARY_NAME, null);
tmpLibOutputStream = new FileOutputStream(tmpLibFile);
libInputStream = new FileInputStream(new File(libPath));
IOUtils.copy(libInputStream, tmpLibOutputStream);
libPath = tmpLibFile.getAbsolutePath();
logger.debug("copy {} to {}", libPath, tmpLibFile);
} catch (Throwable e) {
logger.error("try to copy lib error! libPath: {}", libPath, e);
} finally {
IOUtils.close(libInputStream);
IOUtils.close(tmpLibOutputStream);
}
profiler = AsyncProfiler.getInstance(libPath);
} else {
if (OSUtils.isLinux() || OSUtils.isMac()) {

@ -957,15 +957,18 @@ public abstract class StringUtils {
return text.substring(pos + after.length());
}
// print|(ILjava/util/List;)V
public static String[] splitMethodInfo(String methodInfo) {
int index = methodInfo.indexOf('|');
return new String[] { methodInfo.substring(0, index), methodInfo.substring(index + 1, methodInfo.length()) };
}
// demo/MathGame|primeFactors|(I)Ljava/util/List;|24
public static String[] splitInvokeInfo(String invokeInfo) {
int index1 = invokeInfo.indexOf('|');
int index2 = invokeInfo.indexOf('|', index1 + 1);
int index3 = invokeInfo.indexOf('|', index2 + 1);
return new String[] { invokeInfo.substring(0, index1), invokeInfo.substring(index1 + 1, index2),
invokeInfo.substring(index2 + 1, invokeInfo.length()) };
invokeInfo.substring(index2 + 1, index3), invokeInfo.substring(index3 + 1, invokeInfo.length()) };
}
}

@ -17,12 +17,14 @@ public class SpyImplTest {
Assertions.assertThat(StringUtils.splitMethodInfo("a|b")).containsExactly("a", "b");
Assertions.assertThat(StringUtils.splitMethodInfo("xxxxxxxxxx|fffffffffff")).containsExactly("xxxxxxxxxx",
"fffffffffff");
Assertions.assertThat(StringUtils.splitMethodInfo("print|(ILjava/util/List;)V")).containsExactly("print",
"(ILjava/util/List;)V");
}
@Test
public void testSplitInvokeInfo() throws Throwable {
Assertions.assertThat(StringUtils.splitInvokeInfo("a|b|c")).containsExactly("a", "b", "c");
Assertions.assertThat(StringUtils.splitInvokeInfo("xxxxxxxxxx|fffffffffff|yyy")).containsExactly("xxxxxxxxxx",
"fffffffffff", "yyy");
Assertions.assertThat(StringUtils.splitInvokeInfo("demo/MathGame|primeFactors|(I)Ljava/util/List;|24"))
.containsExactly("demo/MathGame", "primeFactors", "(I)Ljava/util/List;", "24");
}
}

@ -40,16 +40,26 @@ vmoption
#### View individual option
```bash
[arthas@56963]$ vmoption PrintGCDetails
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------------------
PrintGCDetails false MANAGEMENT true
$ vmoption PrintGC
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------
PrintGC false MANAGEMENT true
```
#### Update individual option
```bash
[arthas@56963]$ vmoption PrintGCDetails true
$ vmoption PrintGC true
Successfully updated the vm option.
PrintGCDetails=true
NAME BEFORE-VALUE AFTER-VALUE
------------------------------------
PrintGC false true
```
```bash
$ vmoption PrintGCDetails true
Successfully updated the vm option.
NAME BEFORE-VALUE AFTER-VALUE
-------------------------------------------
PrintGCDetails false true
```

@ -79,4 +79,6 @@ vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.
```bash
vmtool --action forceGc
```
```
* Use the [`vmoption`](vmoption.md) command to dynamically turn on the `PrintGC` option.

@ -40,16 +40,26 @@ vmoption
#### 查看指定的option
```bash
[arthas@56963]$ vmoption PrintGCDetails
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------------------
PrintGCDetails false MANAGEMENT true
$ vmoption PrintGC
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------
PrintGC false MANAGEMENT true
```
#### 更新指定的option
```bash
[arthas@56963]$ vmoption PrintGCDetails true
$ vmoption PrintGC true
Successfully updated the vm option.
NAME BEFORE-VALUE AFTER-VALUE
------------------------------------
PrintGC false true
```
```bash
$ vmoption PrintGCDetails true
Successfully updated the vm option.
PrintGCDetails=true
NAME BEFORE-VALUE AFTER-VALUE
-------------------------------------------
PrintGCDetails false true
```

@ -80,4 +80,6 @@ vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.
```bash
vmtool --action forceGc
```
```
* 可以结合 [`vmoption`](vmoption.md) 命令动态打开`PrintGC`开关。

@ -13,8 +13,8 @@
Examples:
vmoption
vmoption PrintGCDetails
vmoption PrintGCDetails true
vmoption PrintGC
vmoption PrintGC true
WIKI:
https://arthas.aliyun.com/doc/vmoption
@ -61,35 +61,53 @@
### 查看指定的option
`vmoption PrintGCDetails`{{execute T2}}
`vmoption PrintGC`{{execute T2}}
```bash
[arthas@56963]$ vmoption PrintGCDetails
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------------------
PrintGCDetails false MANAGEMENT true
$ vmoption PrintGC
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------
PrintGC false MANAGEMENT true
```
### 更新指定的option
`vmoption PrintGCDetails true`{{execute T2}}
`vmoption PrintGC true`{{execute T2}}
```bash
[arthas@56963]$ vmoption PrintGCDetails true
$ vmoption PrintGC true
Successfully updated the vm option.
PrintGCDetails=true
NAME BEFORE-VALUE AFTER-VALUE
------------------------------------
PrintGC false true
```
再使用`vmtool`命令执行强制GC则可以在`Terminal 1`看到打印出GC日志
`vmtool --action forceGc`{{execute T2}}
```
[GC (JvmtiEnv ForceGarbageCollection) 33752K->19564K(251392K), 0.0082960 secs]
[Full GC (JvmtiEnv ForceGarbageCollection) 19564K->17091K(166912K), 0.0271085 secs]
```
此时切换到arthas demo 运行所在的`Terminal`,使用`Ctrl+c`退出发现比之前多打印了GC垃圾回收信息
### 配置打印GC详情
`vmoption PrintGCDetails true`{{execute T2}}
```bash
Heap
def new generation total 10432K, used 5682K [0x00000000f4800000, 0x00000000f5350000, 0x00000000f8550000)
eden space 9280K, 61% used [0x00000000f4800000, 0x00000000f4d8cad0, 0x00000000f5110000)
from space 1152K, 0% used [0x00000000f5110000, 0x00000000f5110000, 0x00000000f5230000)
to space 1152K, 0% used [0x00000000f5230000, 0x00000000f5230000, 0x00000000f5350000)
tenured generation total 22992K, used 13795K [0x00000000f8550000, 0x00000000f9bc4000, 0x0000000100000000)
the space 22992K, 59% used [0x00000000f8550000, 0x00000000f92c8cc8, 0x00000000f92c8e00, 0x00000000f9bc4000)
Metaspace used 14926K, capacity 15128K, committed 15360K, reserved 1062912K
class space used 1895K, capacity 1954K, committed 2048K, reserved 1048576K
$ vmoption PrintGCDetails true
Successfully updated the vm option.
NAME BEFORE-VALUE AFTER-VALUE
-------------------------------------------
PrintGCDetails false true
```
再使用`vmtool`命令执行强制GC则可以在`Terminal 1`看到打印出GC详情
`vmtool --action forceGc`{{execute T2}}
```
[GC (JvmtiEnv ForceGarbageCollection) [PSYoungGen: 4395K->352K(76288K)] 21487K->17443K(166912K), 0.0013122 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (JvmtiEnv ForceGarbageCollection) [PSYoungGen: 352K->0K(76288K)] [ParOldGen: 17091K->16076K(88064K)] 17443K->16076K(164352K), [Metaspace: 20651K->20651K(1069056K)], 0.0251548 secs] [Times: user=0.15 sys=0.01, real=0.02 secs]
```

@ -13,8 +13,8 @@ Display, and update the vm diagnostic options.
Examples:
vmoption
vmoption PrintGCDetails
vmoption PrintGCDetails true
vmoption PrintGC
vmoption PrintGC true
WIKI:
https://arthas.aliyun.com/doc/vmoption
@ -71,25 +71,42 @@ Display, and update the vm diagnostic options.
```
### Update individual option
`vmoption PrintGC true`{{execute T2}}
```bash
$ vmoption PrintGC true
Successfully updated the vm option.
NAME BEFORE-VALUE AFTER-VALUE
------------------------------------
PrintGC false true
```
Then use the `vmtool` command to force GC, you can see the GC log printed in `Terminal 1`:
`vmtool --action forceGc`{{execute T2}}
```
[GC (JvmtiEnv ForceGarbageCollection) 33752K->19564K(251392K), 0.0082960 secs]
[Full GC (JvmtiEnv ForceGarbageCollection) 19564K->17091K(166912K), 0.0271085 secs]
```
### Configure print GC details
`vmoption PrintGCDetails true`{{execute T2}}
```bash
[arthas@56963]$ vmoption PrintGCDetails true
$ vmoption PrintGCDetails true
Successfully updated the vm option.
PrintGCDetails=true
NAME BEFORE-VALUE AFTER-VALUE
-------------------------------------------
PrintGCDetails false true
```
Nowif we switch to the `Terminal` where arthas demo is runningand use `Ctrl+c` to exityou will find it prints out Garbage Collection details
Then use the `vmtool` command to force GC, you can see the GC details printed in `Terminal 1`:
`vmtool --action forceGc`{{execute T2}}
```bash
Heap
def new generation total 10432K, used 5682K [0x00000000f4800000, 0x00000000f5350000, 0x00000000f8550000)
eden space 9280K, 61% used [0x00000000f4800000, 0x00000000f4d8cad0, 0x00000000f5110000)
from space 1152K, 0% used [0x00000000f5110000, 0x00000000f5110000, 0x00000000f5230000)
to space 1152K, 0% used [0x00000000f5230000, 0x00000000f5230000, 0x00000000f5350000)
tenured generation total 22992K, used 13795K [0x00000000f8550000, 0x00000000f9bc4000, 0x0000000100000000)
the space 22992K, 59% used [0x00000000f8550000, 0x00000000f92c8cc8, 0x00000000f92c8e00, 0x00000000f9bc4000)
Metaspace used 14926K, capacity 15128K, committed 15360K, reserved 1062912K
class space used 1895K, capacity 1954K, committed 2048K, reserved 1048576K
```
[GC (JvmtiEnv ForceGarbageCollection) [PSYoungGen: 4395K->352K(76288K)] 21487K->17443K(166912K), 0.0013122 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (JvmtiEnv ForceGarbageCollection) [PSYoungGen: 352K->0K(76288K)] [ParOldGen: 17091K->16076K(88064K)] 17443K->16076K(164352K), [Metaspace: 20651K->20651K(1069056K)], 0.0251548 secs] [Times: user=0.15 sys=0.01, real=0.02 secs]
```
Loading…
Cancel
Save