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.
19    """
20    helper = cfm_jmidata_v3_helper.JMIDataV3Helper(log_lines)
21    data_type_to_func_map = {
22        'video_sent_bytes': helper.GetVideoSentBytesList,
23        'video_received_bytes': helper.GetVideoReceivedBytesList,
24        'audio_sent_bytes': helper.GetAudioSentBytesList,
25        'audio_received_bytes': helper.GetAudioReceivedBytesList,
26        'audio_received_energy_level': helper.GetAudioReceivedEnergyList,
27        'audio_sent_energy_level': helper.GetAudioSentEnergyList,
28        'framerate_received': helper.GetVideoIncomingFramerateReceivedList,
29        'framerate_sent': helper.GetVideoOutgoingFramerateSentList,
30        'framerate_decoded': helper.GetVideoIncomingFramerateDecodedList,
31        'frames_decoded': helper.GetVideoIncomingFramesDecodedList,
32        'frames_encoded': helper.GetVideoOutgoingFramesEncodedList,
33        'average_encode_time': helper.GetVideoEncodeTimeList,
34        'framerate_to_renderer': helper.GetVideoIncomingFramerateList,
35        'framerate_outgoing': helper.GetVideoOutgoingFramerateInputList,
36        'video_sent_frame_width': helper.GetVideoSentFrameWidthList,
37        'video_received_frame_width': helper.GetVideoReceivedFrameWidthList,
38        'video_sent_frame_height': helper.GetVideoSentFrameHeightList,
39        'video_received_frame_height': helper.GetVideoReceivedFrameHeightList,
40        'cpu_adaptation': helper.GetCPULimitedResolutionList,
41        'bandwidth_adaptation': helper.GetBandwidthLimitedResolutionList,
42        'adaptation_changes': helper.GetVideoAdaptationChangeList,
43        'video_packets_sent': helper.GetVideoPacketsSentList,
44        'video_packets_lost': helper.GetVideoPacketsLostList,
45        'video_encode_cpu_usage': helper.GetVideoEncodeCpuUsagePercentList,
46        'num_active_vid_in_streams':
47                helper.GetNumberOfActiveIncomingVideoStreams,
48        'cpu_processors': helper.GetNumOfProcessors,
49        'cpu_percent': helper.GetTotalCpuPercentage,
50        'browser_cpu_percent': helper.GetBrowserCpuPercentage,
51        'gpu_cpu_percent': helper.GetGpuCpuPercentage,
52        'nacl_effects_cpu_percent': helper.GetNaclEffectsCpuPercentage,
53        'renderer_cpu_percent': helper.GetRendererCpuPercentage,
54    }
55
56
57    data_array = data_type_to_func_map[data_type]()
58    logging.info('Data Type: %s, Data Array: %s', data_type, str(data_array))
59    return data_array
60