しおメモ

雑多な技術系ブログです。ニッチな内容が多いです。

Swiftのメソッドごとのコンパイル時間を表示するワンライナー

忙しい人向けに、.xcactivitylogからメソッドのコンパイル時間を抽出するワンライナーです。

gunzip -c -S .xcactivitylog hoge.xcactivitylog | perl -pe "s/\r/\n/g" | grep -E "^\d+\.\d+ms" | sort -nr | uniq | head -100

中身はただのgzipですが、\rが厄介なのでperlで処理しています。

% gunzip -c -S .xcactivitylog *.xcactivitylog | perl -pe "s/\r/\n/g" | grep -E "^\d+\.\d+ms" | sort -nr | uniq | head -100

227.21ms        .../Presentation/View/ToastView.swift:64:10 instance method showWithAnimation()
200.22ms        .../Utility/DependencyAssembly.swift:12:22  class method setup()
192.17ms        .../Presentation/ViewModel/Implementation/ColorSelectorViewModel.swift:75:10        instance method makeFlowLayout(with:)
...

もっと忙しい人向け

現在のディレクトリから最新のログを拾ってきます。便利〜♨

gunzip -c -S .xcactivitylog $(ls -lt | grep -E "\.xcactivitylog$" | head -1 | awk '{print $10}') | perl -pe "s/\r/\n/g" | grep -E "^\d+\.\d+ms" | sort -nr | uniq | head -100