示例#1
0
def create_files_mtime(files):
    """Create dict of file names and it's modified time.

    param files: List file names.
    return:  Dict of file names with value of the file's modified time.
    """
    return {file_name: fileops.getmtime(file_name) for file_name in files if file_name}
示例#2
0
def create_files_mtime(files):
    """Create dict of file names and it's modified time.

    param files: List file names.
    return:  Dict of file names with value of the file's modified time.
    """
    return {
        file_name: fileops.getmtime(file_name)
        for file_name in files if file_name
    }
示例#3
0
def monitor_device(adb_control, files_mtime):
    """Run monitoring on device and collect results.

    param adb_control: AdbControl object.
    param files_mtime: Dict of files with their modified time.
    """
    adb_control.start()
    try:
        adb_control.wait()
    finally:
        files_saved = [
            path for path in files_mtime
            if fileops.getmtime(path) > files_mtime[path] and not fileops.is_empty(path)
        ]
        LOGGER.info("Files saved: %s", files_saved)
示例#4
0
def monitor_device(adb_control, files_mtime):
    """Run monitoring on device and collect results.

    param adb_control: AdbControl object.
    param files_mtime: Dict of files with their modified time.
    """
    adb_control.start()
    try:
        adb_control.wait()
    finally:
        files_saved = [
            path for path in files_mtime
            if fileops.getmtime(path) > files_mtime[path]
            and not fileops.is_empty(path)
        ]
        LOGGER.info("Files saved: %s", files_saved)
示例#5
0
def main():  #pylint: disable=too-many-statements
    """Execute Main program."""

    parser = optparse.OptionParser()

    program_options = optparse.OptionGroup(parser, "Program Options")
    battery_options = optparse.OptionGroup(parser, "Battery Options")
    memory_options = optparse.OptionGroup(parser, "Memory Options")
    systrace_options = optparse.OptionGroup(parser, "Systrace Options")

    program_options.add_option("--adbBinary", dest="adb_binary",
                               help="The path for adb. Defaults to '%default', which is in $PATH.",
                               default="adb")

    program_options.add_option(
        "--samples", dest="num_samples",
        help="Number of samples to collect, 0 indicates infinite. [Default: %default]", type=int,
        default=0)

    program_options.add_option(
        "--collectionTime", dest="collection_time_secs",
        help="Time in seconds to collect samples, if specifed overrides '--samples'.", type=int,
        default=0)

    program_options.add_option(
        "--sampleIntervalMs", dest="sample_interval_ms",
        help="Time in milliseconds between collecting a sample. [Default: %default]", type=int,
        default=500)

    log_levels = ["debug", "error", "info", "warning"]
    program_options.add_option(
        "--logLevel", dest="log_level", choices=log_levels,
        help="The log level. Accepted values are: {}. [default: '%default'].".format(log_levels),
        default="info")

    battery_options.add_option(
        "--batteryFile", dest="battery_file",
        help="The destination file for battery stats (CSV format).  [Default: %default].",
        default="battery.csv")

    battery_options.add_option("--noBattery", dest="no_battery",
                               help="Disable collection of battery samples.", action="store_true",
                               default=False)

    memory_options.add_option(
        "--memoryFile", dest="memory_file",
        help="The destination file for memory stats (CSV format). [Default: %default].",
        default="memory.csv")

    battery_options.add_option("--noMemory", dest="no_memory",
                               help="Disable collection of memory samples.", action="store_true",
                               default=False)

    systrace_options.add_option(
        "--cpuFile", dest="cpu_file",
        help="The destination file for CPU stats (JSON format). [Default: %default].",
        default="cpu.json")

    systrace_options.add_option("--noCpu", dest="no_cpu", help="Disable collection of CPU samples.",
                                action="store_true", default=False)

    parser.add_option_group(program_options)
    parser.add_option_group(battery_options)
    parser.add_option_group(memory_options)
    parser.add_option_group(systrace_options)

    options, _ = parser.parse_args()

    output_files = {}
    if options.no_battery:
        options.battery_file = None
    else:
        output_files[options.battery_file] = fileops.getmtime(options.battery_file)

    if options.no_memory:
        options.memory_file = None
    else:
        output_files[options.memory_file] = fileops.getmtime(options.memory_file)

    if options.no_cpu:
        options.cpu_file = None
    else:
        output_files[options.cpu_file] = fileops.getmtime(options.cpu_file)

    LOGGER.setLevel(options.log_level.upper())
    LOGGER.info("This program can be cleanly terminated by issuing the following command:"
                "\n\t\t'kill -INT %d'", os.getpid())

    adb = Adb(options.adb_binary)
    LOGGER.info("Detected devices by adb:\n%s%s", adb.devices(), adb.device_available())

    adb_control = AdbControl(adb=adb, battery_file=options.battery_file,
                             memory_file=options.memory_file, cpu_file=options.cpu_file,
                             num_samples=options.num_samples,
                             collection_time_secs=options.collection_time_secs,
                             sample_interval_ms=options.sample_interval_ms)

    adb_control.start()
    try:
        adb_control.wait()
    finally:
        files_saved = []
        for path in output_files:
            if fileops.getmtime(path) > output_files[path] and not fileops.is_empty(path):
                files_saved.append(path)
        LOGGER.info("Files saved: %s", files_saved)
示例#6
0
def main():  #pylint: disable=too-many-statements
    """Execute Main program."""

    parser = optparse.OptionParser()

    program_options = optparse.OptionGroup(parser, "Program Options")
    battery_options = optparse.OptionGroup(parser, "Battery Options")
    memory_options = optparse.OptionGroup(parser, "Memory Options")
    systrace_options = optparse.OptionGroup(parser, "Systrace Options")

    program_options.add_option(
        "--adbBinary",
        dest="adb_binary",
        help="The path for adb. Defaults to '%default', which is in $PATH.",
        default="adb")

    program_options.add_option(
        "--samples",
        dest="num_samples",
        help=
        "Number of samples to collect, 0 indicates infinite. [Default: %default]",
        type=int,
        default=0)

    program_options.add_option(
        "--collectionTime",
        dest="collection_time_secs",
        help=
        "Time in seconds to collect samples, if specifed overrides '--samples'.",
        type=int,
        default=0)

    program_options.add_option(
        "--sampleIntervalMs",
        dest="sample_interval_ms",
        help=
        "Time in milliseconds between collecting a sample. [Default: %default]",
        type=int,
        default=500)

    log_levels = ["debug", "error", "info", "warning"]
    program_options.add_option(
        "--logLevel",
        dest="log_level",
        choices=log_levels,
        help="The log level. Accepted values are: {}. [default: '%default'].".
        format(log_levels),
        default="info")

    battery_options.add_option(
        "--batteryFile",
        dest="battery_file",
        help=
        "The destination file for battery stats (CSV format).  [Default: %default].",
        default="battery.csv")

    battery_options.add_option("--noBattery",
                               dest="no_battery",
                               help="Disable collection of battery samples.",
                               action="store_true",
                               default=False)

    memory_options.add_option(
        "--memoryFile",
        dest="memory_file",
        help=
        "The destination file for memory stats (CSV format). [Default: %default].",
        default="memory.csv")

    memory_options.add_option("--noMemory",
                              dest="no_memory",
                              help="Disable collection of memory samples.",
                              action="store_true",
                              default=False)

    systrace_options.add_option(
        "--cpuFile",
        dest="cpu_file",
        help=
        "The destination file for CPU stats (JSON format). [Default: %default].",
        default="cpu.json")

    systrace_options.add_option("--noCpu",
                                dest="no_cpu",
                                help="Disable collection of CPU samples.",
                                action="store_true",
                                default=False)

    parser.add_option_group(program_options)
    parser.add_option_group(battery_options)
    parser.add_option_group(memory_options)
    parser.add_option_group(systrace_options)

    options, _ = parser.parse_args()

    output_files = {}
    if options.no_battery:
        options.battery_file = None
    else:
        output_files[options.battery_file] = fileops.getmtime(
            options.battery_file)

    if options.no_memory:
        options.memory_file = None
    else:
        output_files[options.memory_file] = fileops.getmtime(
            options.memory_file)

    if options.no_cpu:
        options.cpu_file = None
    else:
        output_files[options.cpu_file] = fileops.getmtime(options.cpu_file)

    LOGGER.setLevel(options.log_level.upper())
    LOGGER.info(
        "This program can be cleanly terminated by issuing the following command:"
        "\n\t\t'kill -INT %d'", os.getpid())

    adb = Adb(options.adb_binary)
    LOGGER.info("Detected devices by adb:\n%s%s", adb.devices(),
                adb.device_available())

    adb_control = AdbControl(adb=adb,
                             battery_file=options.battery_file,
                             memory_file=options.memory_file,
                             cpu_file=options.cpu_file,
                             num_samples=options.num_samples,
                             collection_time_secs=options.collection_time_secs,
                             sample_interval_ms=options.sample_interval_ms)

    adb_control.start()
    try:
        adb_control.wait()
    finally:
        files_saved = []
        for path in output_files:
            if fileops.getmtime(
                    path) > output_files[path] and not fileops.is_empty(path):
                files_saved.append(path)
        LOGGER.info("Files saved: %s", files_saved)