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

Side by Side Diff: base/memory/shared_memory_posix.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: Remove unneeded calls Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
11 #include <sys/stat.h> 11 #include <sys/stat.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 13
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_file.h" 15 #include "base/files/scoped_file.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/shared_memory_dump_provider.h"
17 #include "base/posix/eintr_wrapper.h" 18 #include "base/posix/eintr_wrapper.h"
18 #include "base/posix/safe_strerror.h" 19 #include "base/posix/safe_strerror.h"
19 #include "base/process/process_metrics.h" 20 #include "base/process/process_metrics.h"
20 #include "base/profiler/scoped_tracker.h" 21 #include "base/profiler/scoped_tracker.h"
21 #include "base/scoped_generic.h" 22 #include "base/scoped_generic.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 25
25 #if defined(OS_ANDROID) 26 #if defined(OS_ANDROID)
26 #include "base/os_compat_android.h" 27 #include "base/os_compat_android.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 #endif 352 #endif
352 353
353 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), 354 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
354 MAP_SHARED, mapped_file_, offset); 355 MAP_SHARED, mapped_file_, offset);
355 356
356 bool mmap_succeeded = memory_ != (void*)-1 && memory_ != NULL; 357 bool mmap_succeeded = memory_ != (void*)-1 && memory_ != NULL;
357 if (mmap_succeeded) { 358 if (mmap_succeeded) {
358 mapped_size_ = bytes; 359 mapped_size_ = bytes;
359 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & 360 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
360 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); 361 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
362 SharedMemoryDumpProvider::GetInstance()->IncrementMemoryUsage(mapped_size_);
haraken 2016/11/30 04:39:26 We want to get not only the mmaped size but also t
361 } else { 363 } else {
362 memory_ = NULL; 364 memory_ = NULL;
363 } 365 }
364 366
365 return mmap_succeeded; 367 return mmap_succeeded;
366 } 368 }
367 369
368 bool SharedMemory::Unmap() { 370 bool SharedMemory::Unmap() {
369 if (memory_ == NULL) 371 if (memory_ == NULL)
370 return false; 372 return false;
371 373
372 munmap(memory_, mapped_size_); 374 munmap(memory_, mapped_size_);
375 SharedMemoryDumpProvider::GetInstance()->DecrementMemoryUsage(mapped_size_);
373 memory_ = NULL; 376 memory_ = NULL;
374 mapped_size_ = 0; 377 mapped_size_ = 0;
375 return true; 378 return true;
376 } 379 }
377 380
378 SharedMemoryHandle SharedMemory::handle() const { 381 SharedMemoryHandle SharedMemory::handle() const {
379 return FileDescriptor(mapped_file_, false); 382 return FileDescriptor(mapped_file_, false);
380 } 383 }
381 384
382 SharedMemoryHandle SharedMemory::TakeHandle() { 385 SharedMemoryHandle SharedMemory::TakeHandle() {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 498
496 if (close_self) { 499 if (close_self) {
497 Unmap(); 500 Unmap();
498 Close(); 501 Close();
499 } 502 }
500 503
501 return true; 504 return true;
502 } 505 }
503 506
504 } // namespace base 507 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_dump_provider.cc ('k') | components/discardable_memory/common/discardable_shared_memory_heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698