static void populate_swap(void) { sg_swap_stats *swap = sg_get_swap_stats(NULL); if (swap != NULL) { add_stat(BYTES, &swap->total, "swap", "total", NULL); add_stat(BYTES, &swap->used, "swap", "used", NULL); add_stat(BYTES, &swap->free, "swap", "free", NULL); } }
static void populate_load(void) { sg_load_stats *load = sg_get_load_stats(NULL); if (load != NULL) { add_stat(DOUBLE, &load->min1, "load", "min1", NULL); add_stat(DOUBLE, &load->min5, "load", "min5", NULL); add_stat(DOUBLE, &load->min15, "load", "min15", NULL); } }
static void populate_page(void) { sg_page_stats *page; page = use_diffs ? sg_get_page_stats_diff(NULL) : sg_get_page_stats(NULL); if (page != NULL) { add_stat(UNSIGNED_LONG_LONG, &page->pages_pagein, "page", "in", NULL); add_stat(UNSIGNED_LONG_LONG, &page->pages_pageout, "page", "out", NULL); add_stat(TIME_T, &page->systime, "page", "systime", NULL); } }
static void populate_mem(void) { sg_mem_stats *mem = sg_get_mem_stats(NULL); if (mem != NULL) { add_stat(BYTES, &mem->total, "mem", "total", NULL); add_stat(BYTES, &mem->free, "mem", "free", NULL); add_stat(BYTES, &mem->used, "mem", "used", NULL); add_stat(BYTES, &mem->cache, "mem", "cache", NULL); } }
void populate_proc() { /* FIXME expose individual process info too */ sg_process_count *proc = sg_get_process_count(); if (proc != NULL) { add_stat(INT, &proc->total, "proc", "total", NULL); add_stat(INT, &proc->running, "proc", "running", NULL); add_stat(INT, &proc->sleeping, "proc", "sleeping", NULL); add_stat(INT, &proc->stopped, "proc", "stopped", NULL); add_stat(INT, &proc->zombie, "proc", "zombie", NULL); } }
/* register a double statistical formula, the formula is evaluated when the statistic is printed, the formula expression may reference any registered statistical variable and, in addition, the standard operators '(', ')', '+', '-', '*', and '/', and literal (i.e., C-format decimal, hexidecimal, and octal) constants are also supported; NOTE: all terms are immediately converted to double values and the result is a double value, see eval.h for more information on formulas */ struct stat_stat_t * stat_reg_formula(struct stat_sdb_t *sdb,/* stat database */ int print_me, const char *name, /* stat variable name */ const char *desc, /* stat variable description */ const char *formula, /* formula expression */ const char *format) /* optional variable output format */ { struct stat_stat_t *stat; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = mystrdup(name); stat->desc = mystrdup(desc); stat->print_me = print_me; stat->format = format ? format : "%12.4f"; stat->sc = sc_formula; stat->variant.for_formula.formula = mystrdup(formula); /* link onto SDB chain */ add_stat(sdb, stat); return stat; }
/* register a string statistical variable */ struct stat_stat_t * stat_reg_string(struct stat_sdb_t *sdb, /* stat database */ const char *name, /* stat variable name */ const char *desc, /* stat variable description */ const char *var, /* stat variable */ const char *format) /* optional variable output format */ { struct stat_stat_t *stat; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = mystrdup(name); stat->desc = mystrdup(desc); stat->print_me = TRUE; stat->format = format ? format : "%12s"; stat->sc = sc_string; stat->variant.for_string.string = var; /* link onto SDB chain */ add_stat(sdb, stat); return stat; }
static void populate_const(void) { static int zero = 0; /* Constants, for use with MRTG mode. */ add_stat(INT, &zero, "const", "0", NULL); }
/* create a sparse array distribution in stat database SDB, while the sparse array consumes more memory per bucket than an array distribution, it can efficiently map any number of indicies from 0 to 2^32-1, PF specifies the distribution components to print for optional format FORMAT; the indicies may be optionally replaced with the strings from IMAP, or the entire distribution can be printed with the optional user-specified print function PRINT_FN */ struct stat_stat_t * stat_reg_sdist(struct stat_sdb_t *sdb, /* stat database */ char *name, /* stat variable name */ char *desc, /* stat variable description */ unsigned int init_val, /* dist initial value */ int pf, /* print format, use PF_* defs */ char *format, /* optional variable output format */ print_fn_t print_fn) /* optional user print function */ { struct stat_stat_t *stat; struct bucket_t **sarr; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = mystrdup(name); stat->desc = mystrdup(desc); stat->format = format ? format : NULL; stat->sc = sc_sdist; stat->variant.for_sdist.init_val = init_val; stat->variant.for_sdist.pf = pf; stat->variant.for_sdist.print_fn = print_fn; /* allocate hash table */ sarr = (struct bucket_t **)calloc(HTAB_SZ, sizeof(struct bucket_t *)); if (!sarr) fatal("out of virtual memory"); stat->variant.for_sdist.sarr = sarr; /* link onto SDB chain */ add_stat(sdb, stat); return stat; }
/* register a double statistical variable */ struct stat_stat_t * stat_reg_double(struct stat_sdb_t *sdb, /* stat database */ char *name, /* stat variable name */ char *desc, /* stat variable description */ double *var, /* stat variable */ double init_val, /* stat variable initial value */ char *format) /* optional variable output format */ { struct stat_stat_t *stat; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = mystrdup(name); stat->desc = mystrdup(desc); stat->format = format ? format : "%12.4f"; stat->sc = sc_double; stat->variant.for_double.var = var; stat->variant.for_double.init_val = init_val; /* link onto SDB chain */ add_stat(sdb, stat); /* initialize stat */ *var = init_val; return stat; }
void populate_fs() { int n, i; sg_fs_stats *disk = sg_get_fs_stats(&n); if (disk != NULL) { for (i = 0; i < n; i++) { /* FIXME it'd be nicer if libstatgrab did this */ char *buf, *name, *p; const char *device = disk[i].device_name; if (strcmp(device, "/") == 0) device = "root"; buf = strdup(device); if (buf == NULL) die("out of memory"); name = buf; if (strlen(name) == 2 && name[1] == ':') name[1] = '\0'; if (strncmp(name, "/dev/", 5) == 0) name += 5; while ((p = strchr(name, '/')) != NULL) *p = '_'; add_stat(STRING, &disk[i].device_name, "fs", name, "device_name", NULL); add_stat(STRING, &disk[i].fs_type, "fs", name, "fs_type", NULL); add_stat(STRING, &disk[i].mnt_point, "fs", name, "mnt_point", NULL); add_stat(BYTES, &disk[i].size, "fs", name, "size", NULL); add_stat(BYTES, &disk[i].used, "fs", name, "used", NULL); add_stat(BYTES, &disk[i].avail, "fs", name, "avail", NULL); add_stat(LONG_LONG, &disk[i].total_inodes, "fs", name, "total_inodes", NULL); add_stat(LONG_LONG, &disk[i].used_inodes, "fs", name, "used_inodes", NULL); add_stat(LONG_LONG, &disk[i].free_inodes, "fs", name, "free_inodes", NULL); free(buf); } } }
void populate_disk() { int n, i; sg_disk_io_stats *diskio; diskio = use_diffs ? sg_get_disk_io_stats_diff(&n) : sg_get_disk_io_stats(&n); if (diskio != NULL) { for (i = 0; i < n; i++) { const char *name = diskio[i].disk_name; add_stat(STRING, &diskio[i].disk_name, "disk", name, "disk_name", NULL); add_stat(BYTES, &diskio[i].read_bytes, "disk", name, "read_bytes", NULL); add_stat(BYTES, &diskio[i].write_bytes, "disk", name, "write_bytes", NULL); add_stat(TIME_T, &diskio[i].systime, "disk", name, "systime", NULL); } } }
unsigned int set_var(var_t *var, unsigned int id, unsigned long long mult, char *line) { static unsigned int lastid = 0; char buf0[strlen(line) + 1]; char buf1[strlen(line) + 1]; char buf2i[strlen(line) + 1]; char *buf2 = buf2i; unsigned int ret = 0; int n = 0; if (id <= lastid) return 0; lastid = id; sscanf(line, "%[^: ]:%n", buf0, &n); if (n < 1) return 0; line += n; ret += n; n = 0; if ((n = parse_quoted_string(line, buf1))) { ret += n; if (line[n] == ':') { n++; ret++; } else { n = 0; } } else { if (sscanf(line, "%[^: ]:%n", buf1, &n) < 1) return 0; ret += n; } if (n < 1) { buf2 = NULL; } else { line += n; n = 0; if (!(n = parse_quoted_string(line, buf2))) if (sscanf(line, "%s%n", buf2, &n) < 1) return 0; ret += n; } if (strcmp(buf0, "file") == 0) { add_file(mult, buf1); set_file_var(var, id, mult, buf1, buf2); } else if (strcmp(buf0, "date") == 0) { set_date_var(var, id, mult, buf1); } else { add_stat(mult, buf0); set_stat_var(var, id, mult, buf0, buf1, buf2); } return ret; }
static void populate_proc(void) { /* FIXME expose individual process info too */ sg_process_count *proc = sg_get_process_count(); if (proc != NULL) { add_stat(UNSIGNED_LONG_LONG, &proc->total, "proc", "total", NULL); add_stat(UNSIGNED_LONG_LONG, &proc->running, "proc", "running", NULL); add_stat(UNSIGNED_LONG_LONG, &proc->sleeping, "proc", "sleeping", NULL); add_stat(UNSIGNED_LONG_LONG, &proc->stopped, "proc", "stopped", NULL); add_stat(UNSIGNED_LONG_LONG, &proc->zombie, "proc", "zombie", NULL); } else { char *errbuf; sg_error_details errdet; if( SG_ERROR_NONE != sg_get_error_details(&errdet) ) return; if( NULL == sg_strperror( &errbuf, &errdet ) ) return; fprintf( stderr, "%s\n", errbuf ); } }
static void populate_general(void) { /* FIXME this should be renamed to host. */ sg_host_info *host = sg_get_host_info(NULL); if (host != NULL) { add_stat(STRING, &host->os_name, "general", "os_name", NULL); add_stat(STRING, &host->os_release, "general", "os_release", NULL); add_stat(STRING, &host->os_version, "general", "os_version", NULL); add_stat(STRING, &host->platform, "general", "platform", NULL); add_stat(STRING, &host->hostname, "general", "hostname", NULL); add_stat(UNSIGNED, &host->ncpus, "general", "ncpus", NULL); add_stat(UNSIGNED, &host->maxcpus, "general", "ncpus_cfg", NULL); add_stat(UNSIGNED, &host->bitwidth, "general", "bitwidth", NULL); add_stat(STRING, ((size_t)host->host_state) > (lengthof(host_states) - 1) ? &unexpected_host_state : &host_states[host->host_state], "general", "hoststate", NULL); add_stat(TIME_T, &host->uptime, "general", "uptime", NULL); } }
/* create an array distribution (w/ fixed size buckets) in stat database SDB, the array distribution has ARR_SZ buckets with BUCKET_SZ indicies in each bucked, PF specifies the distribution components to print for optional format FORMAT; the indicies may be optionally replaced with the strings from IMAP, or the entire distribution can be printed with the optional user-specified print function PRINT_FN */ struct stat_stat_t * stat_reg_dist(struct stat_sdb_t *sdb, /* stat database */ const char *name, /* stat variable name */ const char *desc, /* stat variable description */ unsigned int init_val, /* dist initial value */ unsigned int arr_sz, /* array size */ unsigned int bucket_sz, /* array bucket size */ int pf, /* print format, use PF_* defs */ const char *format, /* optional variable output format */ const char **imap, /* optional index -> string map */ print_fn_t print_fn) /* optional user print function */ { unsigned int i; struct stat_stat_t *stat; unsigned int *arr; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = mystrdup(name); stat->desc = mystrdup(desc); stat->print_me = TRUE; stat->format = format ? format : NULL; stat->sc = sc_dist; stat->variant.for_dist.init_val = init_val; stat->variant.for_dist.arr_sz = arr_sz; stat->variant.for_dist.bucket_sz = bucket_sz; stat->variant.for_dist.pf = pf; stat->variant.for_dist.imap = imap; stat->variant.for_dist.print_fn = print_fn; stat->variant.for_dist.overflows = 0; arr = (unsigned int *)calloc(arr_sz, sizeof(unsigned int)); if (!arr) fatal("out of virtual memory"); stat->variant.for_dist.arr = arr; /* link onto SDB chain */ add_stat(sdb, stat); /* initialize stat */ for (i=0; i < arr_sz; i++) arr[i] = init_val; return stat; }
void populate_general() { /* FIXME this should be renamed to host. */ sg_host_info *host = sg_get_host_info(); if (host != NULL) { add_stat(STRING, &host->os_name, "general", "os_name", NULL); add_stat(STRING, &host->os_release, "general", "os_release", NULL); add_stat(STRING, &host->os_version, "general", "os_version", NULL); add_stat(STRING, &host->platform, "general", "platform", NULL); add_stat(STRING, &host->hostname, "general", "hostname", NULL); add_stat(TIME_T, &host->uptime, "general", "uptime", NULL); } }
/* register an integer statistical variable */ struct stat_stat_t * stat_reg_note(struct stat_sdb_t *sdb, /* stat database */ const char *note) /* string to print */ { struct stat_stat_t *stat; stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t)); if (!stat) fatal("out of virtual memory"); stat->name = "--not a stat--"; stat->desc = "--not a stat--"; stat->print_me = TRUE; stat->format = "--not a stat--"; stat->sc = sc_note; stat->variant.for_note.note = mystrdup(note); /* link onto SDB chain */ add_stat(sdb, stat); return stat; }
static void populate_user(void) { static size_t entries; static char *name_list = NULL; size_t name_list_length = 0, pos = 0; sg_user_stats *users = sg_get_user_stats(&entries); if (users != NULL) { size_t i; for (i = 0; i < entries; i++) { const char *name = users[i].login_name; const char *tty = users[i].device; name_list_length += strlen(name) + 1; add_stat(STRING, &users[i].login_name, "user", tty, "login_name", NULL); add_stat(STRING, &users[i].device, "user", tty, "tty", NULL); add_stat(STRING, &users[i].hostname, "user", tty, "from", NULL); add_stat(TIME_T, &users[i].login_time, "user", tty, "login_time", NULL); } name_list = realloc(name_list, name_list_length + 1); for (i = 0; i < entries; i++) { const char *name = users[i].login_name; strncpy(name_list + pos, name, strlen(name)); pos += strlen(name); name_list[pos] = ' '; pos ++; } if (entries != 0) { pos--; } name_list[pos] = '\0'; add_stat(INT, &entries, "user", "num", NULL); add_stat(STRING, &name_list, "user", "names", NULL); } }
void build_metric_stats(struct tree_halo *prog, struct tree_halo *parent, struct tree_halo *desc) { int64_t bin; float dr, dv, dfric=0; float dvmax, v_ratio; if (!(prog->mvir > 0) || !(desc->mvir > 0) || !(prog->vmax > 0) || !(desc->vmax > 0)) return; //Unphysical halo bin = metric_bin(desc->mvir); if (bin < 0) return; dvmax = log10f(prog->vmax/desc->vmax); dr = sqrtf(calc_dr2(prog, desc)); dv = sqrtf(calc_dv2(prog, desc)); add_stat(&(sigma_x[bin]), dr); add_stat(&(sigma_v[bin]), dv); add_stat(&(sigma_vmax[bin]), dvmax); sigma_x[bin].corr += dr*dv; if (parent) { add_stat(&(sigma_x_subs[bin]), dr); add_stat(&(sigma_v_subs[bin]), dv); add_stat(&(sigma_vmax_subs[bin]), dvmax); dfric = calc_dyn_friction(prog, parent, desc); sigma_x_subs[bin].corr += dr*dv; sigma_v_subs[bin].corr += dfric; } if (metric_output) { v_ratio = desc->vrms / desc->vmax; fprintf(metric_output, "%"PRId64" %e %f %"PRId64" %e %f %e %e %e %f %.3f\n", prog->id, prog->mvir, prog->vmax, desc->id, desc->mvir, desc->vmax, dr, dv, dvmax, v_ratio, dfric); } }
void populate_net() { int num_io, num_iface, i; sg_network_io_stats *io; sg_network_iface_stats *iface; io = use_diffs ? sg_get_network_io_stats_diff(&num_io) : sg_get_network_io_stats(&num_io); if (io != NULL) { for (i = 0; i < num_io; i++) { const char *name = io[i].interface_name; add_stat(STRING, &io[i].interface_name, "net", name, "interface_name", NULL); add_stat(BYTES, &io[i].tx, "net", name, "tx", NULL); add_stat(BYTES, &io[i].rx, "net", name, "rx", NULL); add_stat(LONG_LONG, &io[i].ipackets, "net", name, "ipackets", NULL); add_stat(LONG_LONG, &io[i].opackets, "net", name, "opackets", NULL); add_stat(LONG_LONG, &io[i].ierrors, "net", name, "ierrors", NULL); add_stat(LONG_LONG, &io[i].oerrors, "net", name, "oerrors", NULL); add_stat(LONG_LONG, &io[i].collisions, "net", name, "collisions", NULL); add_stat(TIME_T, &io[i].systime, "net", name, "systime", NULL); } } iface = sg_get_network_iface_stats(&num_iface); if (iface != NULL) { for (i = 0; i < num_iface; i++) { const char *name = iface[i].interface_name; int had_io = 0, j; /* If there wasn't a corresponding io stat, add interface_name from here. */ if (io != NULL) { for (j = 0; j < num_io; j++) { if (strcmp(io[j].interface_name, name) == 0) { had_io = 1; break; } } } if (!had_io) { add_stat(STRING, &iface[i].interface_name, "net", name, "interface_name", NULL); } add_stat(INT, &iface[i].speed, "net", name, "speed", NULL); add_stat(BOOL, &iface[i].up, "net", name, "up", NULL); add_stat(DUPLEX, &iface[i].duplex, "net", name, "duplex", NULL); } } }
static void populate_cpu(void) { sg_cpu_stats *cpu_s; cpu_s = use_diffs ? sg_get_cpu_stats_diff(NULL) : sg_get_cpu_stats(NULL); if (use_cpu_percent) { sg_cpu_percent_source cps = use_diffs ? sg_last_diff_cpu_percent : sg_entire_cpu_percent; sg_cpu_percents *cpu_p = sg_get_cpu_percents_of(cps, NULL); if (cpu_p != NULL) { add_stat(DOUBLE, &cpu_p->user, "cpu", "user", NULL); add_stat(DOUBLE, &cpu_p->kernel, "cpu", "kernel", NULL); add_stat(DOUBLE, &cpu_p->idle, "cpu", "idle", NULL); add_stat(DOUBLE, &cpu_p->iowait, "cpu", "iowait", NULL); add_stat(DOUBLE, &cpu_p->swap, "cpu", "swap", NULL); add_stat(DOUBLE, &cpu_p->nice, "cpu", "nice", NULL); add_stat(TIME_T, &cpu_p->time_taken, "cpu", "time_taken", NULL); } } else { if (cpu_s != NULL) { add_stat(UNSIGNED_LONG_LONG, &cpu_s->user, "cpu", "user", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->kernel, "cpu", "kernel", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->idle, "cpu", "idle", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->iowait, "cpu", "iowait", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->swap, "cpu", "swap", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->nice, "cpu", "nice", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->total, "cpu", "total", NULL); add_stat(TIME_T, &cpu_s->systime, "cpu", "systime", NULL); } } if (cpu_s != NULL) { add_stat(UNSIGNED_LONG_LONG, &cpu_s->context_switches, "cpu", "ctxsw", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->voluntary_context_switches, "cpu", "vctxsw", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->involuntary_context_switches, "cpu", "nvctxsw", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->syscalls, "cpu", "syscalls", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->interrupts, "cpu", "intrs", NULL); add_stat(UNSIGNED_LONG_LONG, &cpu_s->soft_interrupts, "cpu", "softintrs", NULL); } }
void populate_cpu() { if (use_cpu_percent) { sg_cpu_percents *cpu_p = sg_get_cpu_percents(); if (cpu_p != NULL) { add_stat(FLOAT, &cpu_p->user, "cpu", "user", NULL); add_stat(FLOAT, &cpu_p->kernel, "cpu", "kernel", NULL); add_stat(FLOAT, &cpu_p->idle, "cpu", "idle", NULL); add_stat(FLOAT, &cpu_p->iowait, "cpu", "iowait", NULL); add_stat(FLOAT, &cpu_p->swap, "cpu", "swap", NULL); add_stat(FLOAT, &cpu_p->nice, "cpu", "nice", NULL); add_stat(TIME_T, &cpu_p->time_taken, "cpu", "time_taken", NULL); } } else { sg_cpu_stats *cpu_s; cpu_s = use_diffs ? sg_get_cpu_stats_diff() : sg_get_cpu_stats(); if (cpu_s != NULL) { add_stat(LONG_LONG, &cpu_s->user, "cpu", "user", NULL); add_stat(LONG_LONG, &cpu_s->kernel, "cpu", "kernel", NULL); add_stat(LONG_LONG, &cpu_s->idle, "cpu", "idle", NULL); add_stat(LONG_LONG, &cpu_s->iowait, "cpu", "iowait", NULL); add_stat(LONG_LONG, &cpu_s->swap, "cpu", "swap", NULL); add_stat(LONG_LONG, &cpu_s->nice, "cpu", "nice", NULL); add_stat(LONG_LONG, &cpu_s->total, "cpu", "total", NULL); add_stat(TIME_T, &cpu_s->systime, "cpu", "systime", NULL); } } }
void gmm_compute(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid) { kb_t *kb; kbcore_t *kbcore; mdef_t *mdef; dict_t *dict; dict2pid_t *d2p; mgau_model_t *mgau; subvq_t *svq; gs_t *gs; int32 ptranskip; int32 s, f, t; int32 single_el_list[2]; stats_t cur_ci_st; stats_t cur_cd_st; stats_t cur_cd_Nbest_st; stats_t *stptr; char str[100]; int32 *idx; int32 *cur_bstidx; int32 *last_bstidx; int32 *cur_scr; int32 *last_scr; int32 tmpint; s3senid_t *cd2cisen; int32 pheurtype; E_INFO("Processing: %s\n", uttid); kb = (kb_t *) data; kbcore = kb->kbcore; mdef = kbcore_mdef(kbcore); dict = kbcore_dict(kbcore); d2p = kbcore_dict2pid(kbcore); mgau = kbcore_mgau(kbcore); svq = kbcore_svq(kbcore); gs = kbcore_gs(kbcore); kb->uttid = uttid; ptranskip = kb->beam->ptranskip; pheurtype = kb->pl->pheurtype; single_el_list[0] = -1; single_el_list[1] = -1; /* Read mfc file and build feature vectors for entire utterance */ kb->stat->nfr = feat_s2mfc2feat(kbcore_fcb(kbcore), ur->uttfile, cmd_ln_str("-cepdir"), ".mfc", sf, ef, kb->feat, S3_MAX_FRAMES); cd2cisen = mdef_cd2cisen(mdef); /*This should be a procedure instead of just logic */ init_stat(&cur_cd_st, "Current CD Senone"); init_stat(&cur_ci_st, "Current CI Senone"); init_stat(&cur_cd_Nbest_st, "Current CD NBest Senone"); for (s = 0; s < mdef->n_ci_sen; s++) { sprintf(str, "Cur Senone %d", s); init_stat(&cur_sen_st[s], str); } for (t = 0; t < (int32) (mdef->n_sen - mdef->n_ci_sen) / NBEST_STEP; t++) { sprintf(str, " %d -Cur Best Senone", t * NBEST_STEP); init_stat(&cur_sen_Nbest_st[t], str); } idx = ckd_calloc(mdef->n_sen - mdef->n_ci_sen, sizeof(int32)); /* Allocate temporary array for CurScr and Curbst indx and Lat index */ cur_bstidx = ckd_calloc(mdef->n_sen, sizeof(int32)); last_bstidx = ckd_calloc(mdef->n_sen, sizeof(int32)); cur_scr = ckd_calloc(mdef->n_sen, sizeof(int32)); last_scr = ckd_calloc(mdef->n_sen, sizeof(int32)); for (f = 0; f < kb->stat->nfr; f++) { for (s = 0; s < mgau->n_mgau; s++) { /*1, Compute the approximate scores with the last best index. */ if (mgau->mgau[s].bstidx != NO_BSTIDX) { single_el_list[0] = mgau->mgau[s].bstidx; last_bstidx[s] = mgau->mgau[s].bstidx; last_scr[s] = mgau_eval(mgau, s, single_el_list, kb->feat[f][0], f, 0); } else { last_bstidx[s] = NO_BSTIDX; } /*2, Compute the exact scores and sort them and get the ranking. */ kb->ascr->senscr[s] = mgau_eval(mgau, s, NULL, kb->feat[f][0], f, 1); /*3, Compute the approximate scores with the current best index */ if (mgau->mgau[s].bstidx != NO_BSTIDX) { single_el_list[0] = mgau->mgau[s].bstidx; cur_bstidx[s] = mgau->mgau[s].bstidx; cur_scr[s] = mgau_eval(mgau, s, single_el_list, kb->feat[f][0], f, 0); } else { cur_bstidx[s] = NO_BSTIDX; } /* Only test for CD senones, test for best index hit */ /*Update either CI senone and CD senone) */ if (!mdef_is_cisenone(mdef, s)) stptr = &cur_cd_st; else stptr = &cur_ci_st; increment_stat(stptr, abs(last_scr[s] - kb->ascr->senscr[s]), abs(cur_scr[s] - kb->ascr->senscr[s]), abs(kb->ascr->senscr[cd2cisen[s]] - kb->ascr->senscr[s]), (cur_bstidx[s] == last_bstidx[s])); if (!mdef_is_cisenone(mdef, s)) { stptr = &cur_sen_st[cd2cisen[s]]; increment_stat(stptr, abs(last_scr[s] - kb->ascr->senscr[s]), abs(cur_scr[s] - kb->ascr->senscr[s]), abs(kb->ascr->senscr[cd2cisen[s]] - kb->ascr->senscr[s]), (cur_bstidx[s] == last_bstidx[s])); stptr->total_senone += 1; } } cur_cd_st.total_fr++; cur_cd_st.total_senone += mdef->n_sen - mdef->n_ci_sen; cur_ci_st.total_fr++; cur_ci_st.total_senone += mdef->n_ci_sen; for (s = 0; s < mdef->n_ci_sen; s++) { cur_sen_st[s].total_fr++; } /*This is the part we need to do sorting */ /*1, sort the scores in the current frames */ /*E_INFO("At frame %d\n",f); */ /*Pointer trick at here. */ for (s = 0; s < mdef->n_sen - mdef->n_ci_sen; s++) { idx[s] = s; } cd = &(kb->ascr->senscr[mdef->n_ci_sen]); qsort(idx, mdef->n_sen - mdef->n_ci_sen, sizeof(int32), intcmp_gmm_compute); /*This loop is stupid and it is just a hack. */ for (s = 0; s < mdef->n_sen - mdef->n_ci_sen; s++) { tmpint = idx[s] + mdef->n_ci_sen; for (t = 0; t < (int32) ((float) (mdef->n_sen - mdef->n_ci_sen) / (float) NBEST_STEP); t++) { if (s < t * NBEST_STEP) { increment_stat(&cur_sen_Nbest_st[t], abs(last_scr[tmpint] - kb->ascr->senscr[tmpint]), abs(cur_scr[tmpint] - kb->ascr->senscr[tmpint]), abs(kb->ascr->senscr[cd2cisen[tmpint]] - kb->ascr->senscr[tmpint]), (cur_bstidx[tmpint] == last_bstidx[tmpint])); cur_sen_Nbest_st[t].total_senone += 1; } } } for (t = 0; t < (int32) ((float) (mdef->n_sen - mdef->n_ci_sen) / (float) NBEST_STEP); t++) { cur_sen_Nbest_st[t].total_fr++; } } print_stat(&cur_cd_st); print_stat(&cur_ci_st); print_stat(&cur_sen_Nbest_st[1]); /*Only show the first NBEST_STEP best */ add_stat(&cd_st, &cur_cd_st); add_stat(&ci_st, &cur_ci_st); for (s = 0; s < mdef->n_ci_sen; s++) { add_stat(&sen_st[s], &cur_sen_st[s]); } for (s = 0; s < (int32) (mdef->n_sen - mdef->n_ci_sen) / NBEST_STEP; s++) { add_stat(&sen_Nbest_st[s], &cur_sen_Nbest_st[s]); } ckd_free(idx); ckd_free(cur_bstidx); ckd_free(last_bstidx); ckd_free(cur_scr); ckd_free(last_scr); }