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,79 +233,98 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_type == TEST_TYPE_APPEND) {
|
for (test_type=type_start; test_type<=type_last; test_type++) {
|
||||||
memset(&record, 0, sizeof(record));
|
if (test_type == TEST_TYPE_APPEND) {
|
||||||
record.op_type = 'C';
|
memset(&record, 0, sizeof(record));
|
||||||
record.slice_type = DA_SLICE_TYPE_FILE;
|
record.op_type = 'C';
|
||||||
record.storage.version = 1111;
|
record.slice_type = DA_SLICE_TYPE_FILE;
|
||||||
record.oid = 9007211709265131LL;
|
record.storage.version = 1111;
|
||||||
record.fid = 0;
|
record.oid = 9007211709265131LL;
|
||||||
record.storage.trunk_id = 61;
|
record.fid = 0;
|
||||||
record.storage.length = 62;
|
record.storage.trunk_id = 61;
|
||||||
record.storage.offset = 12345;
|
record.storage.length = 62;
|
||||||
record.storage.size = 64;
|
record.storage.offset = 12345;
|
||||||
}
|
record.storage.size = 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
start_time_us = get_current_time_us();
|
||||||
|
for (i=0; i<LOOP; i++) {
|
||||||
|
switch (test_type) {
|
||||||
|
case TEST_TYPE_APPEND:
|
||||||
|
cache_binlog_filename_by_sprintf(data_path, subdir_name,
|
||||||
|
subdirs, ++id, full_filename1, sizeof(full_filename1));
|
||||||
|
fast_buffer_reset(&buffer);
|
||||||
|
log_pack_by_sprintf(&record, &buffer, have_extra_field);
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_ITOA:
|
||||||
|
sprintf(buff, "%"PRId64, id);
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_FTOA:
|
||||||
|
sprintf(buff, "%.2f", d);
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_INT2HEX:
|
||||||
|
sprintf(buff, "%x", (int)id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf_time_us = (get_current_time_us() - start_time_us);
|
||||||
|
|
||||||
|
start_time_us = get_current_time_us();
|
||||||
|
for (i=0; i<LOOP; i++) {
|
||||||
|
switch (test_type) {
|
||||||
|
case TEST_TYPE_APPEND:
|
||||||
|
cache_binlog_filename_by_append(data_path, subdir_name,
|
||||||
|
subdirs, ++id, full_filename2, sizeof(full_filename2));
|
||||||
|
fast_buffer_reset(&buffer);
|
||||||
|
log_pack_by_append(&record, &buffer, have_extra_field);
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_ITOA:
|
||||||
|
len = fc_itoa(id, buff);
|
||||||
|
*(buff + len) = '\0';
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_FTOA:
|
||||||
|
len = fc_ftoa(d, 2, buff);
|
||||||
|
*(buff + len) = '\0';
|
||||||
|
break;
|
||||||
|
case TEST_TYPE_INT2HEX:
|
||||||
|
int2hex(id, buff, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
convert_time_us = (get_current_time_us() - start_time_us);
|
||||||
|
|
||||||
|
if (convert_time_us > 0) {
|
||||||
|
ratio = (double)sprintf_time_us / (double)convert_time_us;
|
||||||
|
} else {
|
||||||
|
ratio = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
start_time_us = get_current_time_us();
|
|
||||||
for (i=0; i<LOOP; i++) {
|
|
||||||
switch (test_type) {
|
switch (test_type) {
|
||||||
case TEST_TYPE_APPEND:
|
|
||||||
cache_binlog_filename_by_sprintf(data_path, subdir_name,
|
|
||||||
subdirs, ++id, full_filename1, sizeof(full_filename1));
|
|
||||||
fast_buffer_reset(&buffer);
|
|
||||||
log_pack_by_sprintf(&record, &buffer, have_extra_field);
|
|
||||||
break;
|
|
||||||
case TEST_TYPE_ITOA:
|
case TEST_TYPE_ITOA:
|
||||||
sprintf(buff, "%"PRId64, id);
|
caption = "itoa";
|
||||||
break;
|
break;
|
||||||
case TEST_TYPE_FTOA:
|
case TEST_TYPE_FTOA:
|
||||||
sprintf(buff, "%.2f", d);
|
caption = "ftoa";
|
||||||
break;
|
break;
|
||||||
case TEST_TYPE_INT2HEX:
|
case TEST_TYPE_INT2HEX:
|
||||||
sprintf(buff, "%x", (int)id);
|
caption = "int2hex";
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sprintf_time_us = (get_current_time_us() - start_time_us);
|
|
||||||
|
|
||||||
start_time_us = get_current_time_us();
|
|
||||||
for (i=0; i<LOOP; i++) {
|
|
||||||
switch (test_type) {
|
|
||||||
case TEST_TYPE_APPEND:
|
case TEST_TYPE_APPEND:
|
||||||
cache_binlog_filename_by_append(data_path, subdir_name,
|
caption = "append";
|
||||||
subdirs, ++id, full_filename2, sizeof(full_filename2));
|
|
||||||
fast_buffer_reset(&buffer);
|
|
||||||
log_pack_by_append(&record, &buffer, have_extra_field);
|
|
||||||
break;
|
|
||||||
case TEST_TYPE_ITOA:
|
|
||||||
len = fc_itoa(id, buff);
|
|
||||||
*(buff + len) = '\0';
|
|
||||||
break;
|
|
||||||
case TEST_TYPE_FTOA:
|
|
||||||
len = fc_ftoa(d, 2, buff);
|
|
||||||
*(buff + len) = '\0';
|
|
||||||
break;
|
|
||||||
case TEST_TYPE_INT2HEX:
|
|
||||||
int2hex(id, buff, 0);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
caption = "unkown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
printf("sprintf time: %d ms, %s time: %d ms, "
|
||||||
|
"sprintf time / %s time: %d%%\n",
|
||||||
|
sprintf_time_us / 1000, caption, convert_time_us / 1000,
|
||||||
|
caption, (int)(ratio * 100.00));
|
||||||
}
|
}
|
||||||
convert_time_us = (get_current_time_us() - start_time_us);
|
|
||||||
|
|
||||||
if (convert_time_us > 0) {
|
|
||||||
ratio = (double)sprintf_time_us / (double)convert_time_us;
|
|
||||||
} else {
|
|
||||||
ratio = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sprintf time: %d ms, %s time: %d ms, "
|
|
||||||
"sprintf time / %s time: %d%%\n",
|
|
||||||
sprintf_time_us / 1000, caption, convert_time_us / 1000,
|
|
||||||
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