int main(int argc, char *argv[]){ sim_type_t stype = EVENT_DRIVEN; cs_engine_t *engine; cs_timer_t *timer; cs_event_manager_t *evm; int i; srand(time(NULL)); cs_event_type_t st = (rand() %2 == 0 ? et[0] : et[1]); log4c_init(); log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_INFO, "*** %s, sim_type=%s",\ argv[0], (stype==ACTIVITY_SCAN ? "ACTIVITY_SCAN" : "EVENT_DRIVEN")); //timer initialization timer = (cs_timer_t*) calloc(1, sizeof(cs_timer_t)); cs_init_timer(timer, "CLOCK_TEST"); //set an event to start with cs_event_t *ev_start = CS_NEW_EVENT(1); CS_EVENT_SET_TYPE(ev_start,st); if((evm = (cs_event_manager_t *) malloc(sizeof(cs_event_manager_t)))==NULL){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_FATAL, "*** %s, Memory error", argv[0]); return -1; } if(cs_init_event_manager(evm, 10, timer, stype)!=0){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_FATAL, "*** %s, error\ initiating Event manager", argv[0]); return -1; }
int main (int argc, char ** args) { int args_offset; if (log4c_init()) { g_printerr("Failed to init log4c\r\n"); abort(); } args_offset = 1; args_offset += init_static_vars(argc-args_offset,args+args_offset); if (test_add_service(argc-args_offset,args+args_offset, FALSE)) { NOTICE("%s : ok", "test_add_service(rollback)"); } else { NOTICE("%s : KO", "test_add_service(rollback)"); } if (test_add_service(argc-args_offset,args+args_offset, TRUE)) { NOTICE("%s : ok", "test_add_service(commit)"); } else { NOTICE("%s : KO", "test_add_service(commit)"); } if (test_flush()) { NOTICE("%s : ok", "test_flush()"); } else { NOTICE("%s : KO", "test_flush()"); } return 0; }
int main(int argc, char *argv[]) { sd_test_t *t; int ret; FILE *f; t = sd_test_new(argc, argv); log4c_init(); appender = log4c_appender_get("stream"); f = fopen("/dev/null", "w+"); log4c_appender_set_udata(appender, f); root = log4c_category_get("root"); log4c_category_set_appender(root, appender); log4c_category_set_priority(root, LOG4C_PRIORITY_TRACE); sd_test_add(t, test_big); ret = sd_test_run(t, argc, argv); log4c_appender_set_udata(appender, NULL); fclose(f); sd_test_delete(t); log4c_fini(); return ! ret; }
int main(int argc, char **argv) { if (log4c_init()) { g_message("log4c init error!"); } g_test_init(&argc, &argv, NULL); g_test_add("/misc/icache_insert_1", Fixture, NULL, case_setup, test_icache_insert_1, case_teardown); g_test_add("/misc/icache_insert_2", Fixture, NULL, case_setup, test_icache_insert_2, case_teardown); g_test_add("/misc/icache_query_1", Fixture, NULL, case_setup, test_icache_query_1, case_teardown); g_test_add("/misc/icache_query_2", Fixture, NULL, case_setup, test_icache_query_2, case_teardown); return g_test_run(); }
void setup() { log4c_init(); mkdir(VOLUME_ROOT, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); return; }
void opic_log4c_init() { if (!_log4c_initialized) { log4c_init(); _log4c_initialized = true; } }
bool_ CBase::initialize() { if (0 != log4c_init()) { return false_v; } _category = log4c_category_get("HFRSLog"); return true_v; }
/* Initialize log 4c and log error to stdout upon failure */ static int init_log4c() { int ret = log4c_init(); if (ret) { printf("log4c_init() failed"); } return ret; }
int log_open(const char *category) { if (log4c_init() == 1) { return -1; } log_category = log4c_category_get(category); return 0 ; }
int main(int argc, char **argv) { if (log4c_init()) { g_message("log4c init error!"); } g_test_init(&argc, &argv, NULL); g_test_add("/misc/cache", Fixture, NULL, case_setup, test_cache, case_teardown); return g_test_run(); }
int main(int argc, char **argv) { g_message("enter func %s", __func__); if (log4c_init()) { g_message("log4c init error!"); } g_test_init(&argc, &argv, NULL); g_test_add("/misc/hlfs_find_inode_before_time", Fixture, g_get_current_dir(), hlfs_get_all_snapshots_setup, test_hlfs_get_all_snapshots, hlfs_get_all_snapshots_tear_down); g_message("leave func %s", __func__); return g_test_run(); }
int main(int argc, char** argv) { struct timeval start_time; struct timeval now_time; int looptime = 0; log4c_category_t* mycat = NULL; int i = 0; if (argc < 2) { printf("usage: %s loop_time_in_seconds\n",argv[0]); exit (1); } if (sscanf(argv[1],"%d",&looptime) != 1) { printf("could not convert %s to number of seconds to loop\n",argv[1]); exit(1); } /* You could put your category class into a file with a wrapper macro * to make calling it easier and more consistent */ log4c_init(); mycat = log4c_category_get("six13log.log.app.application1"); i = 0; while ( (now_time.tv_sec - start_time.tv_sec) < looptime) { log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Debugging app 1 - loop %d", i); log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "some error from app1 at line %d in file %s - loop %d", __LINE__, __FILE__, i); sleep(3); i++; } /* Explicitly call the log4c cleanup routine */ if ( log4c_fini()){ printf("log4c_fini() failed"); } return 0; }
int main(int argc, char **args) { int rc = ~0; gs_error_t *err = NULL; gs_grid_storage_t *gs = NULL; g_set_prgname(args[0]); log4c_init(); if (!parse_opt(argc, args)) { PRINT_ERROR("cannot parse the options\n"); return 1; } if (flag_help || argc == 1) { help(); return 0; } if (!meta0_url || !container_name) { meta0_url = strtok(args[1], "/"); container_name = strtok(NULL, "/"); event_message = args[2]; if (!meta0_url || !container_name) { PRINT_ERROR("Missing argument, please check help (-h) for more informations\n"); return 1; } } if (!event_message) { PRINT_ERROR("Missing argument, please check help (-h) for more informations\n"); return 1; } gs = gs_grid_storage_init(meta0_url, &err); if (!gs) PRINT_ERROR("cannot init the GridStorage client\n"); else rc = add_event(gs, container_name, event_message) ? 0 : 1; return rc; }
int main(int argc, char **argv) { if (log4c_init()) { g_message("log4c init error!"); } g_test_init(&argc, &argv, NULL); #if 1 g_test_add("/misc/test_seg_usage_calc", Fixture, NULL, case_setup, test_seg_usage_calc, case_teardown); #endif #if 0 g_test_add("/misc/cache_flush_work_2", Fixture, NULL, case_setup, test_case_cache_flush_2, case_teardown); #endif #if 0 g_test_add("/misc/cache_flush_work_3", Fixture, NULL, case_setup, test_case_cache_flush_3, case_teardown); #endif #if 0 g_test_add("/misc/cache_flush_work_4", Fixture, NULL, case_setup, test_case_cache_flush_4, case_teardown); #endif return g_test_run(); }
int main(int argc, char** args) { int rc = -1; log4c_init(); if (argc <= 1) { help(argc, args); return 1; } if (!parse_opt(argc, args)) { help(argc, args); return 1; } if (flag_help) { help(argc, args); return 0; } if (optind < argc) { GError *local_error = NULL; int i; for (i = optind; i < argc; i++) { /* Sanity check */ PRINT_DEBUG("Going to work with chunk file [%s]\n", args[i]); /* Run decompression */ if(uncompress_chunk2(args[i], preserve, keep_pending, &local_error) != 1) { if(local_error) PRINT_ERROR("Failed to uncompress chunk [%s] :\n %s", args[i], local_error->message); else PRINT_ERROR("Failed to uncompress chunk [%s] : no error\n",args[i]); if (keep_pending) PRINT_DEBUG("%s.pending file kept\n", args[i]); } else { PRINT_DEBUG("Chunk [%s] uncompressed\n",args[i]); } } } return rc; }
static void env_init (void) { static volatile int init_done = 0; char *enabled=NULL, *file=NULL, *str; char *glib=NULL; if (!init_done) { init_done = 1; if (!g_thread_supported ()) g_thread_init (NULL); /* Enables log4c logging */ if (NULL != (enabled = getenv(ENV_LOG4C_ENABLE))) { if (enabled[0] != '0') { // I mean '0', not '\0' if (log4c_init()) g_printerr("cannot load log4c\n"); else if ((file=getenv(ENV_LOG4C_LOAD))) log4c_load(file); } } if (NULL != (glib = getenv(ENV_GLIB2_ENABLE))) { g_log_set_default_handler(logger_stderr, NULL); } else if (!enabled) { g_log_set_default_handler(logger_noop, NULL); } /*configure the sleep time between two failed ADD actions*/ wait_on_add_failed = 10000UL; if ((str = getenv(ENV_WAIT_ON_FAILED_ADD))) { gint64 i64 = g_ascii_strtoll( str, NULL, 10 ); if (i64>=0LL && i64<=10000LL) wait_on_add_failed = i64; } } }
void init(CodecConfiguration *configuration) { // Need to initialize loggers. // Then need to pre-allocate pinned memory and Cuda Global Memory. gpuTunerCategory = log4c_category_get("performance_tuning_gpu_logger"); cpuTunerCategory = log4c_category_get("performance_tuning_cpu_logger"); log4c_init(); currentMode = PRODUCTION; config_t propConfig; config_init(&propConfig); if (!config_read_file(&propConfig, configuration->propertyFilePath)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&propConfig), config_error_line(&propConfig), config_error_text(&propConfig)); config_destroy(&propConfig); return; } config_lookup_bool(&propConfig, "isUseGpu", &useGpu); config_lookup_bool(&propConfig, "isUseDynamicParallelism", &useDynamicParallelism); config_lookup_int(&propConfig, "max_packet_size", &maxPacketSize); config_lookup_int(&propConfig, "max_batch_size", &maxBatchSize); config_lookup_int(&propConfig, "tuner_loop_count", &tunerLoopCount); config_lookup_int(&propConfig, "number_of_cpu_cores", &nCpuCores); config_lookup_int(&propConfig, "cuda_stream_count", &cudaStreamCount); config_lookup_bool(&propConfig, "print_accuracy_log", &printAccuracyLog); currentCudaContextSize = (uint32_t) maxBatchSize; cudaPduContext = allocatePinnedPduContext(maxBatchSize); initCudaParameters((uint32_t) maxBatchSize, ((uint64_t) maxPacketSize * (uint64_t) maxBatchSize)); int isTunerMode = 0; config_lookup_bool(&propConfig, "isTunerMode", &isTunerMode); currentMode = isTunerMode ? TUNER : PRODUCTION; printf("Is Use GPU %d | Max Packet Size %d | Max Batch Size %d | Tuner Mode %d | Accuracy Log %d\n", useGpu, maxPacketSize, maxBatchSize, currentMode, printAccuracyLog); fflush(stdout); switch (currentMode) { case TUNER: { configureTuner(&propConfig); break; } default: { int x, y, z; config_setting_t *block = config_lookup(&propConfig, "production.block"); config_setting_t *grid = config_lookup(&propConfig, "production.grid"); config_setting_lookup_int(block, "x", &x); config_setting_lookup_int(block, "y", &y); config_setting_lookup_int(block, "z", &z); blockDimProdction.x = (uint32_t) x; blockDimProdction.y = (uint32_t) y; blockDimProdction.z = (uint32_t) z; config_setting_lookup_int(grid, "x", &x); config_setting_lookup_int(grid, "y", &y); config_setting_lookup_int(grid, "z", &z); gridDimProduction.x = (uint32_t) x; gridDimProduction.y = (uint32_t) y; gridDimProduction.z = (uint32_t) z; config_lookup_int(&propConfig, "production.cpu_decode_threshold", &cpuDecodeThreshold); } } }
int main(int argc, char **argv) { int i; int ret = 0; FILE *file; char *line; int16_t port; ret = log4c_init(); if (ret != 0) { printf("log4c_init failed[%d]\n", ret); return (ret); } mycat = log4c_category_get("six13log.log.app.application1"); if (!mycat) { printf("log4c_category_get(\"six13log.log.app.application1\"); failed\n"); return (0); } for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-d") == 0) { change_to_deamon(); break; } } log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "conn_srv run"); if (init_conn_client_map() != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init client map failed"); goto done; } ret = game_event_init(); if (ret != 0) goto done; callback_server.cb_get_client_map = get_server_client_map; callback_server.cb_listen_pre = conn_cb_server_listen_pre; callback_server.cb_listen_after = conn_cb_server_listen_after; callback_client.cb_get_client_map = get_client_client_map; callback_client.cb_listen_pre = conn_cb_client_listen_pre; callback_client.cb_listen_after = conn_cb_client_listen_after; file = fopen("../server_info.ini", "r"); if (!file) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "open server_info.ini failed[%d]", errno); ret = -1; goto done; } line = get_first_key(file, "conn_srv_listen_port"); port = atoi(get_value(line)); if (port <= 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv_listen_port"); ret = -1; goto done; } ret = game_add_listen_event(port, &callback_client); if (ret != 0) goto done; line = get_first_key(file, "conn_srv_port"); port = atoi(get_value(line)); if (port <= 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv_port"); ret = -1; goto done; } ret = game_add_listen_event(port, &callback_server); if (ret != 0) goto done; fclose(file); struct event event_timer; struct timeval t1 = {5, 0}; add_timer(t1, &event_timer); // event_timer.ev_callback = cb_testtool_timer; struct timeval t2 = {2, 0}; add_timer(t2, NULL); struct timeval t3 = {4, 0}; add_timer(t3, NULL); if (SIG_ERR == signal(SIGPIPE,SIG_IGN)) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "set sigpipe ign failed"); return (0); } ret = event_base_loop(base, 0); log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "event_base_loop stoped[%d]", ret); struct timeval tv; event_base_gettimeofday_cached(base, &tv); done: log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "conn_srv stoped[%d]", ret); return (ret); }
int main(int argc, char *argv[]) { int i; int ret; // CONTAINER *tmp; int resume = 0; struct sockaddr_in sin; int16_t port; FILE *file; char *line; char *ip; srandom(time(NULL)); ret = log4c_init(); if (ret != 0) { printf("log4c_init failed[%d]\n", ret); return ret; } mycat = log4c_category_get("six13log.log.app"); if (!mycat) { printf("log4c_category_get(\"six13log.log.app.application1\"); failed\n"); return (0); } obj_count_loger = log4c_category_get("count_obj_cate"); if (!obj_count_loger) { printf("log4c_category_get(\"six13log.log.app.application2\"); failed\n"); return (0); } for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-d") == 0) { change_to_deamon(); --argc; break; } } if (argc > 1) resume = 1; ret = load_all_config(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load all config fail[%d]\n", ret); return (-1); } ret = init_gm_system(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init gm system fail[%d]\n", ret); return (-1); } sc_interface = load_game_script(); if (!sc_interface) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load script fail[%d]\n"); return (-1); } log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "game_srv run"); role_rbdata_init_head(); file = fopen("../server_info.ini", "r"); if (!file) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "open server_info.ini failed[%d]", errno); return (-1); } line = get_first_key(file, "game_srv_key"); key = strtoul(get_value(line), NULL, 0); if (key == 0 || key == ULONG_MAX) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no game_srv_key"); return (-1); } if (alloc_shared_mem(resume) != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "alloc_shared_mem[%d] failed", resume); return (-1); } ret = init_all_objs(resume); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init_all_objs[%d] failed[%d]", resume, ret); return (-1); } ret = create_all_static_scene(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "creeate_all_static_scene[%d] failed[%d]", resume, ret); return (-1); } // test_fight(); // return (0); ret = game_event_init(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_event_init failed[%d]", ret); return (-1); } line = get_first_key(file, "conn_srv_ip"); for (i = 0; i < MAX_CONN_SRV && line != NULL; ++i) { memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; conn_server[i].cb_recv = gamesrv_cb_conn_recv; ip = get_value(line); if (!ip) break; line = get_next_key(file, "conn_srv_port"); if (!line) break; port = atoi(get_value(line)); if (port <= 0) break; line = get_next_key(file, "conn_srv_ip"); sin.sin_port = htons(port); ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr); if (ret != 1) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &conn_server[i]); if (ret < 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } conn_server[i].fd = ret; } if (i == 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv"); return (-1); } max_conn_srv = i; line = get_first_key(file, "db_srv_ip"); for (i = 0; i < MAX_ROLEDB_SRV && line != NULL; ++i) { memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; roledb_server[i].cb_recv = gamesrv_cb_roledb_recv; ip = get_value(line); if (!ip) break; line = get_next_key(file, "db_srv_port"); if (!line) break; port = atoi(get_value(line)); if (port <= 0) break; line = get_next_key(file, "db_srv_ip"); sin.sin_port = htons(port); ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr); if (ret != 1) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &roledb_server[i]); if (ret < 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } roledb_server[i].fd = ret; } if (i == 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no roldb_srv"); return (-1); } max_roledb_srv = i; active_roledb_srv = &roledb_server[0]; fclose(file); struct timeval t1 = {5, 0}; add_timer(t1, &log_object_timer); log_object_timer.ev_callback = cb_log_object_timer; ret = event_base_loop(base, 0); log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "event_base_loop stoped[%d]", ret); /* tmp = create_container(); tmp = create_container(); tmp = create_container(); destory_container(tmp); tmp = create_container(); destory_container(tmp); tmp = create_container(); */ /* GAME_CIRCLEQ_FOREACH(tmp, pool_container_freed, base.list_free) { printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx); } printf("\n ================== \n"); GAME_CIRCLEQ_FOREACH(tmp, pool_container_used, base.list_used) { printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx); } */ return (0); }
extern void __attribute__ ((constructor)) __log4c_init(void) { #ifdef WITH_CONSTRUCTORS log4c_init(); #endif }
int main(int argc, char** argv) { struct timeval start_time; struct timeval now_time; user_locinfo_t userloc; int looptime = 0; log4c_category_t* mycat = NULL; /* setup for the extra user location info */ char hostname[256]; int pid = getpid(); gethostname(hostname,255); hostname[255] = '\0'; userloc.hostname = hostname; userloc.pid = pid; if (argc < 2) { printf("usage: %s loop_time_in_seconds\n",argv[0]); exit (1); } if (sscanf(argv[1],"%d",&looptime) != 1) { printf("could not convert %s to number of seconds to loop\n",argv[1]); exit(1); } /* * Here, if using explicit initialization (as opposed to implicit via the * init phase of the library) it's important to initialize the custom appenders * and layouts before calling log4c_init(). * This is because when log4c_init() parses the config file it looks for the * types mentioned in the file to set up the relations between categories, * appenders and layouts. If it does not find a coresponding type in the * internal hash tables, it creates one with that type name, but the function * table is not set up--so that at log time nothing happens. * */ init_examples_lib(); init_userloc_formatters(); log4c_init(); /* * Here we add our own userdefined location info, and then pick that up in our formatter */ mycat = log4c_category_get("six13log.log.app.application3"); gettimeofday(&start_time, NULL); gettimeofday(&now_time, NULL); while ( (now_time.tv_sec - start_time.tv_sec) < looptime) { /* LINE and FILE are bad */ log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Debugging app 3, direct log call"); /* using the new API directly */ const log4c_location_info_t locinfo2 = LOG4C_LOCATION_INFO_INITIALIZER(&userloc); log4c_category_log_locinfo(mycat, &locinfo2, LOG4C_PRIORITY_DEBUG, "Debugging application number THREE with extra user location"); const log4c_location_info_t locinfo3 = LOG4C_LOCATION_INFO_INITIALIZER(NULL); log4c_category_log_locinfo(mycat, &locinfo3, LOG4C_PRIORITY_ERROR, "some error from app at line %d in file %s with NULL for extra user location info", __LINE__, __FILE__); /* using the new API with the define wrapper */ log4c_category_log_userinfo(mycat, &userloc, LOG4C_PRIORITY_DEBUG, "Debug app3 wrapper define"); sleep(3); gettimeofday(&now_time, NULL); } /* Explicitly call the log4c cleanup routine */ if ( log4c_fini()){ printf("log4c_fini() failed"); } return 0; }
int main(int argc, char *argv[]) { int flags = 0; char *buffer = NULL; int i; usec_t start; usec_t stop; char *test_name; /* declare and get a reference to some unconfigured appenders */ log4c_appender_t *mmap_appender = log4c_appender_get("bench.mmap"); log4c_appender_t *stream_appender = log4c_appender_get("stdout"); log4c_appender_t *stream2_appender = log4c_appender_get("bench.stream2"); log4c_appender_t *streamfile_appender = log4c_appender_get("bench.stream"); /* * Obligatory log4c init call */ log4c_init(); /* * Get some categories */ catmmap = log4c_category_get("mmap"); catstream = log4c_category_get("stream"); catstream2 = log4c_category_get("stream2"); catstream_file = log4c_category_get("stream_file"); /* * Read command line options */ getopts(argc, argv); /* * Configure the categories and appenders */ log4c_appender_set_type(mmap_appender, log4c_appender_type_get("mmap")); log4c_category_set_appender(catmmap, mmap_appender); log4c_category_set_appender(catstream, stream_appender); log4c_appender_set_type(stream2_appender, log4c_appender_type_get("stream2")); log4c_category_set_appender(catstream2, stream2_appender); log4c_category_set_appender(catstream_file, streamfile_appender); log4c_category_set_priority(log4c_category_get("root"), LOG4C_PRIORITY_ERROR); /* * Get a buffer for the message */ buffer = (char *) malloc(g_msgsize * sizeof(char)); memset(buffer, 'X', g_msgsize); buffer[g_msgsize - 1] = '\0'; /* * Calibration: do a couple of 1 second sleeps to make sure * the timing routines are in working order. */ start = my_utime(); for (i = 0; i < 2; i++) { sleep(1); } stop = my_utime(); display_time("calibration 2 x 1 second sleep calls", start, stop, (stop - start), (stop - start) / 2); /* logs that write to the screen, if required */ if ( !g_noscreen_appenders) { /* * fprintf writing to the screen */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { fprintf(stdout, "%s\n", buffer); } stop = my_utime(); display_time("fprintf", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * log4c writing to the screen */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream, "%s", buffer); } stop = my_utime(); display_time("fprintf", start, stop, (stop - start), (stop - start) / g_num_msgs); } /* Logs that write to files */ /* * mmap appender writing to bench.mmap * * On windows as this type is not implemented it makes pretty much * null calls to log4c--so it does nothing but is safe. */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catmmap, "%s", buffer); } stop = my_utime(); display_time("mmap", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * stream appender writing to bench.stream */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream_file, "%s", buffer); } stop = my_utime(); display_time("stream_file", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * stream2 appender writing to bench.stream2 * in buffered mode */ log4c_appender_open(stream2_appender); flags = log4c_stream2_get_flags(stream2_appender); start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream2, "%s", buffer); } stop = my_utime(); test_name = (flags & LOG4C_STREAM2_UNBUFFERED ? "stream2 unbuffered -" : "stream2 buffered -"); display_time(test_name, start, stop, (stop - start), (stop - start) / g_num_msgs); log4c_appender_close(stream2_appender); /* * stream2 appender writing to bench.stream2 * in unbuffered mode -- for comparison with buffered mode * test above */ log4c_appender_open(stream2_appender); log4c_stream2_set_flags(stream2_appender, LOG4C_STREAM2_UNBUFFERED); flags = log4c_stream2_get_flags(stream2_appender); start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream2, "%s", buffer); } stop = my_utime(); display_time((flags & LOG4C_STREAM2_UNBUFFERED ? "stream2 unbuffered -" : "stream2 buffered -"), start, stop, (stop - start), (stop - start) / g_num_msgs); log4c_appender_close(stream2_appender); /* * Obligatory log4c cleanup call */ log4c_fini(); free(buffer); return 0; }
/* mkfs.lhfs -l http://<path> -s name */ int main(int argc, char *argv[]) { if (log4c_init()) { g_message("log4c_init failed!"); } GError *error = NULL; GOptionContext *context; context = g_option_context_new("- mkfs hlfs"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_help_enabled(context, TRUE); g_option_group_set_error_hook(g_option_context_get_main_group(context), (GOptionErrorFunc)error_func); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_message("option parsing failed: %s", error->message); exit(EXIT_FAILURE); } //g_print("location is :%s\n",location); //g_print("fsname is :%s\n",fsname); //g_print("block size is :%d\n",block_size); //g_print("segment size is :%d\n",seg_size); // seg_size = SEGMENT_SIZE; if(seg_size <= 0 || seg_size%(1024*1024)!=0){ g_message("segsize <=0 or segment size must 1M margin"); return -1; } if(block_size <=0 || block_size%(512) != 0){ g_message("blocksize <=0 or block size must 512 margin"); return -1; } if(max_fs_size <=0){ g_message("max fs size <=0"); return -1; } struct back_storage *storage = init_storage_handler(uri); if(NULL ==storage){ g_message("can not get storage handler for uri:%s",uri); g_option_context_free(context); return -1; } if((0==storage->bs_file_is_exist(storage,NULL)) && (0==storage->bs_file_is_exist(storage,"superblock"))){ g_message("hlfs with uri:%s has exist",uri); g_option_context_free(context); return 1; } if( 0!=storage->bs_file_mkdir(storage,NULL)){ g_message("can not mkdir for our fs %s",uri); g_option_context_free(context); return -1; } GKeyFile *sb_keyfile= g_key_file_new(); g_key_file_set_string(sb_keyfile,"METADATA","uri",uri); g_key_file_set_integer(sb_keyfile,"METADATA","block_size",block_size); g_key_file_set_integer(sb_keyfile,"METADATA","segment_size",seg_size); g_key_file_set_uint64(sb_keyfile,"METADATA","max_fs_size",max_fs_size); gchar *data = g_key_file_to_data(sb_keyfile,NULL,NULL); g_message("key file data :%s",data); char *head,*hostname,*dir,*fs_name; int port; parse_from_uri(uri,&head,&hostname,&dir,&fs_name,&port); char *sb_file_path = g_build_filename(dir,fs_name,"superblock",NULL); g_message("sb file path %s",sb_file_path); bs_file_t file = storage->bs_file_create(storage,"superblock"); g_message("sb file path 1%s",sb_file_path); //bs_file_t file = storage->bs_file_open(storage,"superblock",BS_WRITEABLE); if (NULL == file) { g_message("open file :superblock failed"); g_free(sb_file_path); g_option_context_free(context); return -1; } g_message("sb file path 2%s",sb_file_path); int size = storage->bs_file_append(storage, file,(char*)data,strlen(data)+1); if(size != strlen(data)+1){ g_message("can not write superblock file"); g_free(sb_file_path); g_option_context_free(context); return -1; } g_message("append size:%d",size); storage->bs_file_flush(storage,file); storage->bs_file_close(storage,file); deinit_storage_handler(storage); if (log4c_fini()) { g_message("log4c_fini failed!"); } return 0; }
/* * ./test -u uri -r request_size -a total_size * uri: /tmp/testenv/testfs * request_size: 4096bytes * total_size: 409600bytes */ int main(int argc, char *argv[]){ if (log4c_init()) { g_message("log4c_init error!"); } GError *error = NULL; GOptionContext *context; context = g_option_context_new("- hlfs test -"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_help_enabled(context, TRUE); g_option_group_set_error_hook(g_option_context_get_main_group(context), (GOptionErrorFunc)error_func); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_message("option parsing failed: %s", error->message); exit(EXIT_FAILURE); } g_option_context_free(context); g_print("TEST: uri is %s, request size is %d, total size is %d\n", uri, request_size, total_size); char *content = (char*)g_malloc0(request_size); HLFS_CTRL * ctrl = init_hlfs(uri); g_assert(ctrl != NULL); uint64_t ret = 0; ret = hlfs_open(ctrl,1); g_assert(ret == 0); g_print("TEST hlfs open over \n"); g_print("test hlfs write\n"); sleep(2); int offset = 0; while(offset < total_size){ ret = hlfs_write(ctrl,content,request_size,offset); g_assert(ret==request_size); offset +=request_size; printf("offset:%d\n",offset); } g_print("TEST hlfs write over \n"); g_print("test hlfs read\n"); sleep(2); offset = 0; while(offset < total_size){ ret = hlfs_read(ctrl,content,request_size,offset); g_assert(ret==request_size); offset +=request_size; printf("offset:%d\n",offset); } g_print("again ------------------------\n"); offset = 0; /******************************************************************************************************************************************/ int fdd; int len; int rett; int i; //char read_buf[409600]; char *contentt = (char*)g_malloc0(40960); if((fdd = open("test.c", O_RDONLY )) == -1){ my_err("open", __LINE__); } else { g_print("Open file success\n"); } //if(write(fd, write_buf, strlen(write_buf)) != strlen(write_buf)){ // my_err("write", __LINE__); //} if(lseek(fdd, 0, SEEK_END) == -1){ my_err("lseek", __LINE__); } if((len = lseek(fdd, 0, SEEK_CUR)) == -1){ my_err("lseek", __LINE__); } if((lseek(fdd, 0, SEEK_SET)) == -1){ my_err("lseek", __LINE__); } printf("len: %d\n", len); if((rett = read(fdd, contentt, len)) < 0){ my_err("lseek",__LINE__); } strcpy(content, contentt); //for(i = 0; i< len; i ++){ g_print("%s ", contentt); //} g_print("\n"); g_print("/************************************************/"); if(lseek(fdd, 10, SEEK_END) == -1){ my_err("lseek", __LINE__); } //close (fdd); /****************************************************************************************************/ //FILE* srcFile = NULL; int srcLength = lseek(fdd, 0, SEEK_CUR); int SNAPPY_OK = 0; char* pSrcBuffer = (char*)g_malloc0(srcLength); read(fdd, pSrcBuffer, srcLength); size_t cbOfCompressed = 32+ srcLength + srcLength/6; char* pCompressedBuffer = (char*)g_malloc0(cbOfCompressed); if (snappy_compress(pSrcBuffer, srcLength, pCompressedBuffer, &cbOfCompressed) == SNAPPY_OK) { free(pSrcBuffer); pSrcBuffer = NULL; if (snappy_validate_compressed_buffer(pCompressedBuffer, cbOfCompressed) == SNAPPY_OK) { size_t cbDecompress = 0; snappy_uncompressed_length(pCompressedBuffer, cbOfCompressed, &cbDecompress); assert(cbDecompress == srcLength); char* pDecompressedBuffer = (char*)g_malloc0(cbDecompress); snappy_uncompress(pCompressedBuffer, cbOfCompressed, pDecompressedBuffer, (size_t*)&cbDecompress); int file; file = open("test1.txt", O_CREAT | O_RDWR ); //_wfopen_s(&file, _T("123.pdf"), _T("ab")); write(file, pDecompressedBuffer, cbDecompress); close(file); free(pDecompressedBuffer); pDecompressedBuffer = NULL; } } close (fdd); /******************************************************************************************************************************************/ // while(offset < total_size){ // ret = hlfs_write(ctrl,content,request_size,offset); // g_assert(ret==request_size); // offset +=request_size; // printf("offset:%d\n",offset); // } // g_print("TEST hlfs write over \n"); // g_print("test hlfs read\n"); // sleep(2); // offset = 0; while(offset < len+1){ ret = hlfs_read(ctrl,content,len,offset); g_assert(ret==len); offset +=len; printf("offset:%d\n",offset); } g_free(content); g_free(contentt); ret = hlfs_close(ctrl); deinit_hlfs(ctrl); g_print("TEST hlfs test over \n"); return 0; }