| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/private_working_set_snapshot.h" | 5 #include "chrome/browser/private_working_set_snapshot.h" |
| 6 | 6 |
| 7 #include <pdh.h> | 7 #include <pdh.h> |
| 8 #include <pdhmsg.h> | 8 #include <pdhmsg.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 15 | 15 |
| 16 // Link pdh.lib (import library for pdh.dll) whenever this file is linked in. | |
| 17 #pragma comment(lib, "pdh.lib") | |
| 18 | |
| 19 PrivateWorkingSetSnapshot::PrivateWorkingSetSnapshot() {} | 16 PrivateWorkingSetSnapshot::PrivateWorkingSetSnapshot() {} |
| 20 | 17 |
| 21 PrivateWorkingSetSnapshot::~PrivateWorkingSetSnapshot() {} | 18 PrivateWorkingSetSnapshot::~PrivateWorkingSetSnapshot() {} |
| 22 | 19 |
| 23 void PrivateWorkingSetSnapshot::Initialize() { | 20 void PrivateWorkingSetSnapshot::Initialize() { |
| 24 DCHECK(!initialized_); | 21 DCHECK(!initialized_); |
| 25 | 22 |
| 26 // Set this to true whether initialization succeeds or not. That is, only try | 23 // Set this to true whether initialization succeeds or not. That is, only try |
| 27 // once. | 24 // once. |
| 28 initialized_ = true; | 25 initialized_ = true; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 size_t PrivateWorkingSetSnapshot::GetPrivateWorkingSet( | 180 size_t PrivateWorkingSetSnapshot::GetPrivateWorkingSet( |
| 184 base::ProcessId process_id) const { | 181 base::ProcessId process_id) const { |
| 185 // Do a binary search for the requested process ID and return the working set | 182 // Do a binary search for the requested process ID and return the working set |
| 186 // if found. | 183 // if found. |
| 187 auto p = std::lower_bound(records_.begin(), records_.end(), process_id); | 184 auto p = std::lower_bound(records_.begin(), records_.end(), process_id); |
| 188 if (p != records_.end() && p->process_id == process_id) | 185 if (p != records_.end() && p->process_id == process_id) |
| 189 return p->private_ws; | 186 return p->private_ws; |
| 190 | 187 |
| 191 return 0; | 188 return 0; |
| 192 } | 189 } |
| OLD | NEW |