Homebrew CaskでCaskのアップデートのpull requestを送るのが自動化されてて便利だった
CONTRIBUTING.mdに書かれている通りだけど、Caskを新しいバージョンに更新しようと思ったとき、新しいバージョンを指定するだけでCaskファイルの変更とpull requestの作成まで自動的にやってくれるスクリプトcask-repairがあって便利だった。
以下はAtomを1.4.2に更新したときのログの抜粋。なおスクリプトの実行にはhub
コマンドのインストールと設定が必要。
$ brew install vitorgalvao/tiny-scripts/cask-repair $ cd "$(brew --repository)"/Library/Taps/caskroom/homebrew-cask $ hub fork # homebrew-caskをforkしてない場合 $ cask-repair --pull origin --push itiut atom # Caskの中身が表示された後、新しいバージョンを聞かれるので入力する Type the new version (or leave blank to abort) > 1.4.2 # diffが表示された後、これで良いか聞かれるので答える Is everything correct? You can also make further manual edits (y/n/e) y Submitting… Submitted (https://github.com/caskroom/homebrew-cask/pull/18104)
Atom + ruby-testでchrubyを使う
環境
bashの場合
chruby/share/chruby/chruby.sh
と chruby/share/chruby/auto.sh
を .bashrc
などで読み込んでいれば特に設定はいらない。
zshの場合
chruby/share/chruby/chruby.sh
と chruby/share/chruby/auto.sh
を .zshrc
などで読み込んだだけではダメで、各テストコマンドの前に chruby_auto &&
をつける必要がある。
RSpec について設定した config.cson
はこんな感じ。
"ruby-test": rspecAllCommand: "chruby_auto && rspec --tty spec" rspecFileCommand: "chruby_auto && rspec --tty {relative_path}" rspecSingleCommand: "chruby_auto && rspec --tty {relative_path}:{line_number}" shell: "zsh" specFramework: "rspec"
なぜ chruby_auto &&
が必要なのか
chruby_auto
は chruby/share/chruby/auto.sh
で定義されている関数で、ディレクトリを親方向にたどって .ruby-version
が見つかったら、chruby
でそのバージョンのrubyを使うようにする。
zshの場合は定義するとともに $preexec_functions
にも登録するので、各コマンドの実行前に自動で実行される*1。
ruby-test はテストコマンドをシェルを立ち上げて実行しているが、本来ならば実行されてほしい chruby_auto
が実行されていない。
$preexec_functions
に chruby_auto
が登録されていることは確認できたのだが、どうやら肝心の $preexec_functions
自体が実行されていないっぽい。
というところまでわかったのだが、これ以上はzsh力が足りなくて調べるのを断念した。
参照
CentOS 6.6 に Systemtap をインストールして動かす
CentOS 6.6 に Systemtap をインストールして動かすのにハマった話です。
インストール方法
最終的に以下のコマンドでインストールして再起動すると Systemtap を動かせました。
$ sudo yum install systemtap $ sudo yum --enablerepo=centosplus install kernel kernel-devel $ sudo yum --enablerepo=base-debuginfo install kernel-debuginfo
ハマった話
ビギナーズガイドによると systemtap を動かすには以下のパッケージが必要です*1。
これらのうち systemtap, systemtap-runtime, kernel-devel は CentOS 公式の Base リポジトリから提供されていて、kernel-debuginfo, kernel-debuginfo-common は Debuginfo リポジトリから提供されています。Debuginfo リポジトリはデフォルトでは有効になっていないので、yum
コマンド実行時にオプション--enablerepo=base-debuginfo
を付けて有効にする必要があります。
これらをインストールします。ただし、これでは動きません。
$ sudo yum install systemtap systemtap-runtime kernel-devel $ sudo yum --enablerepo=base-debuginfo install kernel-debuginfo kernel-debuginfo-common
インストール後に、ビギナーズガイドにあるテスト用のコマンド*2を実行してみます。
$ sudo stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}' Pass 1: parsed user script and 103 library script(s) using 201640virt/29512res/3148shr/26860data kb, in 120usr/60sys/257real ms. semantic error: while resolving probe point: identifier 'kernel' at /usr/share/systemtap/tapset/linux/vfs.stp:768:18 source: probe vfs.read = kernel.function("vfs_read") ^ semantic error: missing x86_64 kernel/module debuginfo [man warning::debuginfo] under '/lib/modules/2.6.32-504.12.2.el6.x86_64/build' semantic error: while resolving probe point: identifier 'vfs' at <input>:1:7 source: probe vfs.read {printf("read performed\n"); exit()} ^ semantic error: no match Pass 2: analyzed script: 0 probe(s), 0 function(s), 0 embed(s), 0 global(s) using 211904virt/39740res/5172shr/35020data kb, in 60usr/480sys/1967real ms. Pass 2: analysis failed. [man error::pass2]
何やら debuginfo が無いと言われます。
原因
ググったりしてもよく分からなかったのですが、kernel-debuginfo の info を見ると原因がわかりました。
$ yum --enablerepo=base-debuginfo info kernel-debuginfo Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Installed Packages Name : kernel-debuginfo Arch : x86_64 Version : 2.6.32 Release : 504.12.2.el6.centos.plus Size : 1.6 G Repo : installed From repo : base-debuginfo Summary : Debug information for package kernel URL : http://www.kernel.org/ License : GPLv2 Description : This package provides debug information for package kernel. : This is required to use SystemTap with kernel-2.6.32-504.12.2.el6.centos.plus.x86_64.
Description の部分に
This is required to use SystemTap with kernel-2.6.32-504.12.2.el6.centos.plus.x86_64.
とあるように、カーネルのリリース名に見慣れぬ centos.plus という文字があります。 これは現在のカーネルとは違っていました。
$ uname -r 2.6.32-504.12.2.el6.x86_64
調べてみると CentOSPlus というリポジトリでも kernel と kernel-devel が提供されています。リリース名も kernel-2.6.32-504.12.2.el6.centos.plus.x86_64 に一致します。
というわけで CentOSPlus リポジトリから kernel とkernel-devel をインストール。
$ sudo yum --enablerepo=centosplus install kernel kernel-devel
そして再起動した後再びテスト用コマンドを実行すると、うまく動きました。
$ sudo stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}' Pass 1: parsed user script and 103 library script(s) using 201672virt/29544res/3148shr/26892data kb, in 110usr/20sys/128real ms. Pass 2: analyzed script: 1 probe(s), 1 function(s), 3 embed(s), 0 global(s) using 296424virt/125164res/4124shr/121644data kb, in 990usr/200sys/1195real ms. Pass 3: translated to C into "/tmp/stap53301G/stap_2a362e40998232e8986eb51a4ebd96d9_1543_src.c" using 296424virt/125496res/4456shr/121644data kb, in 0usr/70sys/59real ms. Pass 4: compiled C into "stap_2a362e40998232e8986eb51a4ebd96d9_1543.ko" in 3670usr/1850sys/5836real ms. Pass 5: starting run. read performed Pass 5: run completed in 10usr/10sys/359real ms.
OProfile / Bugs / #263 Using operf with multiple events, samples may be attributed to wrong event
OProfile / Bugs / #263 Using operf with multiple events, samples may be attributed to wrong event
oprofile v0.9.9 でとあるバグに遭遇しました。operf
で複数のイベントを同時に取得した場合、opreport
の出力結果においてイベント名とその値が正しく関連付けられていないというものです。 このバグは oprofile v1.0.0 にて修正されています。
バグに遭遇した環境は CentOS 6.6, oprofile 0.9.9-6.el6_6 です。チケットで報告されているのと同じく、複数のイベントをそれぞれ単独に取得した場合と比較したとき、イベント名とその値の対応が正しくありませんでした。
2015/04/17 現在ではパッケージマネージャで提供される oprofile は v1.0.0 以前のものが多いかと思うので、注意が必要かもしれません。
以上、IPCを計測しようとしたらCPIになってしまったという結構深刻なバグでした。
sysstatコマンド群の時間表示をUNIX時間にする
やりたいこと
sysstat に含まれるコマンド (sar, iostat, mpstat, pidstat など) の時刻表示を、HH:mm:ss
のような表示ではなくUNIX時間にしたい。
理由
- 機械的に処理しやすくしてデータの加工やプロットを自動化したい
- pidstat で特定のプロセスの情報を取得して、他のコマンドでシステム全体の情報を取得して別々のファイルに出力したとき、時間をキーとしてマージしようと思ったら表記ゆれがあると割りと面倒
調査
sysstat v11.1.3 について少し調べてみた。
- pidstat
- sar
- mpstat
strftime
のフォーマットが%X
なので *4 、できない。- ただし mpstat の機能は sar で代用できると思われる。
- iostat
strftime
のフォーマットが%z
か%X
なので *5 、できない。- ただし iostat の機能は sar で代用できると思われる。
- cifsiostat, nfsiostat-sysstat
まとめ
pidstat はオプション-h
を使うと、sar はオプション-o
でバイナリを出力して sadf でオプション-U
を使うと、時間表示をUNIX時間にできる。
mpstat や iostat は今のところできないが、sar で代用すればいいと思う。
*1:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/pidstat.c#L1329
*2:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/pidstat.c#L2281-L2285
*3:詳しいところまでは追っていないが、たぶんこの辺り: https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/sadf.c#L249
*4:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/mpstat.c#L616-L620
*5:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/iostat.c#L1057-L1063
*6:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/cifsiostat.c#L460-L466
*7:https://github.com/sysstat/sysstat/blob/658d3687289abbf8b96c54f993e0d62967a32498/nfsiostat-sysstat.c#L526-L532
APUE 3rd Editionの写経の準備メモ
Advanced Programming in the UNIX Environment, 3rd Editionの写経のための準備メモ。
環境
OS X
$ gcc -v Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix
Ubuntu
$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.1-16ubuntu6' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.9.1 (Ubuntu 4.9.1-16ubuntu6)
ソースコード
http://www.apuebook.com/code3e.html からダウンロード
コンパイル
OS X
make
のコンパイルエラーを抜粋。
gcc -R. -o t4 t4.o -L../lib -L. -lapue_db -lapue clang: error: unknown argument: '-R.' make[1]: *** [t4] Error 1 make: *** [all] Error 1
-R.
のRの後のドットを取れば解決できるっぽい*1。
--- db/Makefile.orig 2015-03-08 05:45:46.000000000 +0900 +++ db/Makefile 2015-03-08 05:46:00.000000000 +0900 @@ -15,7 +15,7 @@ EXTRALD=-Wl,-rpath=. endif ifeq "$(PLATFORM)" "freebsd" - EXTRALD=-R. + EXTRALD=-R endif ifeq "$(PLATFORM)" "macos" EXTRALD=-R
Ubuntu
make
のコンパイルエラーを抜粋。
gcc -ansi -I../include -Wall -DLINUX -D_GNU_SOURCE badexit2.c -o badexit2 -L../lib -lapue -pthread -lrt -lbsd /usr/bin/ld: cannot find -lbsd collect2: error: ld returned 1 exit status Makefile:31: recipe for target 'badexit2' failed make[1]: *** [badexit2] Error 1
$ sudo apt-get install libbsd-dev
ヘッダとライブラリ
make
した後にヘッダとライブラリをコピー*3。
$ sudo cp include/apue.h /usr/local/include $ sudo cp lib/libapue.a /usr/local/lib
コンパイル時にオプションでライブラリを指定する。
$ gcc ls.c -lapue
サイボウズのLT大会で発表してきた
サイボウズが社内で開いているLT大会「技術Bar」に参加してLTしてきました。
「まだ黒い画面で消耗してるの?」というタイトルで、主にls
コマンドの出力を色付きにして見やすくする方法について話しました。
スライドを作ってから気がついたのですが、スライド作成時のk
コマンドは少しバージョンが古いもので、現在ではオプションがついたりと少しバージョンアップしていました。
技術Barについて
技術Barについては以下の記事で解説されています。
月に1回やっていて学生なら無料で参加できるようなので、学生の人は是非参加すると良いと思います!(ステマ)
働いているエンジニアと話せたり、社内の雰囲気を知れたりする良い機会になりました。
facebookページなどで開催のお知らせがあると思います。
サイボウズはもう16卒の新卒採用の選考が始まってますね。早くエントリーしなきゃ。