2020-09-02 10:44:13 +02:00
|
|
|
{
|
|
|
|
stdenv
|
|
|
|
, bash
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
2020-09-02 17:07:09 +02:00
|
|
|
program
|
2020-09-02 10:44:13 +02:00
|
|
|
, outputDir ? "."
|
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
2020-09-02 17:07:09 +02:00
|
|
|
name = "statspy";
|
2020-09-02 10:44:13 +02:00
|
|
|
preferLocalBuild = true;
|
|
|
|
phases = [ "installPhase" ];
|
2020-09-02 17:07:09 +02:00
|
|
|
programPath = "/bin/${name}";
|
2020-09-02 10:44:13 +02:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2020-09-02 17:07:09 +02:00
|
|
|
cat > $out/bin/${name} <<EOF
|
2020-09-02 10:44:13 +02:00
|
|
|
#!${bash}/bin/bash
|
|
|
|
|
|
|
|
mkdir -p ${outputDir}
|
|
|
|
cat /proc/[0-9]*/stat | sort -n > ${outputDir}/statspy.\$(date +%s.%3N).begin
|
2020-09-02 17:07:09 +02:00
|
|
|
${program}
|
2020-09-02 10:44:13 +02:00
|
|
|
cat /proc/[0-9]*/stat | sort -n > ${outputDir}/statspy.\$(date +%s.%3N).end
|
|
|
|
|
|
|
|
EOF
|
2020-09-02 17:07:09 +02:00
|
|
|
chmod +x $out/bin/${name}
|
2020-09-02 10:44:13 +02:00
|
|
|
'';
|
|
|
|
}
|