Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: src/platform-linux.cc

Issue 160273: X64: Fixes to enable C/C++ functions processing in profiler. (Closed)
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/tickprocessor.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return new PosixMemoryMappedFile(file, memory, size); 216 return new PosixMemoryMappedFile(file, memory, size);
217 } 217 }
218 218
219 219
220 PosixMemoryMappedFile::~PosixMemoryMappedFile() { 220 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
221 if (memory_) munmap(memory_, size_); 221 if (memory_) munmap(memory_, size_);
222 fclose(file_); 222 fclose(file_);
223 } 223 }
224 224
225 225
226 #ifdef ENABLE_LOGGING_AND_PROFILING
227 static uintptr_t StringToULong(char* buffer) {
228 return strtoul(buffer, NULL, 16); // NOLINT
229 }
230 #endif
231
232
233 void OS::LogSharedLibraryAddresses() { 226 void OS::LogSharedLibraryAddresses() {
234 #ifdef ENABLE_LOGGING_AND_PROFILING 227 #ifdef ENABLE_LOGGING_AND_PROFILING
235 static const int MAP_LENGTH = 1024; 228 FILE *fp;
236 int fd = open("/proc/self/maps", O_RDONLY); 229 fp = fopen("/proc/self/maps", "r");
237 if (fd < 0) return; 230 if (fp == NULL) return;
238 while (true) { 231 while (true) {
239 char addr_buffer[11]; 232 uintptr_t start, end;
240 addr_buffer[0] = '0'; 233 char attr_r, attr_w, attr_x, attr_p;
241 addr_buffer[1] = 'x'; 234 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
242 addr_buffer[10] = 0; 235 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
243 int result = read(fd, addr_buffer + 2, 8); 236 char c;
244 if (result < 8) break; 237 if (attr_r == 'r' && attr_x == 'x') {
245 uintptr_t start = StringToULong(addr_buffer); 238 while (c = getc(fp), c != EOF && c != '\n' && c != '/');
246 result = read(fd, addr_buffer + 2, 1); 239 char lib_name[1024];
247 if (result < 1) break; 240 bool lib_has_name = false;
248 if (addr_buffer[2] != '-') break; 241 if (c == '/') {
249 result = read(fd, addr_buffer + 2, 8); 242 ungetc(c, fp);
250 if (result < 8) break; 243 lib_has_name = fgets(lib_name, sizeof(lib_name), fp) != NULL;
251 uintptr_t end = StringToULong(addr_buffer); 244 }
252 char buffer[MAP_LENGTH]; 245 if (lib_has_name && strlen(lib_name) > 0) {
253 int bytes_read = -1; 246 lib_name[strlen(lib_name) - 1] = '\0';
254 do { 247 } else {
255 bytes_read++; 248 snprintf(lib_name, sizeof(lib_name),
256 if (bytes_read >= MAP_LENGTH - 1) 249 "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
257 break; 250 }
258 result = read(fd, buffer + bytes_read, 1); 251 LOG(SharedLibraryEvent(lib_name, start, end));
259 if (result < 1) break;
260 } while (buffer[bytes_read] != '\n');
261 buffer[bytes_read] = 0;
262 // Ignore mappings that are not executable.
263 if (buffer[3] != 'x') continue;
264 char* start_of_path = index(buffer, '/');
265 // If there is no filename for this line then log it as an anonymous
266 // mapping and use the address as its name.
267 if (start_of_path == NULL) {
268 // 40 is enough to print a 64 bit address range.
269 ASSERT(sizeof(buffer) > 40);
270 snprintf(buffer,
271 sizeof(buffer),
272 "%08" V8PRIxPTR "-%08" V8PRIxPTR,
273 start,
274 end);
275 LOG(SharedLibraryEvent(buffer, start, end));
276 } else {
277 buffer[bytes_read] = 0;
278 LOG(SharedLibraryEvent(start_of_path, start, end));
279 } 252 }
253 while (c = getc(fp), c != EOF && c != '\n');
280 } 254 }
281 close(fd); 255 fclose(fp);
282 #endif 256 #endif
283 } 257 }
284 258
285 259
286 int OS::StackWalk(Vector<OS::StackFrame> frames) { 260 int OS::StackWalk(Vector<OS::StackFrame> frames) {
287 // backtrace is a glibc extension. 261 // backtrace is a glibc extension.
288 #ifdef __GLIBC__ 262 #ifdef __GLIBC__
289 int frames_size = frames.length(); 263 int frames_size = frames.length();
290 void** addresses = NewArray<void*>(frames_size); 264 void** addresses = NewArray<void*>(frames_size);
291 265
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 682 }
709 683
710 // This sampler is no longer the active sampler. 684 // This sampler is no longer the active sampler.
711 active_sampler_ = NULL; 685 active_sampler_ = NULL;
712 active_ = false; 686 active_ = false;
713 } 687 }
714 688
715 #endif // ENABLE_LOGGING_AND_PROFILING 689 #endif // ENABLE_LOGGING_AND_PROFILING
716 690
717 } } // namespace v8::internal 691 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | tools/tickprocessor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698