summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Moreira Zinsly <rzinsly@linux.vnet.ibm.com>2014-04-08 17:42:17 -0300
committerAliaksey Kandratsenka <alk@tut.by>2014-04-12 11:14:42 -0700
commit49237462c8ae7920332c1034c623e57b50a6109c (patch)
tree79e83b5b96152ea6ef202e60144c47e3c84564e3
parenta1ae66ef110bd87ff97903e86fd84c745db24646 (diff)
downloadgperftools-49237462c8ae7920332c1034c623e57b50a6109c.tar.gz
Fixed the way that pprof packed profile data in BE.
pprof was writing profile data in a way that only works for little-endian files, this patch verifies if the system is big-endian and writes packed data correctly.
-rwxr-xr-xsrc/pprof26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/pprof b/src/pprof
index 720a431..26860f5 100755
--- a/src/pprof
+++ b/src/pprof
@@ -1079,10 +1079,15 @@ sub TempName {
# Print profile data in packed binary format (64-bit) to standard out
sub PrintProfileData {
my $profile = shift;
-
+ my $big_endian = pack("L", 1) eq pack("N", 1);
# print header (64-bit style)
# (zero) (header-size) (version) (sample-period) (zero)
- print pack('L*', 0, 0, 3, 0, 0, 0, 1, 0, 0, 0);
+ if ($big_endian) {
+ print pack('L*', 0, 0, 0, 3, 0, 0, 0, 1, 0, 0);
+ }
+ else {
+ print pack('L*', 0, 0, 3, 0, 0, 0, 1, 0, 0, 0);
+ }
foreach my $k (keys(%{$profile})) {
my $count = $profile->{$k};
@@ -1091,8 +1096,14 @@ sub PrintProfileData {
my $depth = $#addrs + 1;
# int(foo / 2**32) is the only reliable way to get rid of bottom
# 32 bits on both 32- and 64-bit systems.
- print pack('L*', $count & 0xFFFFFFFF, int($count / 2**32));
- print pack('L*', $depth & 0xFFFFFFFF, int($depth / 2**32));
+ if ($big_endian) {
+ print pack('L*', int($count / 2**32), $count & 0xFFFFFFFF);
+ print pack('L*', int($depth / 2**32), $depth & 0xFFFFFFFF);
+ }
+ else {
+ print pack('L*', $count & 0xFFFFFFFF, int($count / 2**32));
+ print pack('L*', $depth & 0xFFFFFFFF, int($depth / 2**32));
+ }
foreach my $full_addr (@addrs) {
my $addr = $full_addr;
@@ -1103,7 +1114,12 @@ sub PrintProfileData {
}
my $low_addr = substr($addr, -8); # get last 8 hex chars
my $high_addr = substr($addr, -16, 8); # get up to 8 more hex chars
- print pack('L*', hex('0x' . $low_addr), hex('0x' . $high_addr));
+ if ($big_endian) {
+ print pack('L*', hex('0x' . $high_addr), hex('0x' . $low_addr));
+ }
+ else {
+ print pack('L*', hex('0x' . $low_addr), hex('0x' . $high_addr));
+ }
}
}
}