1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tradefed.monitoring.collector; 18 19 import com.android.tradefed.command.remote.DeviceDescriptor; 20 import com.android.tradefed.device.IDeviceManager; 21 22 import com.google.dualhomelab.monitoringagent.resourcemonitoring.Resource; 23 import com.android.tradefed.monitoring.LabResourceDeviceMonitor; 24 import java.util.Collection; 25 import java.util.List; 26 27 /** The interface for user to implement customized resource collectors. */ 28 public interface IResourceMetricCollector { 29 30 /** 31 * Collects host resource metrics. The function must return in {@link 32 * IResourceMetricCollector#getHostMetricizeTimeoutMs()} ms, otherwise the result will be 33 * dropped by the {@link LabResourceDeviceMonitor}. Also, please check 34 * Thread.currentThread().isInterrupted() before expensive operation and return immediately. 35 * 36 * @return a {@link Collection} of host {@link Resource}. 37 */ getHostResourceMetrics()38 public default Collection<Resource> getHostResourceMetrics() { 39 return List.of(); 40 } 41 42 /** 43 * Collects device resource metrics. The function must return in {@link 44 * IResourceMetricCollector#getDeviceMetricizeTimeoutMs()} ms, otherwise the result will be 45 * dropped by the {@link LabResourceDeviceMonitor}. Also, please check 46 * Thread.currentThread().isInterrupted() before expensive operation and return immediately. 47 * 48 * @param descriptor the {@link DeviceDescriptor} about the metricizing device. 49 * @param deviceManager the {@link IDeviceManager} instance. 50 * @return a {@link Collection} of device {@link Resource}. 51 */ getDeviceResourceMetrics( DeviceDescriptor descriptor, IDeviceManager deviceManager)52 public default Collection<Resource> getDeviceResourceMetrics( 53 DeviceDescriptor descriptor, IDeviceManager deviceManager) { 54 return List.of(); 55 } 56 57 /** Gets the host metricize timeout in ms. */ getHostMetricizeTimeoutMs()58 public default long getHostMetricizeTimeoutMs() { 59 return 1000; 60 } 61 62 /** Gets the device metricize timeout in ms. */ getDeviceMetricizeTimeoutMs()63 public default long getDeviceMetricizeTimeoutMs() { 64 return 1000; 65 } 66 } 67