예제 #1
0
void    _test_log(){
    system("rm -f ./test_log.log");

    FLOG_DEBUG(log_handler, "debug log test\n");
    FLOG_ERROR(log_handler, "error log test\n");
    flog_set_level(LOG_LEVEL_ERROR);
    sleep(2);   // wait for log system

    int fd = open("test_log.log", O_RDONLY);
    FTU_ASSERT_GREATER_THAN_INT(0, fd);

    char assert_info[100];
    memset(assert_info, 0, 100);
    int bytes_read = read(fd, assert_info, 100);
    FTU_ASSERT_GREATER_THAN_INT(0, bytes_read);

    printf("read log info:%s\n", assert_info);
    char* ptr = strstr(assert_info, "error log test");
    printf("find ptr=%p\n", ptr);
    FTU_ASSERT_EXPRESS(ptr!=NULL);

    close(fd);
}
예제 #2
0
static
void do_test(int num, int thread_num)
{
    flog_set_flush_interval(2);
    flog_set_level(FLOG_LEVEL_DEBUG);
    flog_set_buffer_size(MAX_BUFF_SIZE_PER_THREAD);
    if ( log_mode == FLOG_ASYNC_MODE ) {
        printf("current buffer size per-thread = %lu\n", flog_get_buffer_size());
    }
    flog_set_roll_size(FILE_ROLL_SIZE);
    flog_register_event_callback(get_log_event);
    init_counters();
    sleep(1);

    unsigned long long start_time = ftime_gettime();
    int end = num / thread_num;
    pthread_t tid[thread_num];
    int i = 0;
    for ( i = 0; i < thread_num; i++ ) {
        pthread_create(&tid[i], NULL, write_log, (void*)&end);
    }

    for ( i = 0; i < thread_num; i++ ) {
        pthread_join(tid[i], NULL);
    }

    unsigned long long end_time = ftime_gettime();
    unsigned long long diff_usec = end_time - start_time;
    printf("pid=%d, tid=%lu, call interface time cost (usec):%llu write_msg:%d miss_msg:%d miss_rate:%f final:%f count/s\n",
            getpid(), pthread_self(), diff_usec, num, buff_full_count, (double)buff_full_count/(double)num, (double)num/((double)diff_usec/1000000));
    printf("metrics:\n");
    printf("\terror_write_count: %d\n", error_write_count);
    printf("\terror_async_push_count: %d\n", error_async_push_count);
    printf("\terror_async_pop_count: %d\n", error_async_pop_count);
    printf("\tlog_truncated_count: %d\n", log_truncated_count);
    printf("\tbuffer_full_count: %d\n", buff_full_count);
}