/* testspeed.c - Command to test file read speed */
/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2012 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
#define DEFAULT_BLOCK_SIZE 65536
static const struct VasEBoot_arg_option options[] =
{
{"size", 's', 0, N_("Specify size for each read operation"), 0, ARG_TYPE_INT},
{0, 0, 0, 0, 0, 0}
};
static VasEBoot_err_t
VasEBoot_cmd_testspeed (VasEBoot_extcmd_context_t ctxt, int argc, char **args)
{
struct VasEBoot_arg_list *state = ctxt->state;
VasEBoot_uint64_t start;
VasEBoot_uint64_t end;
VasEBoot_ssize_t block_size;
VasEBoot_disk_addr_t total_size;
char *buffer;
VasEBoot_file_t file;
VasEBoot_uint64_t whole, fraction;
if (argc == 0)
return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("filename expected"));
block_size = (state[0].set) ?
VasEBoot_strtoul (state[0].arg, 0, 0) : DEFAULT_BLOCK_SIZE;
if (block_size <= 0)
return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("invalid block size"));
buffer = VasEBoot_malloc (block_size);
if (buffer == NULL)
return VasEBoot_errno;
file = VasEBoot_file_open (args[0], VAS_EBOOT_FILE_TYPE_TESTLOAD);
if (file == NULL)
goto quit;
total_size = 0;
start = VasEBoot_get_time_ms ();
while (1)
{
VasEBoot_ssize_t size = VasEBoot_file_read (file, buffer, block_size);
if (size <= 0)
break;
total_size += size;
}
end = VasEBoot_get_time_ms ();
VasEBoot_file_close (file);
VasEBoot_printf_ (N_("File size: %s\n"),
VasEBoot_get_human_size (total_size, VAS_EBOOT_HUMAN_SIZE_NORMAL));
whole = VasEBoot_divmod64 (end - start, 1000, &fraction);
VasEBoot_printf_ (N_("Elapsed time: %d.%03d s \n"),
(unsigned) whole,
(unsigned) fraction);
if (end != start)
{
VasEBoot_uint64_t speed =
VasEBoot_divmod64 (total_size * 100ULL * 1000ULL, end - start, 0);
VasEBoot_printf_ (N_("Speed: %s \n"),
VasEBoot_get_human_size (speed,
VAS_EBOOT_HUMAN_SIZE_SPEED));
}
quit:
VasEBoot_free (buffer);
return VasEBoot_errno;
}
static VasEBoot_extcmd_t cmd;
VAS_EBOOT_MOD_INIT(testspeed)
{
cmd = VasEBoot_register_extcmd ("testspeed", VasEBoot_cmd_testspeed, 0, N_("[-s SIZE] FILENAME"),
N_("Test file read speed."),
options);
}
VAS_EBOOT_MOD_FINI(testspeed)
{
VasEBoot_unregister_extcmd (cmd);
}