Ejemplo n.º 1
0
/*!
 * \brief Insert a new record into transactions table
 * \param ruri request uri
 * \return 0 on success, -1 on failure
 */
int insert_ts_urecord(str* ruri, ts_urecord_t** _r)
{
	ts_entry_t* entry;

	int sl;

	if (new_ts_urecord(ruri, _r) < 0) {
		LM_ERR("creating urecord failed\n");
		return -1;
	}

	sl = ((*_r)->rurihash)&(t_table->size-1);
	entry = &t_table->entries[sl];

	if (entry->n == 0) {
		entry->first = entry->last = *_r;
	} else {
		(*_r)->prev = entry->last;
		entry->last->next = *_r;
		entry->last = *_r;
	}
	entry->n++;
	(*_r)->entry = entry;

	update_stat(stored_ruris, 1);
	update_stat(total_ruris, 1);

	LM_DBG("urecord entry %p",entry);
	return 0;
}
Ejemplo n.º 2
0
static int ws_send_reply(sip_msg_t *msg, int code, str *reason, str *hdrs)
{
	if (hdrs && hdrs->len > 0)
	{
		if (add_lump_rpl(msg, hdrs->s, hdrs->len, LUMP_RPL_HDR) == 0)
		{
			LM_ERR("inserting extra-headers lump\n");
			update_stat(ws_failed_handshakes, 1);
			return -1;
		}
	}

	if (ws_slb.freply(msg, code, reason) < 0)
	{
		LM_ERR("sending reply\n");
		update_stat(ws_failed_handshakes, 1);
		return -1;
	}

	update_stat(
		code == 101 ? ws_successful_handshakes : ws_failed_handshakes,
		1);

	return 0;
}
Ejemplo n.º 3
0
static int w_update_stat(struct sip_msg *msg, char *stat_p, char *n)
{
	struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p;
	pv_value_t pv_val;
	stat_var *stat;

	if (sopv->stat) {
		update_stat( sopv->stat, (long)n);
	} else {
		if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 ||
		(pv_val.flags & PV_VAL_STR)==0 ) {
			LM_ERR("failed to get pv string value\n");
			return -1;
		}
		stat = get_stat( &(pv_val.rs) );
		if ( stat == 0 ) {
			LM_ERR("variable <%.*s> not defined\n",
				pv_val.rs.len, pv_val.rs.s);
			return -1;
		}
		update_stat( stat, (long)n);
	}

	return 1;
}
Ejemplo n.º 4
0
void oneway_nb_test(int iters, int nbytes, int alignment)
{GASNET_BEGIN_FUNCTION();
    int i;
    int64_t begin, end;
    stat_struct_t st;
    gasnet_handle_t *handles;
    int pad = (alignment % PAGESZ);

	/* initialize statistics */
	init_stat(&st, nbytes, alignment);
	
	handles = (gasnet_handle_t*) test_malloc(sizeof(gasnet_handle_t) * iters);
	
	memset(locbuf+pad, 1, nbytes);

	BARRIER();
	
	if (iamsender) {
		/* measure the throughput of sending a message */
		begin = TIME();
                for (i = 0; i < iters; i++) {
                        handles[i] = gasnet_put_nb_bulk(peerproc, rembuf, locbuf+pad, nbytes);
                }
		gasnet_wait_syncnb_all(handles, iters); 
		end = TIME();
	 	update_stat(&st, (end - begin), iters);
	}
	
	BARRIER();
	
	if (iamsender) {
		print_stat(myproc, &st, "put_nb_bulk throughput", PRINT_THROUGHPUT);
	}	
	
	/* initialize statistics */
	init_stat(&st, nbytes, alignment);

	if (iamsender) {
		/* measure the throughput of receiving a message */
		begin = TIME();
                for (i = 0; i < iters; i++) {
                    handles[i] = gasnet_get_nb_bulk(locbuf, peerproc, rembuf+pad, nbytes);
                } 
		gasnet_wait_syncnb_all(handles, iters); 
		end = TIME();
	 	update_stat(&st, (end - begin), iters);
	}
	
	BARRIER();
	
	if (iamsender) {
		print_stat(myproc, &st, "get_nb_bulk throughput", PRINT_THROUGHPUT);
	}	
	
	test_free(handles);
}
Ejemplo n.º 5
0
static int km_cb_req_stats(struct sip_msg *msg,
		unsigned int flags, void *param)
{
	update_stat(rcv_reqs, 1);
	if(!IS_SIP(msg))
		return 1;
	if(msg->first_line.u.request.method_value==METHOD_OTHER)
		update_stat(unsupported_methods, 1);
	return 1;
}
Ejemplo n.º 6
0
static int child_init(int rank)
{
	if (rank==1) {
		/* init stats */
		update_stat( max_expires_stat, max_expires );
		update_stat( max_contacts_stat, max_contacts );
		update_stat( default_expire_stat, default_expires );
	}

	return 0;
}
Ejemplo n.º 7
0
static int child_init(int rank) {
    int pid;
    int k=0;
    
    LM_DBG("Initialization of module in child [%d] \n", rank);

if (rank == PROC_MAIN) {
    
        /* fork notification workers */
	for(k=0;k<notification_processes;k++){
		pid = fork_process(1001+k,"notification_worker",1);
		if (pid==-1){
			LM_CRIT("init_notification_worker(): Error on fork() for worker!\n");
			return 0;
		}
		if (pid==0) {
			if (cfg_child_init()) return 0;
			notification_event_process();
			LM_CRIT("init_notification_worker():: worker_process finished without exit!\n");
			exit(-1);
		}
	}
    }
    
    
    if (rank == PROC_MAIN || rank == PROC_TCP_MAIN)
        return 0;
    if (rank == 1) {
        /* init stats */
        //TODO if parameters are modified via cfg framework do i change them?
        update_stat(max_expires_stat, default_registrar_cfg.max_expires);
        update_stat(max_contacts_stat, default_registrar_cfg.max_contacts);
        update_stat(default_expire_stat, default_registrar_cfg.default_expires);
    }
    /* don't do anything for main process and TCP manager process */

    /* don't do anything for main process and TCP manager process */
    if (rank == PROC_MAIN || rank == PROC_TCP_MAIN)
        return 0;

    /* Init the user data parser */
    if (!parser_init(scscf_user_data_dtd, scscf_user_data_xsd))
        return -1;
    
    
    lock_get(process_lock);
    if ((*callback_singleton) == 0) {
        *callback_singleton = 1;
        cdpb.AAAAddRequestHandler(callback_cdp_request, NULL);
    }
    lock_release(process_lock);

    return 0;
}
Ejemplo n.º 8
0
void handle_agent_reject(struct cc_call* call, int from_customer, int pickup_time)
{
	str un, fid, aid;
	str out;

	//update_stat( stg_aban_incalls, 1); /*abandon from agent */
	update_stat( call->agent->st_aban_incalls, 1);
	call->no_rejections++;

	/* put call back into queue */ 
	call->state = CC_CALL_QUEUED;
	call->setup_time = -1;

	lock_get( data->lock );

	/* prepare CDR */
	prepare_cdr( call, &un, &fid , &aid);

	call->agent->state = CC_AGENT_WRAPUP;
	call->agent->last_call_end = get_ticks();
	/* update last call_end for agent */
	cc_db_update_agent_end_call(call->agent);
	call->agent->ref_cnt--;
	call->agent = NULL;

	cc_queue_push_call( data, call, 1/*top*/);

	if(from_customer || call->prev_state != CC_CALL_QUEUED) {
		out.len = OUT_BUF_LEN(call->flow->recordings[AUDIO_QUEUE].len);
		out.s = out_buf;
		memcpy( out.s, call->flow->recordings[AUDIO_QUEUE].s, out.len);
	}

	lock_release( data->lock );

	if(from_customer || call->prev_state != CC_CALL_QUEUED) {
		/* send call to queue */
		if (set_call_leg( NULL, call, &out)< 0 ) {
			LM_ERR("failed to set new destination for call\n");
		}
		LM_DBG("onhold++: agent rejected [%p]\n", call);
		if(from_customer)
		{
			update_stat( stg_onhold_calls, 1);
			update_stat( call->flow->st_onhold_calls, 1);
		}
	}
	/* write CDR */
	cc_write_cdr( &un, &fid, &aid, -2, call->recv_time,
		get_ticks() - call->recv_time, 0 , pickup_time, call->no_rejections-1,
		call->fst_flags, call->id);
	cc_db_update_call(call);
}
Ejemplo n.º 9
0
static inline void _wsconn_rm(ws_connection_t *wsc)
{
	wsconn_listrm(wsconn_id_hash[wsc->id_hash], wsc, id_next, id_prev);

	update_stat(ws_current_connections, -1);
	if (wsc->sub_protocol == SUB_PROTOCOL_SIP)
		update_stat(ws_sip_current_connections, -1);
	else if (wsc->sub_protocol == SUB_PROTOCOL_MSRP)
		update_stat(ws_msrp_current_connections, -1);

	shm_free(wsc);
}
Ejemplo n.º 10
0
static int w_update_stat(struct sip_msg *msg, char *stat_p, char *n)
{
	struct stat_param *sp = (struct stat_param *)stat_p;
	pv_value_t pv_val;
	stat_var *stat;

	if (sp->type==STAT_PARAM_TYPE_STAT) {
		/* we have the statistic */
		update_stat( sp->u.stat, (long)n);
		return 1;
	}

	if (sp->type==STAT_PARAM_TYPE_PVAR) {
		/* take name from PVAR */
		if (pv_get_spec_value(msg, sp->u.pvar, &pv_val)!=0 ||
		(pv_val.flags & PV_VAL_STR)==0 ) {
			LM_ERR("failed to get pv string value\n");
			return -1;
		}
	} else if (sp->type==STAT_PARAM_TYPE_FMT) {
		/* take name from FMT */
		if (pv_printf_s( msg, sp->u.format, &(pv_val.rs) )!=0 ) {
			LM_ERR("failed to get format string value\n");
			return -1;
		}
	} else if (sp->type==STAT_PARAM_TYPE_NAME) {
		/* take name from STRING */
		pv_val.rs = *sp->u.name;
	}

	LM_DBG("needed statistic is <%.*s>\n", pv_val.rs.len, pv_val.rs.s);

	/* name is in pv_val.rs -> look for it */
	stat = get_stat( &(pv_val.rs) );
	if ( stat==NULL ) {
		/* stats not found -> create it */
		LM_DBG("creating dynamic statistic <%.*s>\n",
			pv_val.rs.len, pv_val.rs.s);
		if (register_dynamic_stat( &(pv_val.rs), &stat )!=0) {
			LM_ERR("failed to create dynamic statistic <%.*s>\n",
				pv_val.rs.len, pv_val.rs.s);
			return -1;
		}
		if (sp->type==STAT_PARAM_TYPE_NAME) {
			sp->u.stat = stat;
			sp->type=STAT_PARAM_TYPE_STAT;
		}
	}

	/* statistic exists ! */
	update_stat( stat, (long)n);
	return 1;
}
Ejemplo n.º 11
0
struct hp_block *hp_shm_malloc_init(char *address, unsigned long size,
									char *name)
{
	struct hp_block *hpb;
	
	hpb = hp_malloc_init(address, size, name);
	if (!hpb) {
		LM_ERR("failed to initialize shm block\n");
		return NULL;
	}

#ifdef HP_MALLOC_FAST_STATS
	hpb->free_hash[PEEK_HASH_RR(hpb, hpb->first_frag->size)].total_no++;
#endif

	hp_frag_attach(hpb, hpb->first_frag);

	/* first fragment attach is the equivalent of a split  */
	if (stats_are_ready()) {
#if defined(STATISTICS) && !defined(HP_MALLOC_FAST_STATS)
		update_stat(shm_rused, FRAG_OVERHEAD);
		update_stat(shm_frags, 1);
#endif
#if defined(DBG_MALLOC) || defined(STATISTICS)
		hpb->real_used += FRAG_OVERHEAD;
		hpb->total_fragments++;
#endif
	} else {
		hpb->real_used += FRAG_OVERHEAD;
		hpb->total_fragments++;
	}

#ifdef HP_MALLOC_FAST_STATS
#ifdef DBG_MALLOC
	hp_stats_lock = hp_shm_malloc_unsafe(hpb, sizeof *hp_stats_lock,
											__FILE__, __FUNCTION__, __LINE__);
#else
	hp_stats_lock = hp_shm_malloc_unsafe(hpb, sizeof *hp_stats_lock);
#endif
	if (!hp_stats_lock) {
		LM_ERR("failed to alloc hp statistics lock\n");
		return NULL;
	}

	if (!lock_init(hp_stats_lock)) {
		LM_CRIT("could not initialize hp statistics lock\n");
		return NULL;
	}
#endif

	return hpb;
}
Ejemplo n.º 12
0
void oneway_nbi_test(int iters, int nbytes, int alignment)
{GASNET_BEGIN_FUNCTION();
    int i;
    int64_t begin, end;
    stat_struct_t st;
    int pad = (alignment % PAGESZ);

	/* initialize statistics */
	init_stat(&st, nbytes, alignment);
	
	memset(locbuf+pad, 1, nbytes);

	BARRIER();
	
	if (iamsender) {
		/* measure the throughput of nonblocking implicit bulk put */
		begin = TIME();
		for (i = 0; i < iters; i++) {
			gasnet_put_nbi_bulk(peerproc, rembuf, locbuf+pad, nbytes);
		}
		gasnet_wait_syncnbi_puts();
		end = TIME();
	 	update_stat(&st, (end - begin), iters);
	}
	
	BARRIER();
	
	if (iamsender) {
		print_stat(myproc, &st, "put_nbi_bulk throughput", PRINT_THROUGHPUT);
	}	

	/* initialize statistics */
	init_stat(&st, nbytes, alignment);

	if (iamsender) {
		/* measure the throughput of nonblocking implicit bulk get */
		begin = TIME();
		for (i = 0; i < iters; i++) {
	 		gasnet_get_nbi_bulk(locbuf, peerproc, rembuf+pad, nbytes);
		}
		gasnet_wait_syncnbi_gets();
		end = TIME();
	 	update_stat(&st, (end - begin), iters);
	}
	
	BARRIER();
	
	if (iamsender) {
		print_stat(myproc, &st, "get_nbi_bulk throughput", PRINT_THROUGHPUT);
	}	
}
Ejemplo n.º 13
0
static int child_init(int rank)
{
	if(sruid_init(&_reg_sruid, '-', "uloc", SRUID_INC)<0)
		return -1;
	if (rank==1) {
		/* init stats */
		//TODO if parameters are modified via cfg framework do i change them?
		update_stat( max_expires_stat, default_registrar_cfg.max_expires );
		update_stat( max_contacts_stat, default_registrar_cfg.max_contacts );
		update_stat( default_expire_stat, default_registrar_cfg.default_expires );
	}

	return 0;
}
Ejemplo n.º 14
0
/* Take care of the statistics associated with numerical codes and replies */
static inline void update_sl_reply_stat(int code) 
{
	stat_var *numerical_stat;

	/* If stats aren't enabled, just skip over this. */
	if (!sl_enable_stats) 
		return;

	/* OpenSIPS already kept track of the total number of 1xx, 2xx, replies.
	* There may be setups that still expect these variables to exist, so we
	* don't touch them */
	if (code < 200 ) {
		update_stat( tx_1xx_rpls , 1);
	} else if (code<300) {
		update_stat( tx_2xx_rpls , 1);
	} else if (code<400) {
		update_stat( tx_3xx_rpls , 1);
	} else if (code<500) {
		update_stat( tx_4xx_rpls , 1);
	} else if (code<600) {
		update_stat( tx_5xx_rpls , 1);
	} else {
		update_stat( tx_6xx_rpls , 1);
	}

	update_stat( sent_rpls , 1);

	numerical_stat = get_stat_var_from_num_code(code, 1);

	if (numerical_stat != NULL)
		update_stat(numerical_stat, 1);
}
Ejemplo n.º 15
0
/*!
 * \brief Write through timer, used for WRITE_THROUGH db_mode
 *
 * Write through timer, used for WRITE_THROUGH db_mode. Process all
 * contacts from the record, delete all expired ones from the DB.
 * \param _r processed record
 * \note currently unused, this mode is also handled by the wb_timer
 */
static inline void wt_timer(urecord_t* _r)
{
	ucontact_t* ptr, *t;

	ptr = _r->contacts;

	while(ptr) {
		if (!VALID_CONTACT(ptr, act_time)) {
			/* run callbacks for EXPIRE event */
			if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
			}

			LM_DBG("Binding '%.*s','%.*s' has expired\n",
				ptr->aor->len, ZSW(ptr->aor->s),
				ptr->c.len, ZSW(ptr->c.s));

			t = ptr;
			ptr = ptr->next;

			if (db_delete_ucontact(t) < 0) {
				LM_ERR("deleting contact from database failed\n");
			}
			mem_delete_ucontact(_r, t);
			update_stat( _r->slot->d->expires, 1);
		} else {
			ptr = ptr->next;
		}
	}
}
Ejemplo n.º 16
0
void init_stats() {
  char startup_time[12];
  sprintf(startup_time, "%ld", time(NULL));

  if (serialize_file && !clear_stats) {
    syslog(LOG_DEBUG, "Deserializing stats from file.");

    statsd_deserialize(serialize_file);
  }

  remove_stats_lock();

  update_stat( "graphite", "last_flush", startup_time );
  update_stat( "messages", "last_msg_seen", startup_time );
  update_stat( "messages", "bad_lines_seen", "0" );
}
Ejemplo n.º 17
0
void bulk_test_nb(int iters) {GASNET_BEGIN_FUNCTION();
    int i;
    int64_t begin, end;
    stat_struct_t stput;
    gasnet_handle_t *handles;
    int payload;
    
	handles = (gasnet_handle_t *) test_malloc(sizeof(gasnet_handle_t) * iters);

	for (payload = min_payload; payload <= max_payload && payload > 0; payload *= 2) {
		init_stat(&stput, payload);

		BARRIER();
	
		if (iamsender) {
			/* measure the throughput of sending a message */
			begin = TIME();
			for (i = 0; i < iters; i++) {
				handles[i] = gasnet_memset_nb(peerproc, tgtmem, 0x5a, payload);
			}
			gasnet_wait_syncnb_all(handles, iters);
			end = TIME();
		 	update_stat(&stput, (end - begin), iters);
		}
	
		BARRIER();
       
		if (iamsender) {
			print_stat(myproc, &stput, "memset_nb throughput", PRINT_THROUGHPUT);
		}	
	
	}

	test_free(handles);
}
Ejemplo n.º 18
0
void bulk_test(int iters) {GASNET_BEGIN_FUNCTION();
    int i;
    int64_t begin, end;
    stat_struct_t stput;
    int payload;
    
	for (payload = min_payload; payload <= max_payload && payload > 0; payload *= 2) {
		init_stat(&stput, payload);

		BARRIER();
	
		if (iamsender) {
			/* measure the throughput of sending a message */
			begin = TIME();
			for (i = 0; i < iters; i++) {
				gasnet_memset(peerproc, tgtmem, 0xaa, payload);
			}
			end = TIME();
		 	update_stat(&stput, (end - begin), iters);
		}
	
		BARRIER();

		if (iamsender) {
			print_stat(myproc, &stput, "memset throughput", PRINT_THROUGHPUT);
		}	
	
	}

}
Ejemplo n.º 19
0
void cc_queue_rmv_call( struct cc_data *data, struct cc_call *call)
{
	LM_DBG(" QUEUE - removing call %p \n",call);
	if ( !is_call_in_queue(data, call) ) { 
		LM_CRIT(" QUEUE - call not in queue l=%p, h=%p\n",
				call->lower_in_queue, call->higher_in_queue);
		abort();
	}

	if (call->lower_in_queue) {
		call->lower_in_queue->higher_in_queue =
			call->higher_in_queue;
	} else {
		data->queue.last = call->higher_in_queue;
	}
	if (call->higher_in_queue) {
		call->higher_in_queue->lower_in_queue =
			call->lower_in_queue;
	} else {
		data->queue.first = call->lower_in_queue;
	}
	call->lower_in_queue = call->higher_in_queue = NULL;
	data->queue.calls_no--;
	update_stat( call->flow->st_queued_calls, -1 );
}
Ejemplo n.º 20
0
/*!
 * \brief Insert a new transaction structure into urecord
 * \param _r urecord
 * \param tindex transaction index in tm table
 * \param tlabel transaction label in tm table
 * \return 0 on success, -1 otherwise
 */
int insert_ts_transaction(struct cell* t, struct sip_msg* msg, struct ts_urecord* _r)
{
	ts_transaction_t *ptr, *prev;
	ts_transaction_t* ts;

	unsigned int tindex;
	unsigned int tlabel;

	tindex = t->hash_index;
	tlabel = t->label;

	ptr = prev = 0;
	ptr = _r->transactions;

	while(ptr) {
		if ((ptr->tindex == tindex) && (ptr->tlabel == tlabel)) {
			LM_DBG("transaction already inserted\n");
			return -1;
		}
		prev = ptr;
		ptr = ptr->next;
	}

	if ( (ts=new_ts_transaction(tindex, tlabel) ) == 0) {
		LM_ERR("failed to create new transaction\n");
		return -1;
	}

	ts->urecord = _r;
	/* add the new transaction at the end of the list */

	if (prev) {
		prev->next = ts;
		ts->prev = prev;
	} else {
		_r->transactions = ts;
	}

	if (ts_set_tm_callbacks(t, msg, ts) < 0) {
		LM_ERR("failed to set transaction %d:%d callbacks\n", tindex, tlabel);
	}

	update_stat(stored_transactions, 1);
	update_stat(total_transactions, 1);

	return 0;
}
Ejemplo n.º 21
0
/*!
 * \brief Write-back timer, used for WRITE_BACK db_mode
 *
 * Write-back timer, used for WRITE_BACK db_mode. Process
 * all contacts from the record, delete expired ones from the DB.
 * Furthermore it updates changed contacts, and also insert new
 * ones in the DB.
 * \param _r processed record
 */
static inline void wb_timer(urecord_t* _r)
{
	ucontact_t* ptr, *t;
	cstate_t old_state;
	int op;

	ptr = _r->contacts;

	while(ptr) {
		if (!VALID_CONTACT(ptr, act_time)) {
			/* run callbacks for EXPIRE event */
			if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
			}

			LM_DBG("Binding '%.*s','%.*s' has expired\n",
				ptr->aor->len, ZSW(ptr->aor->s),
				ptr->c.len, ZSW(ptr->c.s));
			update_stat( _r->slot->d->expires, 1);

			t = ptr;
			ptr = ptr->next;

			/* Should we remove the contact from the database ? */
			if (st_expired_ucontact(t) == 1) {
				if (db_delete_ucontact(t) < 0) {
					LM_ERR("failed to delete contact from the database\n");
				}
			}

			mem_delete_ucontact(_r, t);
		} else {
			/* Determine the operation we have to do */
			old_state = ptr->state;
			op = st_flush_ucontact(ptr);

			switch(op) {
			case 0: /* do nothing, contact is synchronized */
				break;

			case 1: /* insert */
				if (db_insert_ucontact(ptr) < 0) {
					LM_ERR("inserting contact into database failed\n");
					ptr->state = old_state;
				}
				break;

			case 2: /* update */
				if (db_update_ucontact(ptr) < 0) {
					LM_ERR("updating contact in db failed\n");
					ptr->state = old_state;
				}
				break;
			}

			ptr = ptr->next;
		}
	}
}
Ejemplo n.º 22
0
static unsigned int update_balloon_stats(struct virtio_balloon *vb)
{
	unsigned long events[NR_VM_EVENT_ITEMS];
	struct sysinfo i;
	unsigned int idx = 0;
	long available;

	all_vm_events(events);
	si_meminfo(&i);

	available = si_mem_available();

#ifdef CONFIG_VM_EVENT_COUNTERS
	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
				pages_to_bytes(events[PSWPIN]));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
				pages_to_bytes(events[PSWPOUT]));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]);
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]);
#endif
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE,
				pages_to_bytes(i.freeram));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,
				pages_to_bytes(i.totalram));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
				pages_to_bytes(available));

	return idx;
}
Ejemplo n.º 23
0
/* must be called with unlocked WSCONN_LOCK */
int wsconn_put(ws_connection_t *wsc)
{
	int destroy = 0;

	LM_DBG("wsconn_put start for [%p] refcnt [%d]\n", wsc, atomic_get(&wsc->refcnt));

	if (!wsc)
		return -1;

	WSCONN_LOCK;
	/* refcnt == 0*/
	if (wsconn_unref(wsc))
	{
		/* Remove from the WebSocket used list */
		if (wsconn_used_list->head == wsc)
			wsconn_used_list->head = wsc->used_next;
		if (wsconn_used_list->tail == wsc)
			wsconn_used_list->tail = wsc->used_prev;
		if (wsc->used_prev)
			wsc->used_prev->used_next = wsc->used_next;
		if (wsc->used_next)
			wsc->used_next->used_prev = wsc->used_prev;

		/* remove from wsconn_id_hash */
		wsconn_listrm(wsconn_id_hash[wsc->id_hash], wsc, id_next, id_prev);

		/* stat */
		update_stat(ws_current_connections, -1);
		if (wsc->sub_protocol == SUB_PROTOCOL_SIP)
			update_stat(ws_sip_current_connections, -1);
		else if (wsc->sub_protocol == SUB_PROTOCOL_MSRP)
			update_stat(ws_msrp_current_connections, -1);

		destroy = 1;
	}
	WSCONN_UNLOCK;

	LM_DBG("wsconn_put end for [%p] refcnt [%d]\n", wsc, atomic_get(&wsc->refcnt));

	/* wsc is removed from all lists and can be destroyed safely */
	if (destroy)
		wsconn_dtor(wsc);

	return 0;
}
Ejemplo n.º 24
0
static inline void nodb_timer(pcontact_t* _c)
{
	LM_DBG("Running nodb timer on <%.*s>, "
			"Reg state: %s, "
			"Expires: %d, "
			"Expires in: %d seconds, "
			"Received: %.*s:%d, "
                        "Path: %.*s, "
			"Proto: %d, "
                        "Hash: %u, " 
                        "Slot: %u\n",
			_c->aor.len, _c->aor.s,
			reg_state_to_string(_c->reg_state),
			(int)_c->expires,
			(int)(_c->expires - time(NULL)),
			_c->received_host.len, _c->received_host.s,
			_c->received_port,
                        _c->path.len, _c->path.s,
			_c->received_proto,
                        _c->aorhash,
                        _c->sl);

	get_act_time();
        
        
        if ((_c->expires - act_time) + expires_grace <= 0) {//we've allowed some grace time TODO: add as parameter
        //if ((_c->expires - act_time) <= -10) {//we've allowed some grace time TODO: add as parameter
		LM_DBG("pcscf contact <%.*s> has expired and will be removed\n", _c->aor.len, _c->aor.s);
		if (exists_ulcb_type(PCSCF_CONTACT_EXPIRE)) {
			run_ul_callbacks(PCSCF_CONTACT_EXPIRE, _c);
		}

		if (db_mode == WRITE_THROUGH && db_delete_pcontact(_c) != 0) {
			LM_ERR("Error deleting ims_usrloc_pcscf record in DB");
		}

		update_stat(_c->slot->d->expired, 1);
		mem_delete_pcontact(_c->slot->d, _c);
		return;
	}

	//TODO: this is just for tmp debugging
//	p = _c->head;
//	while (p) {
//		if (p->is_default)
//			LM_DBG("public identity %i (default): <%.*s>\n", i, p->public_identity.len, p->public_identity.s);
//		else
//			LM_DBG("public identity %i: <%.*s>\n", i, p->public_identity.len, p->public_identity.s);
//		i++;
//		p=p->next;
//	}
//
//	LM_DBG("There are %i service routes as follows:\n", _c->num_service_routes);
//	for (i=0; i<_c->num_service_routes; i++) {
//		LM_DBG("service route %i: <%.*s>\n", i+1, _c->service_routes[i].len, _c->service_routes[i].s);
//	}
}
Ejemplo n.º 25
0
void cc_queue_push_call(struct cc_data *data, struct cc_call *call, int top)
{
	struct cc_call *call_it;
	int n = 0;

	LM_DBG(" QUEUE - adding call %p \n",call);
	if ( is_call_in_queue(data, call) ) {
		LM_CRIT(" QUEUE - call already in queue \n");
		abort();
	}

	if (top) {
		/* add the call in the very top of the queue */
		call_it = NULL;
	} else {
		/* search (priority based) the place in queue */
		for(call_it=data->queue.last ; call_it ; call_it=call_it->higher_in_queue){
			if (call_it->flow->priority <= call->flow->priority)
				break;
			n++;
		}
	}


	if (call_it) {
		/* add before it */
		if (call_it->lower_in_queue) {
			call_it->lower_in_queue->higher_in_queue = call;
		} else {
			data->queue.last = call;
		}
		call->lower_in_queue = call_it->lower_in_queue;
		call->higher_in_queue = call_it;
		call_it->lower_in_queue = call;
	} else {
		/* add in top of the queue */
		call->lower_in_queue = data->queue.first;
		if (data->queue.first) {
			data->queue.first->higher_in_queue = call;
		}
		else {
			data->queue.last = call;
		}
		call->higher_in_queue = NULL;
		data->queue.first = call;
	}
	data->queue.calls_no++;
	update_stat( call->flow->st_queued_calls, +1 );
	
	LM_DBG("adding call on pos %d (already %d calls), l=%p h=%p\n",
		n, data->queue.calls_no,
		call->lower_in_queue, call->higher_in_queue);
	call->ref_cnt++;

	if (call->queue_start==0)
		call->queue_start = get_ticks();
}
Ejemplo n.º 26
0
/* Check for completed transfers, and remove their easy handles */
void check_multi_info(struct http_m_global *g)
{
	char *eff_url;
	CURLMsg *msg;
	int msgs_left;
	CURL *easy;
	CURLcode res;

	struct http_m_cell *cell;

	LM_DBG("REMAINING: %d\n", g->still_running);
	while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
		if (msg->msg == CURLMSG_DONE) {
			easy = msg->easy_handle;
			res = msg->data.result;
			curl_easy_getinfo(easy, CURLINFO_PRIVATE, &cell);
			curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
			LM_DBG("DONE: %s => (%d) %s\n", eff_url, res, cell->error);

			cell = http_m_cell_lookup(easy);
			if (msg->data.result != 0) {
				LM_ERR("handle %p returned error %d: %s\n", easy, res, cell->error);
				update_stat(errors, 1);
				reply_error(cell);
			} else {
				cell->reply->error[0] = '\0';
				cell->cb(cell->reply, cell->param);

				LM_DBG("reply: [%d] %.*s [%d]\n", (int)cell->reply->retcode, cell->reply->result->len, cell->reply->result->s, cell->reply->result->len);
				update_stat(replies, 1);
			}

			if (cell != 0) {
				LM_DBG("cleaning up cell %p\n", cell);
				unlink_http_m_cell(cell);
				free_http_m_cell(cell);
			}

			LM_DBG("Removing handle %p\n", easy);
			curl_multi_remove_handle(g->multi, easy);
			curl_easy_cleanup(easy);
		}
	}
}
Ejemplo n.º 27
0
/* ------------------------------------------------------------------
 * Opens and iterates through a given directory, operating on allowed
 * files found within it.  . and .. are skipped, as are files beginning
 * with . unless it's been enabled in the flags.  All other entries,
 * both files and directories, are thrown to process_entry to determine
 * whether they're a file/directory/link, and to read/explore them if
 * appropriate.  If threads are being used, they wait for their children
 * threads to terminate after they themselves are done with their work.
 *
 * flags:	The usual I/O option flags.
 * list_head:	A list of already visited directories.  Always will have
 *		the working directory low was called from as the tail,
 *		and will always have the current directory being explored
 *		as the head (so the src = list_head->next->path assignment
 *		is always safe).
 * fullpath:	The realpath of the current directory being explored.
 * dir_depth:	Passed to process_entry.
 * ------------------------------------------------------------------
 */
int explore_dir(params *P, visited_dir *list_head, char *nextpath, 
		int dir_depth)
{
	DIR *d;
	struct dirent *entry;
	struct dirent **done;
	int len;
	
	if ( (d = opendir(nextpath)) == 0)
	{
		return print_file_error(P, errno, nextpath);
	}
	
	if (((P->max_dir_depth) - dir_depth) > read_stat(P, t_ddepth))
		update_stat(P, t_ddepth, ((P->max_dir_depth) - dir_depth));
	
	len = offsetof(struct dirent, d_name) + 
		pathconf(nextpath, _PC_NAME_MAX) + 1;
	if ((entry = malloc(len)) == NULL || 
			(done = malloc(sizeof(struct dirent*))) == NULL)
	{
		fprintf(stderr, "Malloc failed in explore_dir.\n");
		return -1;
	}
	done = &entry;

	while ( (readdir_r(d, entry, done)) == 0 && (*done != NULL))
	{
		/* don't process '.' or '..' in a directory! */
		if ( (strcmp(entry->d_name, THIS_DIR) == 0) 
			|| (strcmp(entry->d_name, PARENT_DIR) == 0))
			continue;

		/* do all files but ones beginning with a dot,
		 * unless we've enabled it! */
		if (entry->d_name[0] == '.')
		{
			if (enabled(P, READ_DOT_FILES))
			{
				process_entry(P, list_head, entry->d_name,
					nextpath, dir_depth, 0);
			}
			else
				inc_stat(P, t_dotfiles, 1);
		}
		else
			process_entry(P, list_head, entry->d_name, nextpath,
				dir_depth, 0);
	}
	closedir(d);
	wait_for_children(list_head);
	free(nextpath);
	return 0;	
}
Ejemplo n.º 28
0
void hp_init_rpm_statistics(struct hp_block *hpb)
{
#ifdef DBG_MALLOC
	/* reset stats updated by mallocs before this init */
	rpm_used->flags &= ~STAT_NO_RESET;
	rpm_rused->flags &= ~STAT_NO_RESET;
	rpm_frags->flags &= ~STAT_NO_RESET;
	reset_stat(rpm_used);
	reset_stat(rpm_rused);
	reset_stat(rpm_frags);
	rpm_used->flags |= STAT_NO_RESET;
	rpm_rused->flags |= STAT_NO_RESET;
	rpm_frags->flags |= STAT_NO_RESET;
#endif
	update_stat(rpm_used, hpb->used);
	update_stat(rpm_rused, hpb->real_used);
	update_stat(rpm_frags, hpb->total_fragments);

	LM_DBG("initializing atomic rpm statistics: "
	       "[ us: %ld | rus: %ld | frags: %ld ]\n", hpb->used, hpb->real_used, hpb->total_fragments);
}
Ejemplo n.º 29
0
int mem_insert_pcontact(struct udomain* _d, str* _contact, struct pcontact_info* _ci, struct pcontact** _c){
	int sl;

	if (new_pcontact(_d->name, _contact, _ci, _c) < 0) {
		LM_ERR("creating pcontact failed\n");
		return -1;
	}

	sl = ((*_c)->aorhash) & (_d->size - 1);
	slot_add(&_d->table[sl], *_c);
	update_stat(_d->contacts, 1);
	return 0;
}
Ejemplo n.º 30
0
static unsigned int update_balloon_stats(struct virtio_balloon *vb)
{
	unsigned long events[NR_VM_EVENT_ITEMS];
	struct sysinfo i;
	unsigned int idx = 0;
	long available;
	unsigned long caches;

	all_vm_events(events);
	si_meminfo(&i);

	available = si_mem_available();
	caches = global_node_page_state(NR_FILE_PAGES);

#ifdef CONFIG_VM_EVENT_COUNTERS
	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
				pages_to_bytes(events[PSWPIN]));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
				pages_to_bytes(events[PSWPOUT]));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]);
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]);
#ifdef CONFIG_HUGETLB_PAGE
	update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGALLOC,
		    events[HTLB_BUDDY_PGALLOC]);
	update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGFAIL,
		    events[HTLB_BUDDY_PGALLOC_FAIL]);
#endif
#endif
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE,
				pages_to_bytes(i.freeram));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,
				pages_to_bytes(i.totalram));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
				pages_to_bytes(available));
	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHES,
				pages_to_bytes(caches));

	return idx;
}