parent
d9d6255621
commit
ec8e47f831
|
|
@ -27,7 +27,8 @@
|
||||||
#include "fastcommon/sched_thread.h"
|
#include "fastcommon/sched_thread.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TEST_TYPE_ITOA = 1,
|
TEST_TYPE_NONE = 0,
|
||||||
|
TEST_TYPE_ITOA,
|
||||||
TEST_TYPE_FTOA,
|
TEST_TYPE_FTOA,
|
||||||
TEST_TYPE_INT2HEX,
|
TEST_TYPE_INT2HEX,
|
||||||
TEST_TYPE_APPEND
|
TEST_TYPE_APPEND
|
||||||
|
|
@ -161,7 +162,7 @@ static inline int cache_binlog_filename_by_append(
|
||||||
|
|
||||||
static void usage(const char *program)
|
static void usage(const char *program)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s [-t {itoa | ftoa | int2hex | append}]\n",
|
fprintf(stderr, "Usage: %s [-t {itoa | ftoa | int2hex | append | all}]\n",
|
||||||
program);
|
program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,6 +178,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
TestType test_type = TEST_TYPE_ITOA;
|
TestType test_type = TEST_TYPE_ITOA;
|
||||||
|
TestType type_start;
|
||||||
|
TestType type_last;
|
||||||
uint64_t id = 123456;
|
uint64_t id = 123456;
|
||||||
double d = 123.456;
|
double d = 123.456;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
@ -191,7 +194,7 @@ int main(int argc, char *argv[])
|
||||||
char full_filename1[PATH_MAX];
|
char full_filename1[PATH_MAX];
|
||||||
char full_filename2[PATH_MAX];
|
char full_filename2[PATH_MAX];
|
||||||
char buff[32] = {0};
|
char buff[32] = {0};
|
||||||
char *caption = "itoa";
|
char *caption;
|
||||||
|
|
||||||
log_init();
|
log_init();
|
||||||
g_current_time = time(NULL);
|
g_current_time = time(NULL);
|
||||||
|
|
@ -201,6 +204,7 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_start = type_last = TEST_TYPE_ITOA;
|
||||||
while ((ch=getopt(argc, argv, "ht:")) != -1) {
|
while ((ch=getopt(argc, argv, "ht:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
@ -208,17 +212,16 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
case 't':
|
case 't':
|
||||||
if (strcasecmp(optarg, "itoa") == 0) {
|
if (strcasecmp(optarg, "itoa") == 0) {
|
||||||
test_type = TEST_TYPE_ITOA;
|
type_start = type_last = TEST_TYPE_ITOA;
|
||||||
caption = "itoa";
|
|
||||||
} else if (strcasecmp(optarg, "ftoa") == 0) {
|
} else if (strcasecmp(optarg, "ftoa") == 0) {
|
||||||
test_type = TEST_TYPE_FTOA;
|
type_start = type_last = TEST_TYPE_FTOA;
|
||||||
caption = "ftoa";
|
|
||||||
} else if (strcasecmp(optarg, "int2hex") == 0) {
|
} else if (strcasecmp(optarg, "int2hex") == 0) {
|
||||||
test_type = TEST_TYPE_INT2HEX;
|
type_start = type_last = TEST_TYPE_INT2HEX;
|
||||||
caption = "int2hex";
|
|
||||||
} else if (strcasecmp(optarg, "append") == 0) {
|
} else if (strcasecmp(optarg, "append") == 0) {
|
||||||
test_type = TEST_TYPE_APPEND;
|
type_start = type_last = TEST_TYPE_APPEND;
|
||||||
caption = "append";
|
} else if (strcasecmp(optarg, "all") == 0) {
|
||||||
|
type_start = TEST_TYPE_ITOA;
|
||||||
|
type_last = TEST_TYPE_APPEND;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "invalid type: %s\n", optarg);
|
fprintf(stderr, "invalid type: %s\n", optarg);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
@ -230,6 +233,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (test_type=type_start; test_type<=type_last; test_type++) {
|
||||||
if (test_type == TEST_TYPE_APPEND) {
|
if (test_type == TEST_TYPE_APPEND) {
|
||||||
memset(&record, 0, sizeof(record));
|
memset(&record, 0, sizeof(record));
|
||||||
record.op_type = 'C';
|
record.op_type = 'C';
|
||||||
|
|
@ -299,10 +303,28 @@ int main(int argc, char *argv[])
|
||||||
ratio = 1.0;
|
ratio = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (test_type) {
|
||||||
|
case TEST_TYPE_ITOA:
|
||||||
|
caption = "itoa";
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_FTOA:
|
||||||
|
caption = "ftoa";
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_INT2HEX:
|
||||||
|
caption = "int2hex";
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_APPEND:
|
||||||
|
caption = "append";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
caption = "unkown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
printf("sprintf time: %d ms, %s time: %d ms, "
|
printf("sprintf time: %d ms, %s time: %d ms, "
|
||||||
"sprintf time / %s time: %d%%\n",
|
"sprintf time / %s time: %d%%\n",
|
||||||
sprintf_time_us / 1000, caption, convert_time_us / 1000,
|
sprintf_time_us / 1000, caption, convert_time_us / 1000,
|
||||||
caption, (int)(ratio * 100.00));
|
caption, (int)(ratio * 100.00));
|
||||||
|
}
|
||||||
|
|
||||||
fast_buffer_destroy(&buffer);
|
fast_buffer_destroy(&buffer);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/file.h>
|
||||||
#include "fastcommon/logger.h"
|
#include "fastcommon/logger.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
@ -36,6 +37,15 @@ int main(int argc, char *argv[])
|
||||||
log_take_over_stdout();
|
log_take_over_stdout();
|
||||||
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED | LOG_COMPRESS_FLAGS_NEW_THREAD);
|
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED | LOG_COMPRESS_FLAGS_NEW_THREAD);
|
||||||
|
|
||||||
|
log_set_filename("/opt/fastcfs/fuse/test.log");
|
||||||
|
|
||||||
|
|
||||||
|
if (flock(g_log_context.log_fd, LOCK_EX) != 0) {
|
||||||
|
logError("flock fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
flock(g_log_context.log_fd, LOCK_UN);
|
||||||
|
|
||||||
printf("sizeof(LogContext): %d, time_precision: %d, compress_log_flags: %d, "
|
printf("sizeof(LogContext): %d, time_precision: %d, compress_log_flags: %d, "
|
||||||
"use_file_write_lock: %d\n", (int)sizeof(LogContext),
|
"use_file_write_lock: %d\n", (int)sizeof(LogContext),
|
||||||
g_log_context.time_precision,
|
g_log_context.time_precision,
|
||||||
|
|
@ -46,7 +56,7 @@ int main(int argc, char *argv[])
|
||||||
"by log_it_ex, timestamp: %d", (int)time(NULL));
|
"by log_it_ex, timestamp: %d", (int)time(NULL));
|
||||||
|
|
||||||
len = sprintf(buff, "this is by log_it_ex1, "
|
len = sprintf(buff, "this is by log_it_ex1, "
|
||||||
"timestamp: %d", (int)time(NULL));
|
"timestamp: %ld", (long)time(NULL));
|
||||||
log_it_ex1(&g_log_context, LOG_INFO, buff, len);
|
log_it_ex1(&g_log_context, LOG_INFO, buff, len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue