• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 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 glob
6import os
7import logging
8import subprocess
9
10def chrome_vmodule_flag():
11    """Return vmodule flag for chrome to enable VDAs/VEAs/JDAs/V4L2IP logs"""
12    logging_patterns = ['*/media/gpu/*video_decode_accelerator.cc=2',
13                        '*/media/gpu/*video_encode_accelerator.cc=2',
14                        '*/media/gpu/*jpeg_decode_accelerator.cc=2',
15                        '*/media/gpu/*image_processor.cc=2',
16                        '*/media/gpu/v4l2/v4l2_device.cc=2']
17    chrome_video_vmodule_flag = '--vmodule=' + ','.join(logging_patterns)
18    logging.info('chrome video vmodule flag: %s', chrome_video_vmodule_flag)
19    return chrome_video_vmodule_flag
20
21
22def video_log_wrapper(func):
23    """
24    Return decorator that make verbose video logs enable
25    before test and make them disable after completing test.
26
27    @param func: function, the test function, e.g., run_once
28    @returns decorator function
29    """
30    vlog = VideoLog()
31
32    #videobuf2 log
33    files = glob.glob('/sys/module/videobuf2_*/parameters/debug')
34    vlog.add_log(files,
35                 ['1'] * len(files),
36                 ['0'] * len(files),
37                 'videobuf2 log')
38
39    #s5p_mfc log
40    fpath = '/sys/module/s5p_mfc/parameters/debug'
41    if os.path.exists(fpath):
42        vlog.add_log([fpath],
43                     ['1'],
44                     ['0'],
45                     's5p_mfc log')
46
47    #rk3399 log
48    #rk3399 debug level is controlled by bits.
49    #Here, 3 means to enable log level 0 and 1.
50    fpath = '/sys/module/rockchip_vpu/parameters/debug'
51    if os.path.exists(fpath):
52        vlog.add_log([fpath],
53                     ['3'],
54                     ['0'],
55                     'rk3399 log')
56
57    #rk3288 log
58    #rk3288 debug level is controlled by bits.
59    #Here, 3 means to enable log level 0 and 1.
60    fpath = '/sys/module/rk3288_vpu/parameters/debug'
61    if os.path.exists(fpath):
62        vlog.add_log([fpath],
63                     ['3'],
64                     ['0'],
65                     'rk3288 log')
66
67    #go2001 log
68    fpath = '/sys/module/go2001/parameters/go2001_debug_level'
69    if os.path.exists(fpath):
70        vlog.add_log([fpath],
71                     ['1'],
72                     ['0'],
73                     'go2001 log')
74
75    def call(*args, **kwargs):
76        """
77        Enable logs before the test, execute the test and disable logs
78        after the test.
79
80        In any case, it is guranteed to disable logs.
81        """
82        with vlog:
83            return func(*args, **kwargs)
84
85    return call
86
87
88def cmdexec_with_log(cmd, info_message):
89    """
90    Execute command, logging infomation message.
91
92    @param cmd: string, command to be executed
93    @param info_message: string, the messages to be shown in log message
94    """
95    try:
96        logging.info('%s : %s', info_message, cmd)
97        subprocess.check_call(cmd, shell=True)
98    except subprocess.CalledProcessError:
99        logging.warning('Fail to execute command [%s] : %s',
100                        info_message, cmd)
101
102
103class VideoLog:
104    """
105    Enable/Disable video logs.
106    """
107    def __init__(self):
108        self.logs = []
109
110    def add_log(self, files, enable_values, disable_values, log_name):
111        """
112        Add new log
113
114        @param files: list of string, file paths
115        @param enable_values: list of string, the list of value
116                              to write to each file path for enabling
117        @param disable_values: list of string, the list of value
118                               to write to each file path for disabling
119        @param log_name: string, name to be shown in log message
120        """
121        self.logs.append({'files': files,
122                          'enable values': enable_values,
123                          'disable values': disable_values,
124                          'log name': log_name})
125
126    def __enter__(self):
127        """Enable logs"""
128        for log in self.logs:
129            log_name = log['log name']
130            for f, ev in zip(log['files'], log['enable values']):
131                cmdexec_with_log('echo %s > %s' % (ev, f),
132                                 '%s enable' % log_name)
133
134    def __exit__(self, exception_type, exception_value, traceback):
135        """Disable logs"""
136        for log in self.logs:
137            log_name = log['log name']
138            for f, dv in zip(log['files'], log['disable values']):
139                cmdexec_with_log('echo %s > %s' % (dv, f),
140                                 '%s disable' % log_name)
141