feat: print elapsed time on fpack/funpack completion
This commit is contained in:
+23
-1
@@ -12,15 +12,33 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
#define PROGRAM_NAME "fpack.exe"
|
#define PROGRAM_NAME "fpack.exe"
|
||||||
#define fpack_fseek64(f, off, whence) _fseeki64((f), (off), (whence))
|
#define fpack_fseek64(f, off, whence) _fseeki64((f), (off), (whence))
|
||||||
#define fpack_ftell64(f) _ftelli64((f))
|
#define fpack_ftell64(f) _ftelli64((f))
|
||||||
#else
|
#else
|
||||||
|
#include <time.h>
|
||||||
#define PROGRAM_NAME "fpack"
|
#define PROGRAM_NAME "fpack"
|
||||||
#define fpack_fseek64(f, off, whence) fseeko((f), (off_t)(off), (whence))
|
#define fpack_fseek64(f, off, whence) fseeko((f), (off_t)(off), (whence))
|
||||||
#define fpack_ftell64(f) ftello((f))
|
#define fpack_ftell64(f) ftello((f))
|
||||||
#endif
|
#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 FPACK_QUIET (1u << 0)
|
#define FPACK_QUIET (1u << 0)
|
||||||
#define FPACK_VERBOSE (1u << 1)
|
#define FPACK_VERBOSE (1u << 1)
|
||||||
#define FPACK_PROGRESS (1u << 2)
|
#define FPACK_PROGRESS (1u << 2)
|
||||||
@@ -258,6 +276,7 @@ int main(int argc, char **argv)
|
|||||||
size_t base_len;
|
size_t base_len;
|
||||||
struct fpk_writer *w;
|
struct fpk_writer *w;
|
||||||
int c;
|
int c;
|
||||||
|
double start_time;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "o:pqvh", long_opts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "o:pqvh", long_opts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -287,6 +306,8 @@ int main(int argc, char **argv)
|
|||||||
input_dir = argv[optind];
|
input_dir = argv[optind];
|
||||||
output = output_arg ? dup_str(output_arg) : derive_output_name(input_dir);
|
output = output_arg ? dup_str(output_arg) : derive_output_name(input_dir);
|
||||||
|
|
||||||
|
start_time = now_seconds();
|
||||||
|
|
||||||
base_len = strlen(input_dir);
|
base_len = strlen(input_dir);
|
||||||
while (base_len > 0 && IS_PATH_SEP(input_dir[base_len - 1]))
|
while (base_len > 0 && IS_PATH_SEP(input_dir[base_len - 1]))
|
||||||
base_len--;
|
base_len--;
|
||||||
@@ -324,7 +345,8 @@ int main(int argc, char **argv)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (!(flags & FPACK_QUIET))
|
if (!(flags & FPACK_QUIET))
|
||||||
printf("wrote: %s (%lu entries)\n", output, (unsigned long)entry_count);
|
printf("wrote: %s (%lu entries) in %.3fs\n", output,
|
||||||
|
(unsigned long)entry_count, now_seconds() - start_time);
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+28
-7
@@ -1,3 +1,7 @@
|
|||||||
|
#if !defined(_WIN32)
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "fpk.h"
|
#include "fpk.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -8,17 +12,31 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include <windows.h>
|
||||||
#define MKDIR(path) _mkdir(path)
|
#define MKDIR(path) _mkdir(path)
|
||||||
#else
|
|
||||||
#define MKDIR(path) mkdir(path, 0755)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define PROGRAM_NAME "funpack.exe"
|
#define PROGRAM_NAME "funpack.exe"
|
||||||
#else
|
#else
|
||||||
|
#include <time.h>
|
||||||
|
#define MKDIR(path) mkdir(path, 0755)
|
||||||
#define PROGRAM_NAME "funpack"
|
#define PROGRAM_NAME "funpack"
|
||||||
#endif
|
#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_LIST (1u << 0)
|
||||||
#define FUNPACK_PROGRESS (1u << 1)
|
#define FUNPACK_PROGRESS (1u << 1)
|
||||||
#define FUNPACK_QUIET (1u << 2)
|
#define FUNPACK_QUIET (1u << 2)
|
||||||
@@ -192,6 +210,7 @@ int main(int argc, char **argv)
|
|||||||
uint64_t count;
|
uint64_t count;
|
||||||
uint64_t i;
|
uint64_t i;
|
||||||
int c;
|
int c;
|
||||||
|
double start_time;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:lpqvh", long_opts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "d:lpqvh", long_opts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -223,6 +242,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
input = argv[optind];
|
input = argv[optind];
|
||||||
|
|
||||||
|
start_time = now_seconds();
|
||||||
|
|
||||||
pak = fpk_open(input);
|
pak = fpk_open(input);
|
||||||
if (!pak) {
|
if (!pak) {
|
||||||
fprintf(stderr, "funpack: cannot open: %s\n", input);
|
fprintf(stderr, "funpack: cannot open: %s\n", input);
|
||||||
@@ -289,8 +310,8 @@ int main(int argc, char **argv)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (!(flags & FUNPACK_QUIET))
|
if (!(flags & FUNPACK_QUIET))
|
||||||
printf("unpacked: %s -> %s (%lu entries)\n", input, out_dir,
|
printf("unpacked: %s -> %s (%lu entries) in %.3fs\n", input, out_dir,
|
||||||
(unsigned long)count);
|
(unsigned long)count, now_seconds() - start_time);
|
||||||
|
|
||||||
free(out_dir);
|
free(out_dir);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user