コード例 #1
0
ファイル: nc_stats.c プロジェクト: YongMan/r3proxy
void
stats_aggregate_force(struct stats *st)
{
    pthread_mutex_lock(&st->stats_mutex);
    st->aggregate = 1;
    stats_aggregate(st);

    st->updated = 1;
    stats_swap(st);
    stats_aggregate(st);

    stats_pool_reset(&st->shadow);
    stats_pool_reset(&st->current);
    pthread_mutex_unlock(&st->stats_mutex);
}
コード例 #2
0
ファイル: nc_stats.c プロジェクト: danchaofan/bilitw
void
stats_swap(struct stats *st)
{
    if (!stats_enabled) {
        return;
    }

    if (st->aggregate == 1) {
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as aggregator "
                  "is busy", st->current.elem, st->shadow.elem);
        return;
    }

    if (st->updated == 0) {
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as there is "
                  "nothing new", st->current.elem, st->shadow.elem);
        return;
    }

    log_debug(LOG_PVERB, "swap stats current %p shadow %p", st->current.elem,
              st->shadow.elem);

    array_swap(&st->current, &st->shadow);

    /*
     * Reset current (a) stats before giving it back to generator to keep
     * stats addition idempotent
     */
    stats_pool_reset(&st->current);
    st->updated = 0;

    st->aggregate = 1;
}
コード例 #3
0
//把current数据拷贝到shadow,然后在stats_aggregate进行合并
//只要有读写事件则更新统计信息,然后拷贝到shadow,最终在stats_aggregate进行合并
void
stats_swap(struct stats *st)
{
    if (!stats_enabled) {
        return;
    }

    if (st->aggregate == 1) { /* 客户端 */
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as aggregator "
                  "is busy", st->current.elem, st->shadow.elem);
        return;
    }

    if (st->updated == 0) {/* 在客户端通过22222两次获取统计信息这段时间内必须要有相关参数的更新,这里才会置1 */
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as there is "
                  "nothing new", st->current.elem, st->shadow.elem);
        return;
    }

    log_debug(LOG_PVERB, "swap stats current %p shadow %p", st->current.elem,
              st->shadow.elem);

    array_swap(&st->current, &st->shadow); 
    //把current数据拷贝到shadow,然后在stats_aggregate进行合并
    
    /*
     * Reset current (a) stats before giving it back to generator to keep
     * stats addition idempotent
     */
    stats_pool_reset(&st->current);
    st->updated = 0;

    st->aggregate = 1;
}