feat: print elapsed time on fpack/funpack completion
This commit is contained in:
+28
-7
@@ -1,3 +1,7 @@
|
||||
#if !defined(_WIN32)
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#endif
|
||||
|
||||
#include "fpk.h"
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
@@ -8,17 +12,31 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#define MKDIR(path) _mkdir(path)
|
||||
#else
|
||||
#define MKDIR(path) mkdir(path, 0755)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PROGRAM_NAME "funpack.exe"
|
||||
#else
|
||||
#include <time.h>
|
||||
#define MKDIR(path) mkdir(path, 0755)
|
||||
#define PROGRAM_NAME "funpack"
|
||||
#endif
|
||||
|
||||
static double now_seconds(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER freq, count;
|
||||
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&count);
|
||||
return (double)count.QuadPart / (double)freq.QuadPart;
|
||||
#else
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define FUNPACK_LIST (1u << 0)
|
||||
#define FUNPACK_PROGRESS (1u << 1)
|
||||
#define FUNPACK_QUIET (1u << 2)
|
||||
@@ -192,6 +210,7 @@ int main(int argc, char **argv)
|
||||
uint64_t count;
|
||||
uint64_t i;
|
||||
int c;
|
||||
double start_time;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "d:lpqvh", long_opts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
@@ -223,6 +242,8 @@ int main(int argc, char **argv)
|
||||
|
||||
input = argv[optind];
|
||||
|
||||
start_time = now_seconds();
|
||||
|
||||
pak = fpk_open(input);
|
||||
if (!pak) {
|
||||
fprintf(stderr, "funpack: cannot open: %s\n", input);
|
||||
@@ -289,8 +310,8 @@ int main(int argc, char **argv)
|
||||
printf("\n");
|
||||
|
||||
if (!(flags & FUNPACK_QUIET))
|
||||
printf("unpacked: %s -> %s (%lu entries)\n", input, out_dir,
|
||||
(unsigned long)count);
|
||||
printf("unpacked: %s -> %s (%lu entries) in %.3fs\n", input, out_dir,
|
||||
(unsigned long)count, now_seconds() - start_time);
|
||||
|
||||
free(out_dir);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user