Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "snapshot/win/process_reader_win.h" | 15 #include "snapshot/win/process_reader_win.h" |
| 16 | 16 |
| 17 #include "base/numerics/safe_conversions.h" | 17 #include "base/numerics/safe_conversions.h" |
| 18 #include "util/win/time.h" | |
| 18 | 19 |
| 19 namespace crashpad { | 20 namespace crashpad { |
| 20 | 21 |
| 22 namespace { | |
| 23 | |
| 24 void TimerClear(timeval* tv) { | |
|
Mark Mentovai
2015/05/04 21:29:23
Do this in compat if it’s needed elsewhere, or jus
scottmg
2015/05/05 16:45:48
Done.
| |
| 25 tv->tv_sec = 0; | |
| 26 tv->tv_usec = 0; | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 21 ProcessReaderWin::ProcessReaderWin() | 31 ProcessReaderWin::ProcessReaderWin() |
| 22 : process_(INVALID_HANDLE_VALUE), | 32 : process_(INVALID_HANDLE_VALUE), |
| 23 process_info_(), | 33 process_info_(), |
| 24 modules_(), | 34 modules_(), |
| 25 initialized_() { | 35 initialized_() { |
| 26 } | 36 } |
| 27 | 37 |
| 28 ProcessReaderWin::~ProcessReaderWin() { | 38 ProcessReaderWin::~ProcessReaderWin() { |
| 29 } | 39 } |
| 30 | 40 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 47 into, | 57 into, |
| 48 base::checked_cast<SIZE_T>(num_bytes), | 58 base::checked_cast<SIZE_T>(num_bytes), |
| 49 &bytes_read) || | 59 &bytes_read) || |
| 50 num_bytes != bytes_read) { | 60 num_bytes != bytes_read) { |
| 51 PLOG(ERROR) << "ReadMemory at " << at << " of " << num_bytes << " failed"; | 61 PLOG(ERROR) << "ReadMemory at " << at << " of " << num_bytes << " failed"; |
| 52 return false; | 62 return false; |
| 53 } | 63 } |
| 54 return true; | 64 return true; |
| 55 } | 65 } |
| 56 | 66 |
| 67 bool ProcessReaderWin::StartTime(timeval* start_time) const { | |
| 68 FILETIME creation, exit, kernel, user; | |
| 69 if (!GetProcessTimes(process_, &creation, &exit, &kernel, &user)) { | |
| 70 PLOG(ERROR) << "GetProcessTimes"; | |
| 71 TimerClear(start_time); | |
| 72 return false; | |
| 73 } | |
| 74 *start_time = FiletimeToTimevalEpoch(creation); | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 bool ProcessReaderWin::CPUTimes(timeval* user_time, | |
| 79 timeval* system_time) const { | |
| 80 FILETIME creation, exit, kernel, user; | |
| 81 if (!GetProcessTimes(process_, &creation, &exit, &kernel, &user)) { | |
| 82 PLOG(ERROR) << "GetProcessTimes"; | |
| 83 TimerClear(user_time); | |
| 84 TimerClear(system_time); | |
| 85 return false; | |
| 86 } | |
| 87 *user_time = FiletimeToTimevalAmount(user); | |
| 88 *system_time = FiletimeToTimevalAmount(kernel); | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 57 const std::vector<ProcessInfo::Module>& ProcessReaderWin::Modules() { | 92 const std::vector<ProcessInfo::Module>& ProcessReaderWin::Modules() { |
| 58 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 93 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 59 | 94 |
| 60 if (!process_info_.Modules(&modules_)) { | 95 if (!process_info_.Modules(&modules_)) { |
| 61 LOG(ERROR) << "couldn't retrieve modules"; | 96 LOG(ERROR) << "couldn't retrieve modules"; |
| 62 } | 97 } |
| 63 | 98 |
| 64 return modules_; | 99 return modules_; |
| 65 } | 100 } |
| 66 | 101 |
| 67 } // namespace crashpad | 102 } // namespace crashpad |
| OLD | NEW |