Add common GLFence::IsSupported() check
[chromium-blink-merge.git] / content / child / content_child_helpers.cc
blobd6d62922d0229842a50a68434ba0e46aea951df1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/content_child_helpers.h"
7 #if defined(OS_LINUX)
8 #include <malloc.h>
9 #endif
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/process/process_metrics.h"
14 #include "v8/include/v8.h"
16 namespace content {
18 #if defined(OS_LINUX) || defined(OS_ANDROID)
19 size_t GetMemoryUsageKB() {
20 struct mallinfo minfo = mallinfo();
21 uint64_t mem_usage =
22 #if defined(USE_TCMALLOC)
23 minfo.uordblks
24 #else
25 (minfo.hblkhd + minfo.arena)
26 #endif
27 >> 10;
29 v8::HeapStatistics stat;
30 // TODO(svenpanne) The call below doesn't take web workers into account, this
31 // has to be done manually by iterating over all Isolates involved.
32 v8::Isolate* isolate = v8::Isolate::GetCurrent();
33 if (isolate)
34 isolate->GetHeapStatistics(&stat);
35 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 10);
37 #elif defined(OS_MACOSX)
38 size_t GetMemoryUsageKB() {
39 scoped_ptr<base::ProcessMetrics> process_metrics(
40 // The default port provider is sufficient to get data for the current
41 // process.
42 base::ProcessMetrics::CreateProcessMetrics(
43 base::GetCurrentProcessHandle(), NULL));
44 return process_metrics->GetWorkingSetSize() >> 10;
46 #else
47 size_t GetMemoryUsageKB() {
48 scoped_ptr<base::ProcessMetrics> process_metrics(
49 base::ProcessMetrics::CreateProcessMetrics(
50 base::GetCurrentProcessHandle()));
51 return process_metrics->GetPagefileUsage() >> 10;
53 #endif
55 } // namespace content