mirror of
https://github.com/AltraMayor/f3.git
synced 2025-08-03 18:46:00 -04:00
f3probe: improve report
- Show copyright header. - Use friendly and precise units. - Measure and show time to probe device.
This commit is contained in:
parent
d940ecd19a
commit
6a63a5fff4
2
Makefile
2
Makefile
@ -13,7 +13,7 @@ f3write: utils.o f3write.o
|
|||||||
f3read: utils.o f3read.o
|
f3read: utils.o f3read.o
|
||||||
$(CC) -o $@ $^
|
$(CC) -o $@ $^
|
||||||
|
|
||||||
f3probe: libprobe.o f3probe.o
|
f3probe: libprobe.o utils.o f3probe.o
|
||||||
$(CC) -o $@ $^ -ludev
|
$(CC) -o $@ $^ -ludev
|
||||||
|
|
||||||
-include *.d
|
-include *.d
|
||||||
|
27
f3probe.c
27
f3probe.c
@ -5,10 +5,14 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "libprobe.h"
|
#include "libprobe.h"
|
||||||
|
|
||||||
|
/* XXX Refactor utils library since f3probe barely uses it. */
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/* Argp's global variables. */
|
/* Argp's global variables. */
|
||||||
const char *argp_program_version = "F3 Probe " F3_STR_VERSION;
|
const char *argp_program_version = "F3 Probe " F3_STR_VERSION;
|
||||||
|
|
||||||
@ -203,8 +207,19 @@ static int unit_test(const char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void report(const char *prefix, uint64_t bytes)
|
||||||
|
{
|
||||||
|
double f = (double)bytes;
|
||||||
|
const char *unit = adjust_unit(&f);
|
||||||
|
assert(bytes % SECTOR_SIZE == 0);
|
||||||
|
printf("%s %.2f %s (%" PRIu64 " sectors)\n", prefix, f, unit,
|
||||||
|
bytes / SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
static int test_device(struct args *args)
|
static int test_device(struct args *args)
|
||||||
{
|
{
|
||||||
|
struct timeval t1, t2;
|
||||||
|
double time_s;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
enum fake_type fake_type;
|
enum fake_type fake_type;
|
||||||
uint64_t real_size_byte, announced_size_byte;
|
uint64_t real_size_byte, announced_size_byte;
|
||||||
@ -215,7 +230,9 @@ static int test_device(struct args *args)
|
|||||||
args->fake_size_gb, args->fake_type)
|
args->fake_size_gb, args->fake_type)
|
||||||
: create_block_device(args->filename);
|
: create_block_device(args->filename);
|
||||||
assert(dev);
|
assert(dev);
|
||||||
|
assert(!gettimeofday(&t1, NULL));
|
||||||
probe_device(dev, &real_size_byte, &announced_size_byte, &wrap);
|
probe_device(dev, &real_size_byte, &announced_size_byte, &wrap);
|
||||||
|
assert(!gettimeofday(&t2, NULL));
|
||||||
free_device(dev);
|
free_device(dev);
|
||||||
|
|
||||||
fake_type = dev_param_to_type(real_size_byte, announced_size_byte,
|
fake_type = dev_param_to_type(real_size_byte, announced_size_byte,
|
||||||
@ -239,11 +256,12 @@ static int test_device(struct args *args)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX Add user friendly values, and sectors. */
|
time_s = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec)/1000000.;
|
||||||
printf("\nDevice geometry:\n");
|
printf("\nDevice geometry:\n");
|
||||||
printf("\t *Real* size: %" PRIu64 " Bytes\n", real_size_byte);
|
report("\t *Real* size:", real_size_byte);
|
||||||
printf("\tAnnounced size: %" PRIu64 " Bytes\n", announced_size_byte);
|
report("\tAnnounced size:", announced_size_byte);
|
||||||
printf("\t Wrap: 2^%i\n\n", wrap);
|
printf("\t Module: 2^%i\n", wrap);
|
||||||
|
printf("\nProbe time: %.2f seconds\n", time_s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,6 +278,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Read parameters. */
|
/* Read parameters. */
|
||||||
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
||||||
|
print_header(stdout, "probe");
|
||||||
|
|
||||||
if (args.unit_test)
|
if (args.unit_test)
|
||||||
return unit_test(args.filename);
|
return unit_test(args.filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user