struct stats * stats_create(uint16_t stats_port, char *stats_ip, int stats_interval, char *source, struct array *server_pool, struct context *ctx) { rstatus_t status; struct stats *st; st = dn_alloc(sizeof(*st)); if (st == NULL) { return NULL; } st->port = stats_port; st->interval = stats_interval; string_set_raw(&st->addr, stats_ip); st->start_ts = (int64_t)time(NULL); st->buf.len = 0; st->buf.data = NULL; st->buf.size = 0; array_null(&st->current); array_null(&st->shadow); array_null(&st->sum); st->tid = (pthread_t) -1; st->sd = -1; string_set_text(&st->service_str, "service"); string_set_text(&st->service, "dynomite"); string_set_text(&st->source_str, "source"); string_set_raw(&st->source, source); string_set_text(&st->version_str, "version"); string_set_text(&st->version, DN_VERSION_STRING); string_set_text(&st->uptime_str, "uptime"); string_set_text(&st->timestamp_str, "timestamp"); //for latency histo string_set_text(&st->latency_999th_str, "latency_999th"); string_set_text(&st->latency_99th_str, "latency_99th"); string_set_text(&st->latency_95th_str, "latency_95th"); string_set_text(&st->latency_mean_str, "latency_mean"); string_set_text(&st->latency_max_str, "latency_max"); //for payload size histo string_set_text(&st->payload_size_999th_str, "payload_size_999th"); string_set_text(&st->payload_size_99th_str, "payload_size_99th"); string_set_text(&st->payload_size_95th_str, "payload_size_95th"); string_set_text(&st->payload_size_mean_str, "payload_size_mean"); string_set_text(&st->payload_size_max_str, "payload_size_max"); string_set_text(&st->alloc_msgs_str, "alloc_msgs"); //only display the first pool struct server_pool *sp = (struct server_pool*) array_get(server_pool, 0); string_set_text(&st->rack_str, "rack"); string_copy(&st->rack, sp->rack.data, sp->rack.len); string_set_text(&st->dc_str, "dc"); string_copy(&st->dc, sp->dc.data, sp->dc.len); st->updated = 0; st->aggregate = 0; histo_init(&st->latency_histo); histo_init(&st->payload_size_histo); st->alloc_msgs = 0; /* map server pool to current (a), shadow (b) and sum (c) */ status = stats_pool_map(&st->current, server_pool); if (status != DN_OK) { goto error; } status = stats_pool_map(&st->shadow, server_pool); if (status != DN_OK) { goto error; } status = stats_pool_map(&st->sum, server_pool); if (status != DN_OK) { goto error; } status = stats_create_buf(st); if (status != DN_OK) { goto error; } status = stats_start_aggregator(st); if (status != DN_OK) { goto error; } st->ctx = ctx; return st; error: stats_destroy(st); return NULL; }
int main(int argc, char *argv[]) { module_t *module; void *result; // future : use for rmf,dumb,histo : // it is an array of everything int type; // float,int,double... for result[] int size_result; int steg = 0; int plot = 0; int size, feature; char filename[MAXLEN_FILENAME]; char svmfilename[MAXLEN_FILENAME]; int outfile; char algoname[MAXLEN_ALGONAME]; filename[0] = 0; svmfilename[0] = 0; int opt; int option_index = 0; FILE *svmfile = NULL; // set default module option strcpy(algoname,"dumb"); for(;;) { opt = getopt_long (argc, argv, "012345", long_options, &option_index); if(opt==-1) break; switch (opt) { case 0: // --module=modulename //printf ("option %s", long_options[option_index].name); if (optarg) { if(strlen(optarg)<MAXLEN_ALGONAME) { strcpy(algoname,optarg); } } else { printf("Error : module name too long\n"); exit(0); } break; case 1: // --file=filename if (optarg) { if(strlen(optarg)<MAXLEN_FILENAME) { strcpy(filename,optarg); } else { printf("Error : filename too long\n"); exit(0); } } break; case 2: // --svm=filename if (optarg) { if(strlen(optarg)<MAXLEN_FILENAME) { strcpy(svmfilename,optarg); } else { printf("Error : svm filename too long\n"); exit(0); } } break; case 3: // --steg steg = 1; //if (optarg) { //steg = atoi(optarg); //} break; case 4: // --plot plot = 1; break; case 5: // --help printhelp(argv[0]); break; } } if(filename[0]==0) { printf("please give a file name.\n"); printhelp(argv[0]); exit(1); } // extract DCT's size = extract_dct(filename); //printf("*** Number of DCTs: %d ***\n", size); /*********************** dumb **************************/ if(!strcmp(algoname,"dumb")) { dumb_hello_module(); // initializes module dumb_init(); // compute sum (dumb feature) for each DCT int x,y,z; dumb_reset(size); for (z=0; z<size; z++) { dumb_compute(dct[z]); } // get features (average of sum in this case) feature = dumb_get_features(); printf("Average of sum of DCTs = %d\n", feature); // free allocations dumb_release(); } /*********************** histo **************************/ if(!strcmp(algoname,"histo")) { int *tab; // used for result printf("applying "); histo_hello_module(); // initializes module histo_init(); // compute histogram for each DCT int x,y,z; histo_reset(size); for (z=0; z<size; z++) { histo_compute(dct[z]); } // get features (histogram) size_result = histo_get_count(); int *numbers; numbers = malloc(size_result*sizeof(int)); result = (void *) malloc(size_result*sizeof(int)); tab = (int *) result; histo_get_features(numbers, tab, plot); // free allocations histo_release(); } /*********************** rmf **************************/ else if(!strcmp(algoname,"rmf")) { int i; param_t param; float *tab; // used for rmf = result printf("applying "); rmf_hello_module(); param.nb_dct = size; // initializes module rmf_init(); int x,y,z; module = rmf_get_module(); result = (void *) malloc(sizeof(float) * module->features); tab = (float *) result; rmf_reset(¶m); for (z=0; z<size; z++) { //printf("%d ",z);fflush(stdout); rmf_compute((int *) dct[z]); if(z % (size/100) == 1) { printf("%d%% ", (1 + z *100 / size));fflush(stdout); } } printf("\n"); rmf_get_features(tab); size_result = module->features; // free allocations rmf_release(); } /*********************** SVM **************************/ if(svmfilename[0]!=0) { int i; svmfile = fopen(svmfilename,"a"); if(svmfile != NULL) { fprintf(svmfile, "%f ",(float) steg); if(!strcmp(algoname,"histo")) { int *tab = result; for(i=0;i<size_result;i++) { fprintf(svmfile, "%d:%d ",i+1, tab[i]); } free(result); } if(!strcmp(algoname,"rmf")) { float *tab = result; for(i=0;i<size_result;i++) { fprintf(svmfile, "%d:%f ",i+1, tab[i]); } free(result); } fprintf(svmfile, "\n"); fclose(svmfile); } else { printf("Cannot open file %s \n", svmfilename); } } return 0; }