uint16_t packet_received(uint8_t packet[], uint16_t length, uint16_t src_addr, int16_t rssi) { if (packet[0] == DATA) { if (type == SINK) { stat_add(STAT_APP_RX); printf("[APP];SINK_RX;%c%c%c%c;%.4x;%u;%u\n", packet[2], packet[3], packet[4], packet[5],src_addr, packet[6],packet[7]); return 0; } else { routing_txframe[0] = DATA; routing_txframe[1] = level-1; //node level routing_txframe[2] = packet[2]; //node id routing_txframe[3] = packet[3]; routing_txframe[4] = packet[4]; routing_txframe[5] = packet[5]; routing_txframe[6] = packet[6]; // num sequence routing_txframe[7] = packet[7] + 1; // nb hops txlength = 8; printf("[ROUTING];NODE_FORWARD;%.4x;%c%c%c%c;%u;%u;%u-%u\n", nodeaddr, routing_txframe[2], routing_txframe[3], routing_txframe[4], routing_txframe[5], routing_txframe[6],routing_txframe[7],global_clock, timerB_time()/32); stat_add(STAT_FORWARD_CNT); mac_send(routing_txframe, txlength, parent_id); } } return 0; }
bool admin_database_stats(PgSocket *client, struct StatList *pool_list) { PgPool *pool; struct List *item; PgDatabase *cur_db = NULL; PgStats st_total, st_db, old_db, old_total; int rows = 0; PktBuf *buf; reset_stats(&st_total); reset_stats(&st_db); reset_stats(&old_db); reset_stats(&old_total); buf = pktbuf_dynamic(512); if (!buf) { admin_error(client, "no mem"); return true; } pktbuf_write_RowDescription(buf, "sqqqqqqqqqqqqqq", "database", "total_xact_count", "total_query_count", "total_received", "total_sent", "total_xact_time", "total_query_time", "total_wait_time", "avg_xact_count", "avg_query_count", "avg_recv", "avg_sent", "avg_xact_time", "avg_query_time", "avg_wait_time"); statlist_for_each(item, pool_list) { pool = container_of(item, PgPool, head); if (!cur_db) cur_db = pool->db; if (pool->db != cur_db) { write_stats(buf, &st_db, &old_db, cur_db->name); rows ++; cur_db = pool->db; stat_add(&st_total, &st_db); stat_add(&old_total, &old_db); reset_stats(&st_db); reset_stats(&old_db); } stat_add(&st_db, &pool->stats); stat_add(&old_db, &pool->older_stats); }
/* No lock necessary */ pa_memblock *pa_memblock_new_user(pa_mempool *p, void *d, size_t length, pa_free_cb_t free_cb, bool read_only) { pa_memblock *b; pa_assert(p); pa_assert(d); pa_assert(length); pa_assert(length != (size_t) -1); pa_assert(free_cb); if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks)))) b = pa_xnew(pa_memblock, 1); PA_REFCNT_INIT(b); b->pool = p; b->type = PA_MEMBLOCK_USER; b->read_only = read_only; b->is_silence = false; pa_atomic_ptr_store(&b->data, d); b->length = length; pa_atomic_store(&b->n_acquired, 0); pa_atomic_store(&b->please_signal, 0); b->per_type.user.free_cb = free_cb; stat_add(b); return b; }
static uint16_t retest(void) { stat_add(STAT_MAC_RETRY_ACK_TIMEOUT); count_as_retry = 1; tx_delay(); return 0; }
int main(int argc, char *argv[]) { int diff; diff = stat_getsize("image_plusone.bmp.gz") - stat_getsize("image_ideal.bmp.gz"); printf("Diff: %d\n", diff); stat_add(diff, "statistic.txt"); return 0; }
/* No lock necessary */ pa_memblock *pa_memblock_new_pool(pa_mempool *p, size_t length) { pa_memblock *b = NULL; struct mempool_slot *slot; static int mempool_disable = 0; pa_assert(p); pa_assert(length); if (mempool_disable == 0) mempool_disable = getenv("PULSE_MEMPOOL_DISABLE") ? 1 : -1; if (mempool_disable > 0) return NULL; /* If -1 is passed as length we choose the size for the caller: we * take the largest size that fits in one of our slots. */ if (length == (size_t) -1) length = pa_mempool_block_size_max(p); if (p->block_size >= PA_ALIGN(sizeof(pa_memblock)) + length) { if (!(slot = mempool_allocate_slot(p))) return NULL; b = mempool_slot_data(slot); b->type = PA_MEMBLOCK_POOL; pa_atomic_ptr_store(&b->data, (uint8_t*) b + PA_ALIGN(sizeof(pa_memblock))); } else if (p->block_size >= length) { if (!(slot = mempool_allocate_slot(p))) return NULL; if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks)))) b = pa_xnew(pa_memblock, 1); b->type = PA_MEMBLOCK_POOL_EXTERNAL; pa_atomic_ptr_store(&b->data, mempool_slot_data(slot)); } else { pa_log_debug("Memory block too large for pool: %lu > %lu", (unsigned long) length, (unsigned long) p->block_size); pa_atomic_inc(&p->stat.n_too_large_for_pool); return NULL; } PA_REFCNT_INIT(b); b->pool = p; b->read_only = b->is_silence = false; b->length = length; pa_atomic_store(&b->n_acquired, 0); pa_atomic_store(&b->please_signal, 0); stat_add(b); return b; }
critical uint16_t mac_send(uint8_t packet[], uint16_t length, uint16_t dst_addr) { DEBUG("[csma] STAT_MAC_TX\n"); stat_add(STAT_MAC_TX); // check length if (length>PACKET_LENGTH_MAX) { DEBUG("[csma] STAT_ERROR_PACKET_TOO_LONG\n"); return 2; } // check state #ifdef QUEUE_ENABLE if (mess_in_queue >= QUEUE_LEN) { // there is already a frame about to be sent printf("[QUEUE];FULL_QUEUE\n"); stat_add(STAT_FULL_QUEUE); error_cb(); return 1; } else if (txframe.length != 0) { printf("[QUEUE];PUSH\n"); stat_add(STAT_ADD_QUEUE); mess_queue[mess_in_queue].length = length + HEADER_LENGTH; mess_queue[mess_in_queue].type = TYPE_DATA; mess_queue[mess_in_queue].dst_addr[0] = dst_addr>>8; mess_queue[mess_in_queue].dst_addr[1] = dst_addr & 0xFF; mess_queue[mess_in_queue].src_addr[0] = node_addr>>8; mess_queue[mess_in_queue].src_addr[1] = node_addr & 0xFF; // copy payload memcpy(mess_queue[mess_in_queue].payload, packet, mess_queue[mess_in_queue].length - HEADER_LENGTH); mess_in_queue += 1; return 0; }
/* Self-locked */ pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_id, size_t offset, size_t size) { pa_memblock *b = NULL; pa_memimport_segment *seg; pa_assert(i); pa_mutex_lock(i->mutex); if ((b = pa_hashmap_get(i->blocks, PA_UINT32_TO_PTR(block_id)))) { pa_memblock_ref(b); goto finish; } if (pa_hashmap_size(i->blocks) >= PA_MEMIMPORT_SLOTS_MAX) goto finish; if (!(seg = pa_hashmap_get(i->segments, PA_UINT32_TO_PTR(shm_id)))) if (!(seg = segment_attach(i, shm_id))) goto finish; if (offset+size > seg->memory.size) goto finish; if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks)))) b = pa_xnew(pa_memblock, 1); PA_REFCNT_INIT(b); b->pool = i->pool; b->type = PA_MEMBLOCK_IMPORTED; b->read_only = true; b->is_silence = false; pa_atomic_ptr_store(&b->data, (uint8_t*) seg->memory.ptr + offset); b->length = size; pa_atomic_store(&b->n_acquired, 0); pa_atomic_store(&b->please_signal, 0); b->per_type.imported.id = block_id; b->per_type.imported.segment = seg; pa_hashmap_put(i->blocks, PA_UINT32_TO_PTR(block_id), b); seg->n_blocks++; stat_add(b); finish: pa_mutex_unlock(i->mutex); return b; }
int main(int argc, char **argv) { Stat_T data; stat_init(&data); while (--argc) { double ftmp; ftmp = atof(*(++argv)); stat_add(ftmp, &data); } puts("\nBefore \"Olympic\" filtering\n"); printf("Minimum datum = %g\n", stat_min(&data)); printf("Maximum datum = %g\n", stat_max(&data)); printf("Number of samples = %d\n", stat_count(&data)); printf("Arithmetic mean = %g\n", stat_mean(&data)); printf("Geometric mean = %g\n", stat_gmean(&data)); printf("Harmonic mean = %g\n", stat_hmean(&data)); printf("Standard deviation (N) = %g\n", stat_stddevP(&data)); printf("Standard deviation (N-1) = %g\n", stat_stddevS(&data)); printf("Variance = %g\n", stat_var(&data)); printf("Population coeff. of var. = %g%%\n", stat_varcoeffP(&data)); printf("Sample coeff. of var. = %g%%\n", stat_varcoeffS(&data)); puts("\nAfter \"Olympic\" filtering\n"); printf("stat_olympic() returned %s\n", stat_olympic(&data) ? "ERROR" : "SUCCESS"); printf("Minimum datum = %g\n", stat_min(&data)); printf("Maximum datum = %g\n", stat_max(&data)); printf("Number of samples = %d\n", stat_count(&data)); printf("Arithmetic mean = %g\n", stat_mean(&data)); printf("Geometric mean = %g\n", stat_gmean(&data)); printf("Harmonic mean = %g\n", stat_hmean(&data)); printf("Standard deviation (N) = %g\n", stat_stddevP(&data)); printf("Standard deviation (N-1) = %g\n", stat_stddevS(&data)); printf("Variance = %g\n", stat_var(&data)); printf("Population coeff. of var. = %g%%\n", stat_varcoeffP(&data)); printf("Sample coeff. of var. = %g%%\n", stat_varcoeffS(&data)); return EXIT_SUCCESS; }
/* No lock necessary */ pa_memblock *pa_memblock_new_fixed(pa_mempool *p, void *d, size_t length, int read_only) { pa_memblock *b; pa_assert(p); pa_assert(d); pa_assert(length != (size_t) -1); pa_assert(length > 0); if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks)))) b = pa_xnew(pa_memblock, 1); PA_REFCNT_INIT(b); b->pool = p; b->type = PA_MEMBLOCK_FIXED; b->read_only = read_only; pa_atomic_ptr_store(&b->data, d); b->length = length; pa_atomic_store(&b->n_acquired, 0); pa_atomic_store(&b->please_signal, 0); stat_add(b); return b; }
/* No lock necessary */ static pa_memblock *memblock_new_appended(pa_mempool *p, size_t length) { pa_memblock *b; pa_assert(p); pa_assert(length); /* If -1 is passed as length we choose the size for the caller. */ if (length == (size_t) -1) length = pa_mempool_block_size_max(p); b = pa_xmalloc(PA_ALIGN(sizeof(pa_memblock)) + length); PA_REFCNT_INIT(b); b->pool = p; b->type = PA_MEMBLOCK_APPENDED; b->read_only = b->is_silence = false; pa_atomic_ptr_store(&b->data, (uint8_t*) b + PA_ALIGN(sizeof(pa_memblock))); b->length = length; pa_atomic_store(&b->n_acquired, 0); pa_atomic_store(&b->please_signal, 0); stat_add(b); return b; }
int main(void) { WDTCTL = WDTPW+WDTHOLD; set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); set_aclk_div(1); LEDS_INIT(); LEDS_OFF(); ds2411_init(); nodeaddr = (((uint16_t)ds2411_id.serial1)<<8) + (ds2411_id.serial0); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_rx); eint(); printf("[APP];BOOTING;%.4x\n",nodeaddr); //check if this node is the sink if (nodeaddr == sink_nodes) { type = SINK; level = DEFAULT_LEVEL; } else { //retrieve father for (idx=0; idx<NUMBER_NODES; idx++) { if (list_nodes[idx] == nodeaddr) { if(father_nodes1[idx] != 0x0000) { parent_id = father_nodes1[idx]; level = 12; break; } } } } //hack for mobile /*if(nodeaddr == 0x1f5d) { parent_id = 0x0000; mac_set_mobile(1); level = 12; }*/ mac_init(10); mac_set_rx_cb(packet_received); mac_set_error_cb(packet_error); mac_set_sent_cb(packet_sent); timerB_set_alarm_from_now(TIMERB_ALARM_CCR6, 32768, 32768); timerB_register_cb(TIMERB_ALARM_CCR6, inc_clock); while (1) { LPM1; if (state == SM_TX) { if (level != UNDEF_LEVEL && type != SINK) { seq_max = NUM_SEQ_MAX; delay = rand(); delay &= 0xCFFF; delay += 12000; //(369ms < delay < 1991ms) timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, delay, 0); timerB_register_cb(TIMERB_ALARM_CCR5, next_send); } else { printf("[APP];NOROUTE\n"); } state = SM_IDLE; } else if (state == SM_LOOP_TX) { if (level != UNDEF_LEVEL) { sprintf(sourceaddr,"%.4x",nodeaddr); data_txframe[0] = DATA; data_txframe[1] = level-1; data_txframe[2] = sourceaddr[0]; data_txframe[3] = sourceaddr[1]; data_txframe[4] = sourceaddr[2]; data_txframe[5] = sourceaddr[3]; data_txframe[6] = seq; //sequence data_txframe[7] = 1; //hops txlength = 8; stat_add(STAT_APP_TX); printf("[APP];NODE_TX;%.4x;%.4x;%u;%u-%u\n", nodeaddr, parent_id, seq, global_clock, timerB_time()/32); seq++; mac_send(data_txframe, txlength, parent_id); if (DEBUG_LEDS == 1) { LED_GREEN_ON(); } if (seq < seq_max) { timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, SEND_DATA_PERIOD, 0); timerB_register_cb(TIMERB_ALARM_CCR5, next_send); } } state = SM_IDLE; } } return 0; }
static int handle_txn_close(TSCont cont, TSEvent event ATS_UNUSED, void *edata) { TSHttpTxn txn = (TSHttpTxn) edata; config_t *config; void *txnd; int status_code = 0; TSMBuffer buf; TSMLoc hdr_loc; uint64_t out_bytes, in_bytes; char *remap, *hostname; char *unknown = "unknown"; char stat_name[MAX_STAT_LENGTH]; config = (config_t *) TSContDataGet(cont); txnd = TSHttpTxnArgGet(txn, config->txn_slot); hostname = (char *) ((uintptr_t) txnd & (~((uintptr_t) 0x01))); // Get hostname if (txnd) { if ((uintptr_t) txnd & 0x01) // remap succeeded? { if (!config->post_remap_host) remap = hostname; else remap = get_effective_host(txn); if (!remap) remap = unknown; in_bytes = TSHttpTxnClientReqHdrBytesGet(txn); in_bytes += TSHttpTxnClientReqBodyBytesGet(txn); CREATE_STAT_NAME(stat_name, remap, "in_bytes"); stat_add(stat_name, (TSMgmtInt) in_bytes, config->persist_type, config->stat_creation_mutex); out_bytes = TSHttpTxnClientRespHdrBytesGet(txn); out_bytes += TSHttpTxnClientRespBodyBytesGet(txn); CREATE_STAT_NAME(stat_name, remap, "out_bytes"); stat_add(stat_name, (TSMgmtInt) out_bytes, config->persist_type, config->stat_creation_mutex); if (TSHttpTxnClientRespGet(txn, &buf, &hdr_loc) == TS_SUCCESS) { status_code = (int) TSHttpHdrStatusGet(buf, hdr_loc); TSHandleMLocRelease(buf, TS_NULL_MLOC, hdr_loc); if (status_code < 200) CREATE_STAT_NAME(stat_name, remap, "status_other"); else if (status_code <= 299) CREATE_STAT_NAME(stat_name, remap, "status_2xx"); else if (status_code <= 399) CREATE_STAT_NAME(stat_name, remap, "status_3xx"); else if (status_code <= 499) CREATE_STAT_NAME(stat_name, remap, "status_4xx"); else if (status_code <= 599) CREATE_STAT_NAME(stat_name, remap, "status_5xx"); else CREATE_STAT_NAME(stat_name, remap, "status_other"); stat_add(stat_name, 1, config->persist_type, config->stat_creation_mutex); } else { CREATE_STAT_NAME(stat_name, remap, "status_unknown"); stat_add(stat_name, 1, config->persist_type, config->stat_creation_mutex); } if (remap != unknown) TSfree(remap); } else if (hostname) TSfree(hostname); } TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); TSDebug(DEBUG_TAG, "Handler Finished"); return 0; }