Exemple #1
0
int main (int argc, char **argv) {
    int norun;
    char *rulesfile, *statefile;
    int newflag, checkflag;

    Sfio_t *ifp, *ofp;
    int osm;
    DDSschema_t *schemap;
    DDSheader_t hdr;
    int ret;

    VG_alarm_t adata;
    ruleev_t *ruleevp;
    cc_t *ccp;
    nd_t *ndp;
    ev_t *evp;
    sl_inv_nd2cc_t *nd2ccp;
    char *currdate, *s;
    int maxalarmkeepmin;

    schemap = NULL;
    osm = DDS_HDR_NAME | DDS_HDR_DESC;
    rulesfile = NULL;
    statefile = NULL;
    currdate = NULL;
    newflag = FALSE;
    checkflag = FALSE;
    norun = 0;
    for (;;) {
        switch (optget (argv, usage)) {
        case -100:
            rulesfile = opt_info.arg;
            continue;
        case -101:
            statefile = opt_info.arg;
            continue;
        case -102:
            currdate = opt_info.arg;
            continue;
        case -200:
            newflag = TRUE;
            continue;
        case -201:
            checkflag = TRUE;
            continue;
        case -999:
            SUwarnlevel++;
            continue;
        case '?':
            SUusage (0, "vggce", opt_info.arg);
            norun = 1;
            continue;
        case ':':
            SUusage (1, "vggce", opt_info.arg);
            norun = 2;
            continue;
        }
        break;
    }
    if (norun)
        return norun - 1;
    argc -= opt_info.index, argv += opt_info.index;

    ifp = ofp = NULL;
    if (!rulesfile || !statefile || !currdate || strlen (currdate) != 10) {
        SUwarning (0, "vggce", "missing arguments");
        goto failsafe1;
    }

    DDSinit ();
    if (!(ifp = SUsetupinput (sfstdin, 1048576))) {
        SUwarning (0, "vggce", "setupinput failed");
        goto failsafe1;
    }
    if (!(ofp = SUsetupoutput (NULL, sfstdout, 1048576))) {
        SUwarning (0, "vggce", "setupoutput failed");
        goto failsafe1;
    }
    if ((ret = DDSreadheader (ifp, &hdr)) == -1) {
        SUwarning (0, "vggce", "DDSreadheader failed");
        goto failsafe1;
    }
    if (ret == -2)
        goto done;
    if (ret == 0) {
        if (hdr.schemap)
            schemap = hdr.schemap;
    }
    if (!schemap) {
        SUwarning (0, "vggce", "DDSloadschema failed");
        goto failsafe1;
    }
    if (!hdr.schemap && schemap)
        hdr.schemap = schemap;
    hdr.contents = osm;
    hdr.vczspec = "";
    if (osm && DDSwriteheader (ofp, &hdr) == -1) {
        SUwarning (0, "vggce", "DDSwriteheader failed");
        goto failsafe1;
    }

    s = getenv ("DEFAULTTMODE");
    if (!(ftmode = vmstrdup (Vmheap, s ? s : VG_ALARM_S_MODE_KEEP))) {
        SUwarning (0, "vggce", "cannot copy tmode");
        goto failsafe1;
    }
    if ((rtmode = strchr (ftmode, ':')))
        *rtmode++ = 0;
    else
        rtmode = ftmode;

    currtime = 0;
    maxalarmkeepmin = atoi (getenv ("MAXALARMKEEPMIN"));
    sl_inv_nd2ccopen (getenv ("INVND2CCFILE"));

    if (sevmapload (getenv ("SEVMAPFILE")) == -1) {
        SUwarning (0, "vggce", "cannot load sevmap file");
        goto failsafe1;
    }
    if (initgraph () == -1) {
        SUwarning (0, "vggce", "initgraph failed");
        goto failsafe1;
    }
    if (initcorr () == -1) {
        SUwarning (0, "vggce", "initcorr failed");
        goto failsafe1;
    }
    if (loadrules (rulesfile) == -1) {
        SUwarning (0, "vggce", "loadrules failed");
        goto failsafe1;
    }
    if (checkflag)
        goto done;
    if (!newflag && loadevstate (statefile) == -1) {
        SUwarning (0, "vggce", "loadstate failed");
        goto failsafe1;
    }

    ccmark++;
    evmark++;

    while ((
        ret = DDSreadrecord (ifp, &adata, schemap)
    ) == sizeof (VG_alarm_t)) {
        VG_warning (0, "GCE INFO", "read alarm %s", adata.s_text);

        if (
            !DATEMATCH (currdate, adata.s_dateissued) ||
            adata.s_sortorder != VG_ALARM_N_SO_NORMAL ||
            adata.s_pmode != VG_ALARM_N_PMODE_PROCESS
        )
            goto write;

        if (currtime < adata.s_timeissued)
            currtime = adata.s_timeissued;

        if (!(ruleevp = matchruleev (&adata)))
            goto write;

        if (!(nd2ccp = sl_inv_nd2ccfind (adata.s_level1, adata.s_id1)))
            goto write;

        if (!(ccp = insertcc (nd2ccp->sl_cclevel, nd2ccp->sl_ccid, TRUE))) {
            SUwarning (0, "vggce", "cannot insert cc %s", nd2ccp->sl_ccid);
            goto failsafe1;
        }
        if (ccp->svcpm < 1)
            goto write;

        if (!(ndp = findnd (adata.s_level1, adata.s_id1))) {
            SUwarning (0, "vggce", "cannot find nd %s", adata.s_id1);
            goto failsafe1;
        }

        if (!(evp = insertev (
            adata.s_timeissued, adata.s_type, ccp, ndp, ruleevp
        ))) {
            SUwarning (0, "vggce", "cannot insert ev");
            goto failsafe1;
        }
        if (evp->svcpm < 1)
            goto write;

        if (insertndevent (ndp, evp) == -1) {
            SUwarning (0, "vggce", "cannot insert ev in nd");
            goto failsafe1;
        }

write:
        if (DDSwriterecord (ofp, &adata, schemap) != sizeof (VG_alarm_t)) {
            SUwarning (0, "vggce", "cannot write alarm");
            goto failsafe1;
        }
        VG_warning (0, "GCE INFO", "wrote alarm");
    }

    ndmark++;

    if (pruneevs (currtime - 60 * maxalarmkeepmin, 1) == -1) {
        SUwarning (0, "vggce", "cannot prune evs (1)");
        goto failsafe1;
    }

    calcsvcvalues (SVC_MODE_NOEV, -1, -1);
    calcsvcvalues (SVC_MODE_OLDEV, 0, 0);
    calcsvcvalues (SVC_MODE_NEWEV, 0, 1);

    if (updatealarms (SVC_MODE_OLDEV, SVC_MODE_NEWEV, 1) == -1) {
        SUwarning (0, "vggce", "cannot update alarms (1)");
        goto failsafe1;
    }

    evmark++;
//    ccmark++;

    if (pruneevs (currtime - 60 * maxalarmkeepmin, 2) == -1) {
        SUwarning (0, "vggce", "cannot prune evs");
        goto failsafe1;
    }

    calcsvcvalues (SVC_MODE_PRUNE, 2, 2);

    if (updatealarms (SVC_MODE_NEWEV, SVC_MODE_PRUNE, 2) == -1) {
        SUwarning (0, "vggce", "cannot update alarms (2)");
        goto failsafe1;
    }

    if (saveevstate (statefile) == -1) {
        SUwarning (0, "vggce", "savestate failed");
        goto failsafe1;
    }

    VG_warning (0, "GCE INFO", "events=%d", evpm);

    if (ret != 0)
        SUerror ("vggce", "failed to read full record");

done:
    DDSterm ();
    return 0;

failsafe1:
    SUwarning (0, "vggce", "IN FAILSAFE MODE");
    if (sfmove (ifp, ofp, -1, -1) == -1)
        SUwarning (0, "vggce", "cannot copy data");
    return 101;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    printf("node size %d\n", sizeof(struct node));
    parseargs(argc, argv);
    rule_set_cnt = loadrules(fpr);
    printf("load rules %d\n", rule_set_cnt);

    //struct node * root1, *root2;
    //struct table_entry *root3;
    DEFINE_ROOT1;
    DEFINE_ROOT2;
    DEFINE_ROOT3;

    struct tree_info info;

    //root1 = load_tree(ifp1, &info);
    //root2 = load_tree(ifp2, &info);
    //root3 = load_hs(ifp3);
    LOAD_TREE1; 
    LOAD_TREE2;
    LOAD_TREE3;

#if 0 
    uint32_t r1,r2,r3;
    int ret;
    int ret2;
    int trace_no = 0;
    int flag = 0;
    uint32_t ft[MAXDIMENSIONS];
    while((trace_no = load_ft(fpt, ft)) != 0) {
         //if(trace_no == 30)
         //   printf("here\n");
        //r1 = (uint32_t)search_rules(root1, ft);
        r1 = (uint32_t)lookup_table(root1, ft);
        //r2 = (uint32_t)search_rules(root2, ft);
        r2 = (uint32_t)lookup_table(root2, ft);
        r3 = (uint32_t)lookup_table(root3, ft);
        //r1 = SEARCH_TREE1;
        //r2 = SEARCH_TREE2;
        //r3 = SEARCH_TREE3;

        ret = MIN(r1, MIN(r3,r2));
        ret2 = g_linear_search(ft);
        if(ret != ret2) {
            printf("ret %d, ret2 %d\n",ret, ret2);
            printf("trace no: %d\n", trace_no);
        }
        if(!flag) 
            flag = 1;
    }

    if(flag == 1) {
        printf("matching finished\n");
    }
#endif
#if 1 
    uint32_t *ft = (uint32_t *)malloc(1000000 * MAXDIMENSIONS * sizeof(uint32_t));
    int i = 0;
    int trace_cnt = 0;

    while(load_ft(fpt, ft+i*MAXDIMENSIONS) && i < 1000000){
        i++;
    }
    trace_cnt = i;
    long total_time = 0;
    printf("loading %d entries\n", trace_cnt);


    struct timespec tp_a, tp_b;
    int ret;
    uint32_t r1,r2,r3;
    clock_gettime(CLOCK_MONOTONIC, &tp_b);
    for(i=i-1;i>=0;i--) {
        r1 = SEARCH_TREE1;
        r2 = SEARCH_TREE2;
        r3 = SEARCH_TREE3;
        //r1 = (uint32_t)search_rules(root1, ft);
        //r2 = (uint32_t)search_rules(root2, ft);
        //r3 = (uint32_t)lookup_table(root3, ft);
        ret = MIN(r1, MIN(r3,r2));
#ifdef STAT
        if(acc > max_acc)
            max_acc = acc;
        sum_acc+=acc;
        acc=0;
#endif
    }
    clock_gettime(CLOCK_MONOTONIC, &tp_a);

    printf("%lu %lu\n", tp_a.tv_sec, tp_a.tv_nsec);
    printf("%lu %lu\n", tp_b.tv_sec, tp_b.tv_nsec);
    total_time = ((long)tp_a.tv_sec - (long)tp_b.tv_sec) * 1000000000ULL + 
            (tp_a.tv_nsec - tp_b.tv_nsec);
#ifdef STAT
    printf("mem %lu %.2fKB %.2fMB\n", total_size, (double)total_size/1024, (double)total_size/(1024*1024));
    printf("max_acc %u avg_acc %.2f\n", max_acc, (double)sum_acc/trace_cnt);
#endif

    printf("time: %ld\n", total_time); 
    double ave_time = (double)total_time / trace_cnt;
    printf("ave time: %.1fns\n", ave_time);
    double gbps = (1/ave_time) * 1e9 / 1.48e6;
    printf("gbps: %.1fGbps\n", gbps);  

#endif
    
    return 0;

}