1# Copyright (c) 2017 The Chromium OS 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 5import logging 6 7from autotest_lib.server.cros import cfm_jmidata_v3_helper 8 9 10def GetDataFromLogs(testcase, data_type, log_lines): 11 """Returns a list of data_type from JMI data in javascript log. 12 13 @param testcase: Testcase instance. 14 @param data_type: Type of data to be retrieved (audio sent/audio received 15 etc. See above for complete list.). 16 @param log_lines: log_file to be parsed. 17 18 @return A list of data_type from javascript log. If the data_type is not 19 supported for the given type of data (i.e. the underlying helper raises 20 NotImplementedError), an empty list is returned. 21 """ 22 helper = cfm_jmidata_v3_helper.JMIDataV3Helper(log_lines) 23 data_type_to_func_map = { 24 'video_sent_bytes': helper.GetVideoSentBytesList, 25 'video_received_bytes': helper.GetVideoReceivedBytesList, 26 'audio_sent_bytes': helper.GetAudioSentBytesList, 27 'audio_received_bytes': helper.GetAudioReceivedBytesList, 28 'audio_received_energy_level': helper.GetAudioReceivedEnergyList, 29 'audio_sent_energy_level': helper.GetAudioSentEnergyList, 30 'framerate_received': helper.GetVideoIncomingFramerateReceivedList, 31 'framerate_sent': helper.GetVideoOutgoingFramerateSentList, 32 'framerate_decoded': helper.GetVideoIncomingFramerateDecodedList, 33 'frames_decoded': helper.GetVideoIncomingFramesDecodedList, 34 'frames_encoded': helper.GetVideoOutgoingFramesEncodedList, 35 'average_encode_time': helper.GetVideoEncodeTimeList, 36 'framerate_to_renderer': helper.GetVideoIncomingFramerateList, 37 'framerate_outgoing': helper.GetVideoOutgoingFramerateInputList, 38 'video_sent_frame_width': helper.GetVideoSentFrameWidthList, 39 'video_received_frame_width': helper.GetVideoReceivedFrameWidthList, 40 'video_sent_frame_height': helper.GetVideoSentFrameHeightList, 41 'video_received_frame_height': helper.GetVideoReceivedFrameHeightList, 42 'cpu_adaptation': helper.GetCPULimitedResolutionList, 43 'bandwidth_adaptation': helper.GetBandwidthLimitedResolutionList, 44 'adaptation_changes': helper.GetVideoAdaptationChangeList, 45 'video_packets_sent': helper.GetVideoPacketsSentList, 46 'video_packets_lost': helper.GetVideoPacketsLostList, 47 'video_encode_cpu_usage': helper.GetVideoEncodeCpuUsagePercentList, 48 'num_active_vid_in_streams': 49 helper.GetNumberOfActiveIncomingVideoStreams, 50 'cpu_processors': helper.GetNumOfProcessors, 51 'cpu_percent': helper.GetTotalCpuPercentage, 52 'browser_cpu_percent': helper.GetBrowserCpuPercentage, 53 'gpu_cpu_percent': helper.GetGpuCpuPercentage, 54 'nacl_effects_cpu_percent': helper.GetNaclEffectsCpuPercentage, 55 'renderer_cpu_percent': helper.GetRendererCpuPercentage, 56 } 57 58 try: 59 data_array = data_type_to_func_map[data_type]() 60 except NotImplementedError as e: 61 logging.warning('data_type "%s" is not implemented in helper %s, ' 62 'returning empty data set', 63 data_type, 64 helper, 65 exc_info = True) 66 data_array = [0] 67 logging.info('Data Type: %s, Data Array: %s', data_type, str(data_array)) 68 # Ensure we always return at least one element, or perf uploads will be 69 # sad. 70 return data_array or [0] 71 72