0%

运行Java VisualVM

执行命令

1
jvisualvm

JVisualVM启动成功后,如图所示:

安装Visual GC插件

点击 工具 -> 插件

选择设置标签,更新中心配置,也就是设置从哪里下载插件。

可以在 https://visualvm.github.io/pluginscenters.html 页面找到不同版本的插件源地址。

设置好以后,在可用插件标签下面,我们选择安装Visual GC插件。

安装好以后,重启Java VisualVM

就可以看到Visual GC的标签了。如下图所示:

当程序出现内存泄露(Out of memory)时,我们需要通过Eclipse的Memory Analyzer Tool去定位错误的代码。

从Eclipse官网下载MAT,https://www.eclipse.org/mat/downloads.php

选择不同操作的版本。

1
2
3
4
5
6
7
8
9
10
11
12
Memory Analyzer 1.8.1 Release
Version: 1.8.1.20180910 | Date: 19 September 2018 | Type: Released
Update Site: http://download.eclipse.org/mat/1.8.1/update-site/
Archived Update Site: MemoryAnalyzer-1.8.1.201809100846.zip
Stand-alone Eclipse RCP Applications
Windows (x86)
Windows (x86_64)
Mac OSX (Mac/Cocoa/x86_64)
Linux (x86/GTK+)
Linux (x86_64/GTK+)
Linux (PPC64/GTK+)
Linux (PPC64le/GTK+)

当我在Mac系统双击mat.app打开MAT时,系统报错,查看日志内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
!SESSION 2019-04-18 21:48:21.506 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_92
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=zh_CN
Framework arguments: -keyring /Users/simon/.eclipse_keyring
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -keyring /Users/simon/.eclipse_keyring

!ENTRY org.eclipse.osgi 4 0 2019-04-18 21:48:24.893
!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: The platform metadata area could not be written: /private/var/folders/cl/kn5ppbpd28j0s6y5kcxm9rdm0000gn/T/AppTranslocation/8157A927-01B7-4CF8-8F8B-AA4530391F8A/d/mat.app/Contents/MacOS/workspace/.metadata. By default the platform writes its content
under the current working directory when the platform is launched. Use the -data parameter to
specify a different content area for the platform.
at org.eclipse.core.internal.runtime.DataArea.assertLocationInitialized(DataArea.java:70)
...

查看日志,分析原因,我们得知其中一个文件无写入权限。IllegalStateException: The platform metadata area could not be written.

我们可以指定一个具有写入权限的文件夹,设置如下:

编辑文件 /Applications/mat.app/Contents/Eclipse/MemoryAnalyzer.ini

添加-data参数:

1
2
-data
/Users/simon/workspace

data参数和路径必须在两个不同的行,data参数必须放在Laucher之前。

最终文件内容如下所示:

1
2
3
4
5
6
7
8
9
10
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
-data
/Users/simon/workspace
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.700.v20180518-1200
-vmargs
-Xmx1024m
-Dorg.eclipse.swt.internal.carbon.smallFonts
-XstartOnFirstThread

保存文件后,再次双击启动MAT,软件可以成功打开了。

iTerm2

首先推荐安装iTerm2终端,可在官网 http://iterm2.com/ 免费下载安装。

安装oh-my-zsh

查看系统的shell

1
2
3
4
5
6
7
8
9
10
11
cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

bash是mac中terminal自带的shell,把它换成zsh,这个的功能要多得多。拥有语法高亮,命令行tab补全,自动提示符,显示Git仓库状态等功能。

1
chsh -s /bin/zsh

安装oh-my-zsh

使用curl安装oh-my-zsh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Cloning Oh My Zsh...
Cloning into '/Users/simon/.oh-my-zsh'...
remote: Enumerating objects: 1023, done.
remote: Counting objects: 100% (1023/1023), done.
remote: Compressing objects: 100% (940/940), done.
remote: Total 1023 (delta 23), reused 848 (delta 20), pack-reused 0
Receiving objects: 100% (1023/1023), 681.01 KiB | 5.00 KiB/s, done.
Resolving deltas: 100% (23/23), done.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!


Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us at https://twitter.com/ohmyzsh.

p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh.

安装成功。

如何切换主题就不在这里详述了。