OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/cygprofile/cygprofile.h" | 5 #include "tools/cygprofile/cygprofile.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
9 #include <sys/stat.h> | 11 #include <sys/stat.h> |
10 #include <sys/syscall.h> | 12 #include <sys/syscall.h> |
11 #include <sys/time.h> | 13 #include <sys/time.h> |
12 #include <sys/types.h> | 14 #include <sys/types.h> |
13 | 15 |
14 #include <cstdio> | 16 #include <cstdio> |
15 #include <fstream> | 17 #include <fstream> |
16 #include <string> | 18 #include <string> |
17 #include <vector> | 19 #include <vector> |
18 | 20 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 80 |
79 const std::string value; | 81 const std::string value; |
80 | 82 |
81 private: | 83 private: |
82 // Returns whether the integer representation of the hexadecimal address | 84 // Returns whether the integer representation of the hexadecimal address |
83 // stored in |line| at position |start_offset| was successfully stored in | 85 // stored in |line| at position |start_offset| was successfully stored in |
84 // |result|. | 86 // |result|. |
85 static bool ParseAddress(const std::string& line, | 87 static bool ParseAddress(const std::string& line, |
86 size_t start_offset, | 88 size_t start_offset, |
87 size_t length, | 89 size_t length, |
88 uint64* result) { | 90 uint64_t* result) { |
89 if (start_offset >= line.length()) | 91 if (start_offset >= line.length()) |
90 return false; | 92 return false; |
91 | 93 |
92 uint64 address; | 94 uint64_t address; |
93 const bool ret = HexStringToUInt64( | 95 const bool ret = HexStringToUInt64( |
94 base::StringPiece(line.c_str() + start_offset, length), &address); | 96 base::StringPiece(line.c_str() + start_offset, length), &address); |
95 if (!ret) | 97 if (!ret) |
96 return false; | 98 return false; |
97 | 99 |
98 *result = address; | 100 *result = address; |
99 return true; | 101 return true; |
100 } | 102 } |
101 | 103 |
102 // Parses /proc/self/maps and returns a two line string such as: | 104 // Parses /proc/self/maps and returns a two line string such as: |
103 // 758c6000-79f4b000 r-xp 00000000 b3:17 309475 libchrome.2009.0.so | 105 // 758c6000-79f4b000 r-xp 00000000 b3:17 309475 libchrome.2009.0.so |
104 // secs usecs pid:threadid func | 106 // secs usecs pid:threadid func |
105 static std::string MakeFileHeaderLine() { | 107 static std::string MakeFileHeaderLine() { |
106 std::ifstream mapsfile("/proc/self/maps"); | 108 std::ifstream mapsfile("/proc/self/maps"); |
107 CHECK(mapsfile.good()); | 109 CHECK(mapsfile.good()); |
108 std::string result; | 110 std::string result; |
109 | 111 |
110 for (std::string line; std::getline(mapsfile, line); ) { | 112 for (std::string line; std::getline(mapsfile, line); ) { |
111 if (line.find("r-xp") == std::string::npos) | 113 if (line.find("r-xp") == std::string::npos) |
112 continue; | 114 continue; |
113 | 115 |
114 const size_t address_length = line.find('-'); | 116 const size_t address_length = line.find('-'); |
115 uint64 start_address = 0; | 117 uint64_t start_address = 0; |
116 CHECK(ParseAddress(line, 0, address_length, &start_address)); | 118 CHECK(ParseAddress(line, 0, address_length, &start_address)); |
117 | 119 |
118 uint64 end_address = 0; | 120 uint64_t end_address = 0; |
119 CHECK(ParseAddress(line, address_length + 1, address_length, | 121 CHECK(ParseAddress(line, address_length + 1, address_length, |
120 &end_address)); | 122 &end_address)); |
121 | 123 |
122 const uintptr_t current_func_addr = reinterpret_cast<uintptr_t>( | 124 const uintptr_t current_func_addr = reinterpret_cast<uintptr_t>( |
123 &MakeFileHeaderLine); | 125 &MakeFileHeaderLine); |
124 if (current_func_addr >= start_address && | 126 if (current_func_addr >= start_address && |
125 current_func_addr < end_address) { | 127 current_func_addr < end_address) { |
126 result.swap(line); | 128 result.swap(line); |
127 break; | 129 break; |
128 } | 130 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 366 } |
365 | 367 |
366 if (g_tls_log != kMagicBeingConstructed) | 368 if (g_tls_log != kMagicBeingConstructed) |
367 g_tls_log->AddEntry(this_fn); | 369 g_tls_log->AddEntry(this_fn); |
368 } | 370 } |
369 | 371 |
370 void __cyg_profile_func_exit(void* this_fn, void* call_site) {} | 372 void __cyg_profile_func_exit(void* this_fn, void* call_site) {} |
371 | 373 |
372 } // extern "C" | 374 } // extern "C" |
373 } // namespace cygprofile | 375 } // namespace cygprofile |
OLD | NEW |