Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <filter.h>
- #include <dbg.h>
- #include <sys/time.h>
- typedef struct ProfilerSession {
- struct timeval * profilerTimeStart;
- struct timeval * profilerTimeEnd;
- } ProfilerSession;
- ProfilerSession *session = NULL;
- StateEvent filter_transition(StateEvent state, Connection *conn, tns_value_t *config) {
- if (session == NULL) {
- session = (ProfilerSession *)malloc(sizeof(ProfilerSession));
- session->profilerTimeStart = malloc(sizeof(struct timeval));
- session->profilerTimeEnd = malloc(sizeof(struct timeval));
- }
- if (state == REQ_RECV) {
- debug("[Profiler:OPEN] Connection opened. Sampling time with gettimeofday.");
- int rc = gettimeofday(session->profilerTimeStart, NULL);
- check(rc == 0, "Something went REALLY wrong with Profiler filter");
- struct timeval startTime = *(session->profilerTimeStart);
- debug("[Profiler:OPEN] Start of request %ldms", startTime.tv_sec * 10000 + startTime.tv_usec);
- } else if (state == RESP_SENT) {
- gettimeofday(session->profilerTimeEnd, NULL);
- struct timeval endTime = *(session->profilerTimeEnd);
- debug("[Profiler:CLOSE] End of request at %ldms", endTime.tv_sec * 10000 + endTime.tv_usec);
- struct timeval startTime = *(session->profilerTimeStart);
- long int diff = (endTime.tv_sec * 10000 + endTime.tv_usec) - (startTime.tv_sec * 10000 + startTime.tv_usec);
- debug("[Profiler:CLOSE] Request took %ldms.", diff);
- }
- return state;
- error:
- return CLOSE;
- }
- StateEvent *filter_init(Server *srv, bstring load_path, int *out_nstates) {
- StateEvent states[] = {REQ_RECV, RESP_SENT};
- *out_nstates = Filter_states_length(states);
- check(*out_nstates == 2, "Wrong states array length.");
- debug("[Profiler:filter_init] initted filter with needed states:");
- size_t i;
- for (i = 0; i < *out_nstates; i++) {
- debug("[Profiler:filter_init] state: %d", states[i]);
- }
- return Filter_state_list(states, *out_nstates);
- error:
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement