1 // Copyright 2017 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. 4 5 #include "remoting/host/current_process_stats_agent.h" 6 7 #include "base/process/process_metrics.h" 8 #include "build/build_config.h" 9 10 #if defined(OS_WIN) 11 #include <windows.h> // This include must come first. 12 13 #include <psapi.h> 14 #endif 15 16 namespace remoting { 17 CurrentProcessStatsAgent(const std::string & process_name)18CurrentProcessStatsAgent::CurrentProcessStatsAgent( 19 const std::string& process_name) 20 : process_name_(process_name), 21 metrics_(base::ProcessMetrics::CreateCurrentProcessMetrics()) {} 22 23 CurrentProcessStatsAgent::~CurrentProcessStatsAgent() = default; 24 GetResourceUsage()25protocol::ProcessResourceUsage CurrentProcessStatsAgent::GetResourceUsage() { 26 protocol::ProcessResourceUsage current; 27 current.set_process_name(process_name_); 28 current.set_processor_usage(metrics_->GetPlatformIndependentCPUUsage()); 29 30 // The concepts of "Page File" and "Working Set" are only well defined on 31 // Windows. 32 // TODO: Currently, this code is only run on Windows. In the future, if/when 33 // this code runs on other platforms, consistent memory metrics should be 34 // obtained from the memory-infra service. 35 #if defined(OS_WIN) 36 PROCESS_MEMORY_COUNTERS pmc; 37 if (::GetProcessMemoryInfo(::GetCurrentProcess(), &pmc, sizeof(pmc))) { 38 current.set_pagefile_size(pmc.PagefileUsage); 39 current.set_working_set_size(pmc.WorkingSetSize); 40 } 41 #endif 42 43 return current; 44 } 45 46 } // namespace remoting 47