1 // Copyright 2018 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #include "aemu/base/CpuTime.h" 15 16 namespace android { 17 namespace base { 18 operator -(const CpuTime & a,const CpuTime & other)19CpuTime operator-(const CpuTime& a, const CpuTime& other) { 20 CpuTime res = a; 21 res -= other; 22 return res; 23 } 24 operator -=(const CpuTime & other)25CpuTime& CpuTime::operator-=(const CpuTime& other) { 26 wall_time_us -= other.wall_time_us; 27 user_time_us -= other.user_time_us; 28 system_time_us -= other.system_time_us; 29 return *this; 30 } 31 usageUs() const32uint64_t CpuTime::usageUs() const { 33 return user_time_us + system_time_us; 34 } 35 usage() const36float CpuTime::usage() const { 37 if (!wall_time_us) return 0.0f; 38 return (float)(user_time_us + system_time_us) / (float)(wall_time_us); 39 } 40 usageUser() const41float CpuTime::usageUser() const { 42 if (!wall_time_us) return 0.0f; 43 return (float)(user_time_us) / (float)(wall_time_us); 44 } 45 usageSystem() const46float CpuTime::usageSystem() const { 47 if (!wall_time_us) return 0.0f; 48 return (float)(system_time_us) / (float)(wall_time_us); 49 } 50 51 } // namespace android 52 } // namespace base 53