12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "stats.h"
-
- static pyfcgi_stats_t pyfcgi_stats;
-
- int pyfcgi_stats_init()
- {
- struct sigaction act;
- struct itimerspec timeout;
-
- memset(&pyfcgi_stats, 0, sizeof(pyfcgi_stats_t));
-
- if(timer_create(CLOCK_REALTIME, NULL, &(pyfcgi_stats.timerid)) < 0)
- {
- pyfcgi_log(LOG_ERR,
- "Unable to create timer for stats collecting : %s",
- strerror(errno));
- goto err;
- }
-
- act.sa_handler = pyfcgi_stats_collector;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- act.sa_restorer = NULL;
- if(sigaction(SIGALRM, &act, &(pyfcgi_stats.oldact)) < 0)
- {
- pyfcgi_log(LOG_ERR,
- "Unable to register signal handler for stats collecting : %s",
- strerror(errno));
- goto err_deltimer;
- }
-
- timeout.it_value.tv_sec = 1;
- timeout.it_value.tv_nsec = 0;
- timeout.it_interval = timeout.it_value;
- if(timer_settime(pyfcgi_stats.timerid, 0, &timeout, NULL) < 0)
- {
- pyfcgi_log(LOG_ERR,
- "Unable to start timer for stats collecting : %s",
- strerror(errno));
- goto err_sigrestore;
- }
- return 0;
-
- err_sigrestore:
- sigaction(SIGALRM, &(pyfcgi_stats.oldact), NULL);
- err_deltimer:
- timer_delete(pyfcgi_stats.timerid);
- err:
- memset(&pyfcgi_stats, 0, sizeof(pyfcgi_stats_t));
- return -1;
- }
-
- void pyfcgi_stats_collector(int signum)
- {
- int ret;
- pyfcgi_stats_t *stats;
-
- stats = &pyfcgi_stats;
-
- stats->reqs[stats->cur_req] = 0;
- while( !(ret = sem_trywait(PyFCGI_SEM(SEM_WREQS).sem)) )
- {
- stats->reqs[stats->cur_req]++;
- }
- pyfcgi_log(LOG_DEBUG, "%d req/s", stats->reqs[stats->cur_req]);
- stats->cur_req++;
-
- return;
- }
|