Guest User

count-instruction.pl

a guest
Nov 2nd, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.88 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. my @binaries = qw[
  5.     /boot/vmlinuz-linux
  6.     /usr/bin/bash
  7.     /usr/bin/tar
  8.     /usr/bin/gzip
  9.     /usr/bin/geany
  10.     /usr/bin/python
  11.     /usr/bin/perl
  12.     /usr/bin/thunar
  13.     /usr/bin/firefox
  14.     /usr/lib/xorg/modules/drivers/radeon_drv.so
  15.     /usr/bin/git
  16. ];
  17.  
  18. for my $input (sort @binaries) {
  19.     my $objtype = `objdump -f $input 2>&1`;
  20.     if (! -e $input or $objtype =~ /not recognized/) {
  21.         warn "Skipping $input.\n";
  22.         next;
  23.     }
  24.  
  25.     open DUMP, "-|", "objdump -d $input";
  26.  
  27.     my $sum = 0;
  28.     my $count = 0;
  29.     for (<DUMP>) {
  30.       next if /\(bad\)/;
  31.       next unless /:\t([^\t]*)\t/;
  32.       $sum += scalar(split / /, ($1 =~ s/ *$//r));
  33.       ++$count;
  34.     }
  35.     if ($count == 0) {
  36.       warn "No operations found in $input.\n";
  37.       next;
  38.     }
  39.     print "Average for $input = ", $sum / $count, "\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment