Finology 大数据金融

通过大数据以量化金融

当程序出现内存泄露(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.

安装成功。

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

Jupyter有两种模式

命令模式

按Esc切换到命令模式,单元格的边框是蓝色的。这个模式下的常用快捷键(Shift-Enter可能是我们最常用的命令):

Enter : 转入编辑模式
Shift-Enter : 运行本单元,选中下个单元
Ctrl-Enter : 运行本单元
Alt-Enter : 运行本单元,在其下插入新单元
Y : 单元转入代码状态
M :单元转入markdown状态
R : 单元转入raw状态
1 : 设定 1 级标题
2 : 设定 2 级标题
3 : 设定 3 级标题
4 : 设定 4 级标题
5 : 设定 5 级标题
6 : 设定 6 级标题
Up : 选中上方单元
K : 选中上方单元
Down : 选中下方单元
J : 选中下方单元
Shift-K : 扩大选中上方单元
Shift-J : 扩大选中下方单元
A : 在上方插入新单元
B : 在下方插入新单元
X : 剪切选中的单元
C : 复制选中的单元
Shift-V : 粘贴到上方单元
V : 粘贴到下方单元
Z : 恢复删除的最后一个单元
D,D : 删除选中的单元
Shift-M : 合并选中的单元
Ctrl-S : 文件存盘
S : 文件存盘
L : 转换行号
O : 转换输出
Shift-O : 转换输出滚动
Esc : 关闭页面
Q : 关闭页面
H : 显示快捷键帮助
I,I : 中断Notebook内核
0,0 : 重启Notebook内核
Shift : 忽略
Shift-Space : 向上滚动
Space : 向下滚动

编辑模式

编辑模式按 Enter 键切换,这模式下单元格颜色是绿的:

Tab : 代码补全或缩进
Shift-Tab : 提示
Ctrl-] : 缩进
Ctrl-[ : 解除缩进
Ctrl-A : 全选
Ctrl-Z : 复原
Ctrl-Shift-Z : 再做
Ctrl-Y : 再做
Ctrl-Home : 跳到单元开头
Ctrl-Up : 跳到单元开头
Ctrl-End : 跳到单元末尾
Ctrl-Down : 跳到单元末尾
Ctrl-Left : 跳到左边一个字首
Ctrl-Right : 跳到右边一个字首
Ctrl-Backspace : 删除前面一个字
Ctrl-Delete : 删除后面一个字
Esc : 进入命令模式
Ctrl-M : 进入命令模式
Shift-Enter : 运行本单元,选中下一单元
Ctrl-Enter : 运行本单元
Alt-Enter : 运行本单元,在下面插入一单元
Ctrl-Shift– : 分割单元
Ctrl-Shift-Subtract : 分割单元
Ctrl-S : 文件存盘
Shift : 忽略
Up : 光标上移或转入上一单元
Down :光标下移或转入下一单元

0%