您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

diffsize.pl 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/perl -w
  2. # usage:
  3. # [somebody@somewhere ~/ipxe/src]$ ./util/diffsize.pl [<old rev> [<new rev>]]
  4. # by default <old rev> is HEAD and <new rev> is the working tree
  5. use strict;
  6. -d "bin" or die "Please run me in the iPXE src directory\n";
  7. mkdir ".sizes";
  8. my($oldrev, $newrev);
  9. my($oldname, $newname);
  10. if (@ARGV) {
  11. $oldname = shift;
  12. } else {
  13. $oldname = "HEAD";
  14. }
  15. if (@ARGV) {
  16. $newname = shift;
  17. } else {
  18. $newrev = "tree" . time();
  19. }
  20. $oldrev = `git rev-parse $oldname`;
  21. chomp $oldrev;
  22. unless (defined $newrev) {
  23. $newrev = `git rev-parse $newname`;
  24. chomp $newrev;
  25. }
  26. sub calc_sizes($$) {
  27. my($name, $rev) = @_;
  28. my $output;
  29. my $lastrev;
  30. my $stashed = 0;
  31. my $res = 0;
  32. return if -e ".sizes/$rev.sizes";
  33. if (defined $name) {
  34. $output = `git stash`;
  35. $stashed = 1 unless $output =~ /No local changes to save/;
  36. $lastrev = `git name-rev --name-only HEAD`;
  37. system("git checkout $name >/dev/null"); $res ||= $?;
  38. }
  39. system("make -j4 bin/ipxe.lkrn >/dev/null"); $res ||= $?;
  40. system("make bin/ipxe.lkrn.sizes > .sizes/$rev.sizes"); $res ||= $?;
  41. if (defined $name) {
  42. system("git checkout $lastrev >/dev/null"); $res ||= $?;
  43. system("git stash pop >/dev/null") if $stashed; $res ||= $?;
  44. }
  45. if ($res) {
  46. unlink(".sizes/$rev.sizes");
  47. die "Error making sizes file\n";
  48. }
  49. }
  50. our %Sizes;
  51. sub save_sizes($$) {
  52. my($id, $rev) = @_;
  53. my $file = ".sizes/$rev.sizes";
  54. open SIZES, $file or die "opening $file: $!\n";
  55. while (<SIZES>) {
  56. my($text, $data, $bss, $total, $hex, $name) = split;
  57. $name =~ s|bin/||; $name =~ s|\.o$||;
  58. # Skip the header and totals lines
  59. next if $total =~ /[a-z]/ or $name =~ /TOTALS/;
  60. # Skip files named with dash, due to old Makefile bug
  61. next if $name =~ /-/;
  62. $Sizes{$name} = {old => 0, new => 0} unless exists $Sizes{$name};
  63. $Sizes{$name}{$id} = $total;
  64. }
  65. }
  66. calc_sizes($oldname, $oldrev);
  67. calc_sizes($newname, $newrev);
  68. save_sizes('old', $oldrev);
  69. save_sizes('new', $newrev);
  70. my $total = 0;
  71. for (sort keys %Sizes) {
  72. my $diff = $Sizes{$_}{new} - $Sizes{$_}{old};
  73. if (abs($diff) >= 16) {
  74. printf "%12s %+d\n", substr($_, 0, 12), $Sizes{$_}{new} - $Sizes{$_}{old};
  75. }
  76. $total += $diff;
  77. }
  78. printf " TOTAL: %+d\n", $total;