LoginSignup
1
1

More than 5 years have passed since last update.

WindowsでNYTProfを利用してPerlプログラムの実行を解析する

Last updated at Posted at 2016-06-08

あるお客様からのオーダーでバッチに9時間かかるというので、
調査した時の検証基礎資料。

ActivePerlをインストール

ここからOSバージョンに合わせてActivePerlをインストール
http://www.activestate.com/activeperl/downloads

ppmを利用して、NYTProfをインストール

NYTProfのサポートバージョンを確認する

NYTProfのサポートバージョンを確認する。

NYTProf
https://code.activestate.com/ppm/Devel-NYTProf/

コマンドプロンプトを管理者権限で起動する

管理者権限で『cmd』コマンドを実行する

一般ユーザー権限だとppmコマンドは利用できなかった

C:\Users\システム管理者>ppm
'ppm' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

NYTProfコマンドをインストールする

ppm

Perl Package Managerが起動するので、
GUIにてプログラムをインストールする

image

ユーザー名が日本語入りの場合、以下のようなエラーが出る。

C:\WINDOWS\system32>ppm
ppm gui failed: DBI connect('dbname=C:\Users\システ~1\AppData\Local/ActiveState/ActivePerl/2201/ppm-MSWin32-x64-multi-thread-5_22.db','',...) failed: unable to open database file

その場合には以下のようにディレクトリを新規作成して、パスを指定すると良い

C:\WINDOWS\system32>MKDIR C:\Perl\ppm
C:\WINDOWS\system32>SET ACTIVEPERL_PPM_HOME=C:\Perl\ppm

CUIでインストールも出来るらしい(未確認)

※未確認
C:\WINDOWS\system32>ppm-shell
ppm 4.20 (ActivePerl 2201)
Copyright (C) 2013 ActiveState Software Inc.  All rights reserved.
ppm> install Devel-NYTProf

プロファイリングを実行する

サンプルスクリプト作成

以下のファイルを『C:\Perl\sample.pl』に作成する

perl
print "hello, world\n";

プロファイリング作成

C:\WINDOWS\system32>C:\Perl64\bin\perl -d:NYTProf C:\Perl\sample.pl
hello, world

プロファイリングレポート作成

C:\WINDOWS\system32>nytprofhtml
No such signal: SIGUSR2 at C:\Perl64\bin/nytprofhtml line 162.
Reading nytprof.out
Processing nytprof.out data
Writing line reports to nytprof directory
 100% ...
Extracting subroutine call data ...
Extracting subroutine links
Generating subroutine stack flame graph ...

Windowsのプロファイルファイル、レポートファイルの保存場所は初期が以下になる

トレースファイル
C:\Windows\System32\nytprof.out
レポートファイル
C:\Windows\System32\nytprof\index.html

プロファイリングレポートファイルの閲覧

systemフォルダのファイルをブラウザでは閲覧できない為、フォルダ移動をして確認を行う。

C:\WINDOWS\system32>xcopy C:\Windows\System32\nytprof C:\Perl\report
C:\Windows\System32\nytprof\all_stacks_by_time.calls
C:\Windows\System32\nytprof\all_stacks_by_time.svg
C:\Windows\System32\nytprof\C-Perl-sample-pl-1-line.html
C:\Windows\System32\nytprof\flamegraph_subattr.txt
C:\Windows\System32\nytprof\index-subs-excl.html
C:\Windows\System32\nytprof\index.html
C:\Windows\System32\nytprof\packages-callgraph.dot
C:\Windows\System32\nytprof\style.css
C:\Windows\System32\nytprof\subs-callgraph.dot
C:\Windows\System32\nytprof\subs-treemap-excl.html
10 個のファイルをコピーしました

C:\Windows\System32\nytprof\index.html

をブラウザで開く

サンプル出力結果
https://dl.dropboxusercontent.com/u/4127244/report/index.html

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1