Example #1
0
void print_statistics(void * ps_tree)
{
    /* Statistics data */
    unsigned int num_files = 0, max_file_len = 0, total_file_len = 0;
    unsigned int total_revisions = 0, max_revisions_for_file = 0;
    unsigned int total_branches = 0, max_branches_for_file = 0;
    unsigned int total_branches_sym = 0, max_branches_sym_for_file = 0;

    /* Other vars */
    struct hash_entry *he;
   
    printf("Statistics:\n");
    fflush(stdout);

    /* Gather file statistics */
    reset_hash_iterator(file_hash);
    while ((he=next_hash_entry(file_hash)))
    {
	int len = strlen(he->he_key);
	CvsFile *file = (CvsFile *)he->he_obj;
	
	num_files++;
	max_file_len = MAX(max_file_len, len);
	total_file_len += len;

	count_hash(file->revisions, &total_revisions, &max_revisions_for_file);
	count_hash(file->branches, &total_branches, &max_branches_for_file);
	count_hash(file->branches_sym, &total_branches_sym,
	    &max_branches_sym_for_file);
    }

    /* Print file statistics */
    printf("Num files: %d\nMax filename len: %d, Average filename len: %.2f\n",
	    num_files, max_file_len, (float)total_file_len/num_files);

    printf("Max revisions for file: %d, Average revisions for file: %.2f\n",
	  max_revisions_for_file, (float)total_revisions/num_files);
    printf("Max branches for file: %d, Average branches for file: %.2f\n",
	  max_branches_for_file, (float)total_branches/num_files);
    printf("Max branches_sym for file: %d, Average branches_sym for file: %.2f\n",
	  max_branches_sym_for_file, (float)total_branches_sym/num_files);

    /* Gather patchset statistics */
    twalk(ps_tree, stat_ps_tree_node);

    /* Print patchset statistics */
    printf("Num patchsets: %d\n", num_patch_sets);
    printf("Max PS members in PS: %d\nAverage PS members in PS: %.2f\n",
	    max_ps_member_in_ps, (float)num_ps_member/num_patch_sets);
    printf("Num authors: %d, Max author len: %d, Avg. author len: %.2f\n", 
	    num_authors, max_author_len, (float)total_author_len/num_authors);
    printf("Max desc len: %d, Avg. desc len: %.2f\n",
	    max_descr_len, (float)total_descr_len/num_patch_sets);
}
Example #2
0
static void
count_hash(struct nhash *h, int *n) {
  if (h == NULL)
    return;

  if (h->l)
    count_hash(h->l, n);

  if (h->r)
    count_hash(h->r, n);

  (*n)++;
}
Example #3
0
int
nhash_num(NHASH hash)
{
  int i, n = 0;
  for (i = 0; i < HASH_SIZE; i++) {
    if (hash[i]) {
      count_hash(hash[i], &n);
    }
  }
  return n;
}
Example #4
0
void *ws_hash_get(WsHashPtr hash, const char *name)
{
    WsHashItem *i;
    size_t h = count_hash(name);

    for (i = hash->items[h]; i; i = i->next)
        if (strcmp(i->name, name) == 0)
            return i->data;

    return NULL;
}
Example #5
0
WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data)
{
    WsHashItem *i;
    size_t h = count_hash(name);

    for (i = hash->items[h]; i; i = i->next) {
        if (strcmp(i->name, name) == 0) {
            /* Found it. */

            /* Destroy the old item */
            if (hash->destructor)
                (*hash->destructor)(i->data, hash->destructor_context);

            i->data = data;

            return WS_FALSE;
        }
    }

    /* Must create a new mapping. */
    i = ws_calloc(1, sizeof(*i));

    if (i == NULL)
        return WS_FALSE;

    i->name = ws_strdup(name);
    if (i->name == NULL) {
        ws_free(i);
        return WS_FALSE;
    }

    i->data = data;

    /* Link it to our hash. */
    i->next = hash->items[h];
    hash->items[h] = i;

    return WS_TRUE;
}
Example #6
0
/* 处理所有服务器策略的配置 */
AP_DECLARE(int) ap_server_policy_walk(apr_hash_t *sp_hash)
{
    int total;
    server_policy_t *sp;
    apr_hash_index_t *hi;
    apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
    apr_time_t start_time;
    apr_time_t stop_time;

    if (!sp_hash) {
        return DECLINED;
    }

    start_time = apr_time_now();

    /* 配置处理过程中的临时数据放在临时内存池里面 */
    apr_pool_create(&ptemp, pconf);
    apr_pool_tag(ptemp, "ptemp");

    total = count_hash(sp_hash);
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_main_server,
                 "server policy hash size: %d", total);

    /* 只部署符合当前运行模式的服务器策略 */
    total = 0;
    for (hi = apr_hash_first(NULL, sp_hash); hi; hi = apr_hash_next(hi)) {
        apr_hash_this(hi, NULL, NULL, (void *)&sp);
        if (!sp && (sp->work_mode != ap_work_mode)) {
            continue;
        }

        if (sp->is_default && (sp->work_mode == WORK_REVERSE)) {
            continue;
        }

        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_main_server,
                     "server policy (%d): %s", total + 1, sp->name);

        /* 重新构建虚拟主机 */
        if (rebuild_vhost(sp, ptemp)) {
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                         "deploy server policy %s error", sp->name);
            continue;
        }

        sp->server->next = ap_main_server->next;
        ap_main_server->next = sp->server;
        total++;
    }

    apr_pool_destroy(ptemp);

    stop_time = apr_time_now();
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_main_server,
                 "cost (%lld) micro-seconds to walk server policy", (long long)(stop_time - start_time));

    if (!total) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_main_server,
                     "there is no available server policy");
        return DONE;
    }

    return OK;
}