| OLD | NEW |
| 1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 return true; | 672 return true; |
| 673 } | 673 } |
| 674 | 674 |
| 675 static bool ParseProcMapsLine(char *text, uint64 *start, uint64 *end, | 675 static bool ParseProcMapsLine(char *text, uint64 *start, uint64 *end, |
| 676 char *flags, uint64 *offset, | 676 char *flags, uint64 *offset, |
| 677 int *major, int *minor, int64 *inode, | 677 int *major, int *minor, int64 *inode, |
| 678 unsigned *filename_offset) { | 678 unsigned *filename_offset) { |
| 679 #if defined(__linux__) | 679 #if defined(__linux__) |
| 680 /* | 680 /* |
| 681 * It's similar to: | 681 * It's similar to: |
| 682 * sscanf(text, "%"SCNx64"-%"SCNx64" %4s %"SCNx64" %x:%x %"SCNd64" %n", | 682 * sscanf(text,"%" SCNx64 "-%" SCNx64 " %4s %" SCNx64 " %x:%x %" SCNd64 " %n", |
| 683 * start, end, flags, offset, major, minor, inode, filename_offset) | 683 * start, end, flags, offset, major, minor, inode, filename_offset) |
| 684 */ | 684 */ |
| 685 char *endptr = text; | 685 char *endptr = text; |
| 686 if (endptr == NULL || *endptr == '\0') return false; | 686 if (endptr == NULL || *endptr == '\0') return false; |
| 687 | 687 |
| 688 if (!StringToIntegerUntilCharWithCheck(start, endptr, 16, '-', &endptr)) | 688 if (!StringToIntegerUntilCharWithCheck(start, endptr, 16, '-', &endptr)) |
| 689 return false; | 689 return false; |
| 690 | 690 |
| 691 if (!StringToIntegerUntilCharWithCheck(end, endptr, 16, ' ', &endptr)) | 691 if (!StringToIntegerUntilCharWithCheck(end, endptr, 16, ' ', &endptr)) |
| 692 return false; | 692 return false; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 int paren_count = 0; | 936 int paren_count = 0; |
| 937 while (--backing_ptr > stext_) { | 937 while (--backing_ptr > stext_) { |
| 938 if (*backing_ptr == '(') { | 938 if (*backing_ptr == '(') { |
| 939 ++paren_count; | 939 ++paren_count; |
| 940 if (paren_count >= 2) { | 940 if (paren_count >= 2) { |
| 941 uint64 tmp_file_mapping; | 941 uint64 tmp_file_mapping; |
| 942 uint64 tmp_file_pages; | 942 uint64 tmp_file_pages; |
| 943 uint64 tmp_anon_mapping; | 943 uint64 tmp_anon_mapping; |
| 944 uint64 tmp_anon_pages; | 944 uint64 tmp_anon_pages; |
| 945 | 945 |
| 946 sscanf(backing_ptr+1, "F %"SCNx64" %"SCNd64") (A %"SCNx64" %"SCNd64"
)", | 946 sscanf(backing_ptr+1, |
| 947 "F %" SCNx64 " %" SCNd64 ") (A %" SCNx64 " %" SCNd64 ")", |
| 947 file_mapping ? file_mapping : &tmp_file_mapping, | 948 file_mapping ? file_mapping : &tmp_file_mapping, |
| 948 file_pages ? file_pages : &tmp_file_pages, | 949 file_pages ? file_pages : &tmp_file_pages, |
| 949 anon_mapping ? anon_mapping : &tmp_anon_mapping, | 950 anon_mapping ? anon_mapping : &tmp_anon_mapping, |
| 950 anon_pages ? anon_pages : &tmp_anon_pages); | 951 anon_pages ? anon_pages : &tmp_anon_pages); |
| 951 // null terminate the file name (there is a space | 952 // null terminate the file name (there is a space |
| 952 // before the first (. | 953 // before the first (. |
| 953 backing_ptr[-1] = 0; | 954 backing_ptr[-1] = 0; |
| 954 break; | 955 break; |
| 955 } | 956 } |
| 956 } | 957 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 const char *filename, dev_t dev) { | 1077 const char *filename, dev_t dev) { |
| 1077 // We assume 'flags' looks like 'rwxp' or 'rwx'. | 1078 // We assume 'flags' looks like 'rwxp' or 'rwx'. |
| 1078 char r = (flags && flags[0] == 'r') ? 'r' : '-'; | 1079 char r = (flags && flags[0] == 'r') ? 'r' : '-'; |
| 1079 char w = (flags && flags[0] && flags[1] == 'w') ? 'w' : '-'; | 1080 char w = (flags && flags[0] && flags[1] == 'w') ? 'w' : '-'; |
| 1080 char x = (flags && flags[0] && flags[1] && flags[2] == 'x') ? 'x' : '-'; | 1081 char x = (flags && flags[0] && flags[1] && flags[2] == 'x') ? 'x' : '-'; |
| 1081 // p always seems set on linux, so we set the default to 'p', not '-' | 1082 // p always seems set on linux, so we set the default to 'p', not '-' |
| 1082 char p = (flags && flags[0] && flags[1] && flags[2] && flags[3] != 'p') | 1083 char p = (flags && flags[0] && flags[1] && flags[2] && flags[3] != 'p') |
| 1083 ? '-' : 'p'; | 1084 ? '-' : 'p'; |
| 1084 | 1085 |
| 1085 const int rc = snprintf(buffer, bufsize, | 1086 const int rc = snprintf(buffer, bufsize, |
| 1086 "%08"PRIx64"-%08"PRIx64" %c%c%c%c %08"PRIx64" %02x:%02
x %-11"PRId64" %s\n", | 1087 "%08" PRIx64 "-%08" PRIx64 " %c%c%c%c %08" PRIx64 " " |
| 1088 "%02x:%02x %-11" PRId64 " %s\n", |
| 1087 start, end, r,w,x,p, offset, | 1089 start, end, r,w,x,p, offset, |
| 1088 static_cast<int>(dev/256), static_cast<int>(dev%256), | 1090 static_cast<int>(dev/256), static_cast<int>(dev%256), |
| 1089 inode, filename); | 1091 inode, filename); |
| 1090 return (rc < 0 || rc >= bufsize) ? 0 : rc; | 1092 return (rc < 0 || rc >= bufsize) ? 0 : rc; |
| 1091 } | 1093 } |
| 1092 | 1094 |
| 1093 namespace tcmalloc { | 1095 namespace tcmalloc { |
| 1094 | 1096 |
| 1095 // Helper to add the list of mapped shared libraries to a profile. | 1097 // Helper to add the list of mapped shared libraries to a profile. |
| 1096 // Fill formatted "/proc/self/maps" contents into buffer 'buf' of size 'size' | 1098 // Fill formatted "/proc/self/maps" contents into buffer 'buf' of size 'size' |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 ProcMapsIterator::Buffer linebuf; | 1135 ProcMapsIterator::Buffer linebuf; |
| 1134 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { | 1136 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { |
| 1135 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), | 1137 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), |
| 1136 start, end, flags, offset, inode, filename, | 1138 start, end, flags, offset, inode, filename, |
| 1137 0); | 1139 0); |
| 1138 RawWrite(fd, linebuf.buf_, written); | 1140 RawWrite(fd, linebuf.buf_, written); |
| 1139 } | 1141 } |
| 1140 } | 1142 } |
| 1141 | 1143 |
| 1142 } // namespace tcmalloc | 1144 } // namespace tcmalloc |
| OLD | NEW |