예제 #1
0
//
// Note: Error checking not coded for brevity
//
int main(int argc, char **argv)
{
    web100_agent      *agent;
    web100_group      *group;
    web100_connection *conn;
    web100_snapshot   *snap;
    web100_log 	      *log;
    web100_var 	      *var = NULL;

    char buf[8];
    int ii;

    if(argc<2) {
	printf("Usage: logtest cid\n");
	exit(EXIT_FAILURE);
    }

    agent = web100_attach(WEB100_AGENT_TYPE_LOCAL, NULL);
    group = web100_group_find(agent, "read");
    conn  = web100_connection_lookup(agent, atoi(argv[1]));
    snap  = web100_snapshot_alloc(group, conn); 

    log = web100_log_open_write("logtest.txt", conn, group);

    for(ii=0;ii<3;ii++) {
	web100_snap(snap);
	web100_log_write(log, snap);
	printf("writing snapshot %d\n", ii);
	sleep(1);
    }

    web100_log_close_write(log);
    web100_snapshot_free(snap); 
    snap = NULL;
    log = NULL;
    //
    // Now post process; Normally a different run
    //
    log   = web100_log_open_read("logtest.txt");

    agent = web100_get_log_agent(log);
    group = web100_get_log_group(log);
    conn  = web100_get_log_connection(log);
    snap  = web100_snapshot_alloc(group, conn);

    var   = web100_var_find(group, "CurrTime");

    for(ii=0;ii<3;ii++) { 
       	web100_snap_from_log(snap, log); 
       	web100_snap_read(var, snap, &buf);
       	printf("CurrTime is: %s\n", web100_value_to_text(WEB100_TYPE_COUNTER32, &buf));
    }

    web100_log_close_read(log);

    return;
}
예제 #2
0
파일: testoptions.c 프로젝트: nkinkade/ndt
void*
snapWorker(void* arg) {
    /* WARNING void* arg (workerArgs) is on the stack of the function below and
     * doesn't exist forever. */
    WorkerArgs *workerArgs = (WorkerArgs*) arg;
    SnapArgs *snapArgs = workerArgs->snapArgs;
    tcp_stat_agent* agent = workerArgs->agent;
    CwndPeaks* peaks = workerArgs->peaks;
    int writeSnap = workerArgs->writeSnap;

    // snap log written into every "delay" milliseconds
    double delay = ((double) snapArgs->delay) / 1000.0;

    while (1) {
        pthread_mutex_lock(&mainmutex);
        if (workerLoop) {
            pthread_cond_broadcast(&maincond);
            pthread_mutex_unlock(&mainmutex);
            break;
        }
        pthread_mutex_unlock(&mainmutex);
        mysleep(0.01);
    }

    // Find Congestion window peaks from a web_100 snapshot, if enabled
    // Write snap log , if enabled, all in a synchronous manner.
    while (1) {
        pthread_mutex_lock(&mainmutex);
        if (!workerLoop) {
            pthread_mutex_unlock(&mainmutex);
            break;
        }
#if USE_WEB100
        web100_snap(snapArgs->snap);
        if (peaks) {
            findCwndPeaks(agent, peaks, snapArgs->snap);
        }
        if (writeSnap) {
            web100_log_write(snapArgs->log, snapArgs->snap);
        }
#elif USE_WEB10G
        estats_read_vars(snapArgs->snap, snapArgs->conn, agent);
        if (peaks) {
            findCwndPeaks(agent, peaks, snapArgs->snap);
        }
        if (writeSnap) {
            estats_record_write_data(snapArgs->log, snapArgs->snap);
        }
#endif
        pthread_mutex_unlock(&mainmutex);
        mysleep(delay);
    }

    return NULL;
}
예제 #3
0
파일: testoptions.c 프로젝트: nkinkade/ndt
/** Method to start snap worker thread that collects snap logs
 * @param snaparg object
 * @param tcp_stat_agent Agent
 * @param snaplogenabled Is snap logging enabled?
 * @param workerlooparg integer used to syncronize writing/reading from snaplog/tcp_stat snapshot
 * @param wrkrthreadidarg Thread Id of workera
 * @param metafilename	value of metafile name
 * @param tcp_stat_connection connection pointer
 * @param tcp_stat_group group web100_group pointer
 */
void start_snap_worker(SnapArgs *snaparg, tcp_stat_agent* agentarg,
                       CwndPeaks* peaks, char snaplogenabled,
                       pthread_t *wrkrthreadidarg, char *metafilename,
                       tcp_stat_connection conn, tcp_stat_group* group) {
    FILE *fplocal;

    WorkerArgs workerArgs;
    workerArgs.snapArgs = snaparg;
    workerArgs.agent = agentarg;
    workerArgs.peaks = peaks;
    workerArgs.writeSnap = snaplogenabled;

#if USE_WEB100
    group = web100_group_find(agentarg, "read");
    snaparg->snap = web100_snapshot_alloc(group, conn);
#elif USE_WEB10G
    snaparg->conn = conn;
    estats_val_data_new(&snaparg->snap);
#endif

    if (snaplogenabled) {
        // memcpy(metafilevariablename, metafilename, strlen(metafilename));
        // The above could have been here, except for a caveat: metafile stores
        // just the file name, but full filename is needed to open the log file

        fplocal = fopen(get_logfile(), "a");

#if USE_WEB100
        snaparg->log = web100_log_open_write(metafilename, conn, group);
#elif USE_WEB10G
        estats_record_open(&snaparg->log, metafilename, "w");
#endif
        if (fplocal == NULL) {
            log_println(
                0,
                "Unable to open log file '%s', continuing on without logging",
                get_logfile());
        } else {
            log_println(1, "Snaplog file: %s\n", metafilename);
            fprintf(fplocal, "Snaplog file: %s\n", metafilename);
            fclose(fplocal);
        }
    }

    if (pthread_create(wrkrthreadidarg, NULL, snapWorker,
                       (void*) &workerArgs)) {
        log_println(1, "Cannot create worker thread for writing snap log!");
        *wrkrthreadidarg = 0;
    }

    pthread_mutex_lock(&mainmutex);
    workerLoop= 1;
    // obtain web100 snap into "snaparg.snap"
#if USE_WEB100
    web100_snap(snaparg->snap);
    if (snaplogenabled) {
        web100_log_write(snaparg->log, snaparg->snap);
    }
#elif USE_WEB10G
    estats_read_vars(snaparg->snap, conn, agentarg);
    if (snaplogenabled) {
        estats_record_write_data(snaparg->log, snaparg->snap);
    }
#endif
    pthread_cond_wait(&maincond, &mainmutex);
    pthread_mutex_unlock(&mainmutex);
}