]> git.sur5r.net Git - i3/i3status/blob - testcases/010-cpu-usage/setup.pl
Merge pull request #315 from gportay/fix-typo-in-man
[i3/i3status] / testcases / 010-cpu-usage / setup.pl
1 #!/usr/bin/env perl
2
3 use v5.10;
4 use strict;
5 use warnings;
6
7 if ($#ARGV != 0 || ! -d $ARGV[0]) {
8     say "Error with setup script: argument not provided or not a directory";
9     exit 1;
10 }
11
12 chomp(my $cpu_count = `grep -c -P '^processor\\s+:' /proc/cpuinfo`);
13 my $output_file = "$ARGV[0]/stat";
14 open(my $fh, '>', $output_file) or die "Could not open file '$output_file' $!";
15 print $fh "cpu  0 0 0 0 0 0 0 0 0 0\n";
16 print $fh "cpu0 100 0 0 0 0 0 0 0 0 0\n";
17 if ($cpu_count > 1) {
18     print $fh "cpu1 50 0 0 50 0 0 0 0 0 0\n";
19     for (my $i = 2; $i <= $cpu_count; $i++) {
20         print $fh "cpu$i 0 0 0 0 0 0 0 0 0 0\n";
21     }
22 }
23 close $fh;