mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
separate statistics gathering from the scheduler structure
This commit is contained in:
parent
52e4b416c9
commit
e705696896
29
fdqueue.c
29
fdqueue.c
@ -34,12 +34,16 @@ void list_alarms(){
|
||||
|
||||
INFO("Alarms;");
|
||||
while(alarm){
|
||||
INFOF("%s in %lldms", alarm->stats.name, alarm->alarm - now);
|
||||
INFOF("%s in %lldms",
|
||||
(alarm->stats?alarm->stats->name:"Unnamed"),
|
||||
alarm->alarm - now);
|
||||
alarm = alarm->_next;
|
||||
}
|
||||
INFO("File handles;");
|
||||
for (i=0;i<fdcount;i++)
|
||||
INFOF("%s watching #%d", fd_callbacks[i]->stats.name, fds[i].fd);
|
||||
INFOF("%s watching #%d",
|
||||
(fd_callbacks[i]->stats?fd_callbacks[i]->stats->name:"Unnamed"),
|
||||
fds[i].fd);
|
||||
}
|
||||
|
||||
// add an alarm to the list of scheduled function calls.
|
||||
@ -72,12 +76,15 @@ int schedule(struct sched_ent *alarm){
|
||||
int unschedule(struct sched_ent *alarm){
|
||||
struct sched_ent *prev = alarm->_prev;
|
||||
struct sched_ent *next = alarm->_next;
|
||||
if (prev!=NULL)
|
||||
|
||||
if (prev)
|
||||
prev->_next = next;
|
||||
else if(next_alarm==alarm)
|
||||
next_alarm = next;
|
||||
if (next!=NULL)
|
||||
|
||||
if (next)
|
||||
next->_prev = prev;
|
||||
|
||||
alarm->_prev = NULL;
|
||||
alarm->_next = NULL;
|
||||
return 0;
|
||||
@ -87,9 +94,9 @@ int unschedule(struct sched_ent *alarm){
|
||||
int watch(struct sched_ent *alarm){
|
||||
if (alarm->_poll_index>=0 && fd_callbacks[alarm->_poll_index]==alarm){
|
||||
// updating event flags
|
||||
INFOF("Updating watch %s, #%d for %d", alarm->stats.name, alarm->poll.fd, alarm->poll.events);
|
||||
INFOF("Updating watch %s, #%d for %d", (alarm->stats?alarm->stats->name:"Unnamed"), alarm->poll.fd, alarm->poll.events);
|
||||
}else{
|
||||
INFOF("Adding watch %s, #%d for %d", alarm->stats.name, alarm->poll.fd, alarm->poll.events);
|
||||
INFOF("Adding watch %s, #%d for %d", (alarm->stats?alarm->stats->name:"Unnamed"), alarm->poll.fd, alarm->poll.events);
|
||||
if (fdcount>=MAX_WATCHED_FDS)
|
||||
return WHY("Too many file handles to watch");
|
||||
fd_callbacks[fdcount]=alarm;
|
||||
@ -116,18 +123,22 @@ int unwatch(struct sched_ent *alarm){
|
||||
fds[fdcount].fd=-1;
|
||||
fd_callbacks[fdcount]=NULL;
|
||||
alarm->_poll_index=-1;
|
||||
INFOF("%s stopped watching #%d for %d", alarm->stats.name, alarm->poll.fd, alarm->poll.events);
|
||||
INFOF("%s stopped watching #%d for %d", (alarm->stats?alarm->stats->name:"Unnamed"), alarm->poll.fd, alarm->poll.events);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void call_alarm(struct sched_ent *alarm, int revents){
|
||||
struct call_stats call_stats;
|
||||
fd_func_enter(&call_stats);
|
||||
struct callback_stats *stats = alarm->stats;
|
||||
|
||||
if (stats)
|
||||
fd_func_enter(&call_stats);
|
||||
|
||||
alarm->poll.revents = revents;
|
||||
alarm->function(alarm);
|
||||
|
||||
fd_func_exit(&call_stats, &alarm->stats);
|
||||
if (stats)
|
||||
fd_func_exit(&call_stats, stats);
|
||||
}
|
||||
|
||||
int fd_checkalarms()
|
||||
|
@ -61,6 +61,9 @@ int monitor_process_data(struct monitor_context *c);
|
||||
static void monitor_new_client(int s);
|
||||
|
||||
struct sched_ent named_socket;
|
||||
struct callback_stats named_stats;
|
||||
struct callback_stats client_stats;
|
||||
|
||||
int monitor_setup_sockets()
|
||||
{
|
||||
struct sockaddr_un name;
|
||||
@ -117,7 +120,8 @@ int monitor_setup_sockets()
|
||||
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) WHY("Monitor server socket setup");
|
||||
|
||||
named_socket.function=monitor_poll;
|
||||
named_socket.stats.name="monitor_poll";
|
||||
named_stats.name="monitor_poll";
|
||||
named_socket.stats=&named_stats;
|
||||
named_socket.poll.fd=sock;
|
||||
named_socket.poll.events=POLLIN;
|
||||
watch(&named_socket);
|
||||
@ -318,7 +322,8 @@ static void monitor_new_client(int s) {
|
||||
|
||||
c = &monitor_sockets[monitor_socket_count++];
|
||||
c->alarm.function = monitor_client_poll;
|
||||
c->alarm.stats.name="monitor_client_poll";
|
||||
client_stats.name = "monitor_client_poll";
|
||||
c->alarm.stats=&client_stats;
|
||||
c->alarm.poll.fd = s;
|
||||
c->alarm.poll.events=POLLIN;
|
||||
c->line_length = 0;
|
||||
|
10
overlay.c
10
overlay.c
@ -112,7 +112,15 @@ int overlayServerMode()
|
||||
/* Create structures to use 1MB of RAM for testing */
|
||||
overlay_route_init(1);
|
||||
|
||||
#define SCHEDULE(X, Y) struct sched_ent _sched_##X; bzero(&_sched_##X, sizeof(struct sched_ent)); _sched_##X.function=X;_sched_##X.stats.name="" #X "";_sched_##X.alarm=overlay_gettime_ms()+Y; schedule(&_sched_##X);
|
||||
#define SCHEDULE(X, Y) \
|
||||
struct sched_ent _sched_##X; \
|
||||
struct callback_stats _stats_##X; \
|
||||
bzero(&_sched_##X, sizeof(struct sched_ent)); \
|
||||
_sched_##X.stats = &_stats_##X; \
|
||||
_sched_##X.function=X;\
|
||||
_stats_##X.name="" #X "";\
|
||||
_sched_##X.alarm=overlay_gettime_ms()+Y;\
|
||||
schedule(&_sched_##X);
|
||||
|
||||
/* Periodically check for server shut down */
|
||||
SCHEDULE(server_shutdown_check, 0);
|
||||
|
@ -41,6 +41,9 @@ struct interface_rules {
|
||||
|
||||
struct interface_rules *interface_filter=NULL;
|
||||
|
||||
struct callback_stats interface_poll_stats;
|
||||
struct callback_stats dummy_poll_stats;
|
||||
|
||||
unsigned int overlay_sequence_number=0;
|
||||
|
||||
long long overlay_next_tick();
|
||||
@ -234,7 +237,9 @@ overlay_interface_init_socket(int interface, struct sockaddr_in src_addr, struct
|
||||
|
||||
I(alarm.poll.events)=POLLIN;
|
||||
I(alarm.function) = overlay_interface_poll;
|
||||
I(alarm.stats.name)="overlay_interface_poll";
|
||||
|
||||
interface_poll_stats.name="overlay_interface_poll";
|
||||
I(alarm.stats)=&interface_poll_stats;
|
||||
watch(&I(alarm));
|
||||
|
||||
return 0;
|
||||
@ -295,7 +300,8 @@ int overlay_interface_init(char *name,struct sockaddr_in src_addr,struct sockadd
|
||||
// schedule an alarm for this interface
|
||||
I(alarm.function)=overlay_dummy_poll;
|
||||
I(alarm.alarm)=overlay_gettime_ms()+10;
|
||||
I(alarm.stats.name)="overlay_dummy_poll";
|
||||
dummy_poll_stats.name="overlay_dummy_poll";
|
||||
I(alarm.stats)=&dummy_poll_stats;
|
||||
schedule(&I(alarm));
|
||||
} else {
|
||||
if (overlay_interface_init_socket(overlay_interface_count,src_addr,broadcast))
|
||||
|
@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
struct sched_ent mdp_abstract;
|
||||
struct sched_ent mdp_named;
|
||||
struct callback_stats mdp_stats;
|
||||
|
||||
int overlay_mdp_setup_sockets()
|
||||
{
|
||||
@ -112,7 +113,8 @@ int overlay_mdp_setup_sockets()
|
||||
WHY_perror("setsockopt");
|
||||
|
||||
mdp_named.function = overlay_mdp_poll;
|
||||
mdp_named.stats.name = "overlay_mdp_poll";
|
||||
mdp_stats.name="overlay_mdp_poll";
|
||||
mdp_named.stats = &mdp_stats;
|
||||
mdp_named.poll.events = POLLIN;
|
||||
watch(&mdp_named);
|
||||
}
|
||||
|
@ -191,17 +191,18 @@ int fd_func_exit(struct call_stats *this_call, struct callback_stats *aggregate_
|
||||
long long elapsed=now - this_call->enter_time;
|
||||
current_call = this_call->prev;
|
||||
|
||||
if (!aggregate_stats->_initialised){
|
||||
aggregate_stats->_initialised=1;
|
||||
aggregate_stats->_next = stats_head;
|
||||
fd_clearstat(aggregate_stats);
|
||||
stats_head = aggregate_stats;
|
||||
}
|
||||
|
||||
if (current_call)
|
||||
current_call->child_time+=elapsed;
|
||||
|
||||
fd_update_stats(aggregate_stats, (elapsed - this_call->child_time));
|
||||
|
||||
if (!aggregate_stats->_initialised){
|
||||
aggregate_stats->_initialised=1;
|
||||
aggregate_stats->_next = stats_head;
|
||||
stats_head = aggregate_stats;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,8 @@ typedef struct rhizome_file_fetch_record {
|
||||
|
||||
} rhizome_file_fetch_record;
|
||||
|
||||
struct callback_stats fetch_stats;
|
||||
|
||||
/* List of queued transfers */
|
||||
#define MAX_QUEUED_FILES 4
|
||||
int rhizome_file_fetch_queue_count=0;
|
||||
@ -684,9 +686,11 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Watch for activity on the socket */
|
||||
q->alarm.function=rhizome_fetch_poll;
|
||||
q->alarm.stats.name="rhizome_fetch_poll";
|
||||
fetch_stats.name="rhizome_fetch_poll";
|
||||
q->alarm.stats=&fetch_stats;
|
||||
q->alarm.poll.events=POLLIN|POLLOUT;
|
||||
watch(&q->alarm);
|
||||
/* And schedule a timeout alarm */
|
||||
|
@ -82,6 +82,10 @@ int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, c
|
||||
|
||||
#define RHIZOME_SERVER_MAX_LIVE_REQUESTS 32
|
||||
|
||||
struct sched_ent server_alarm;
|
||||
struct callback_stats server_stats;
|
||||
|
||||
struct callback_stats connection_stats;
|
||||
|
||||
/*
|
||||
HTTP server and client code for rhizome transfers.
|
||||
@ -115,7 +119,6 @@ unsigned char favicon_bytes[]={
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
int favicon_len=318;
|
||||
|
||||
struct sched_ent server_alarm;
|
||||
|
||||
int rhizome_server_start()
|
||||
{
|
||||
@ -170,7 +173,8 @@ int rhizome_server_start()
|
||||
|
||||
/* Add Rhizome HTTPd server to list of file descriptors to watch */
|
||||
server_alarm.function = rhizome_server_poll;
|
||||
server_alarm.stats.name="rhizome_server_poll";
|
||||
server_stats.name="rhizome_server_poll";
|
||||
server_alarm.stats=&server_stats;
|
||||
server_alarm.poll.fd = rhizome_server_socket;
|
||||
server_alarm.poll.events = POLLIN;
|
||||
watch(&server_alarm);
|
||||
@ -228,8 +232,6 @@ void rhizome_client_poll(struct sched_ent *alarm)
|
||||
/* We have the request. Now parse it to see if we can respond to it */
|
||||
rhizome_server_parse_http_request(r);
|
||||
}
|
||||
|
||||
r->request_length+=bytes;
|
||||
}
|
||||
|
||||
if (sigPipeFlag||((bytes==0)&&(errno==0))) {
|
||||
@ -263,7 +265,8 @@ void rhizome_server_poll(struct sched_ent *alarm)
|
||||
/* We are now trying to read the HTTP request */
|
||||
request->request_type=RHIZOME_HTTP_REQUEST_RECEIVING;
|
||||
request->alarm.function = rhizome_client_poll;
|
||||
request->alarm.stats.name="rhizome_client_poll";
|
||||
connection_stats.name="rhizome_client_poll";
|
||||
request->alarm.stats=&connection_stats;
|
||||
request->alarm.poll.fd=sock;
|
||||
request->alarm.poll.events=POLLIN;
|
||||
request->alarm.alarm = overlay_gettime_ms()+RHIZOME_IDLE_TIMEOUT;
|
||||
|
Loading…
x
Reference in New Issue
Block a user