add query to buffer
| 54 | |
| 55 | // add query to buffer |
| 56 | void QueriesLog_AddQuery |
| 57 | ( |
| 58 | QueriesLog log, // queries log |
| 59 | uint64_t received, // query received timestamp |
| 60 | double wait_duration, // waiting time |
| 61 | double execution_duration, // executing time |
| 62 | double report_duration, // reporting time |
| 63 | bool parameterized, // uses parameters |
| 64 | bool utilized_cache, // utilized cache |
| 65 | bool write, // write query |
| 66 | bool timeout, // timeout query |
| 67 | const char *query // query string |
| 68 | ) { |
| 69 | // add query stats to buffer |
| 70 | // acquire READ lock, multiple threads can be populating the circular buffer |
| 71 | // simultaneously (the circular-buffer is lock-free) |
| 72 | |
| 73 | int res = pthread_rwlock_rdlock(&log->rwlock); |
| 74 | ASSERT(res == 0); |
| 75 | |
| 76 | // get a slot within log's buffer |
| 77 | void *slot = CircularBuffer_Reserve(log->queries); |
| 78 | |
| 79 | // dump query to slot |
| 80 | LoggedQuery *q = (LoggedQuery*)(slot); |
| 81 | |
| 82 | if(q->query != NULL) { |
| 83 | rm_free(q->query); |
| 84 | } |
| 85 | |
| 86 | q->received = received; |
| 87 | q->wait_duration = wait_duration; |
| 88 | q->execution_duration = execution_duration; |
| 89 | q->report_duration = report_duration; |
| 90 | q->parameterized = parameterized; |
| 91 | q->write = write; |
| 92 | q->timeout = timeout; |
| 93 | q->utilized_cache = utilized_cache; |
| 94 | q->query = rm_strdup(query); |
| 95 | |
| 96 | res = pthread_rwlock_unlock(&log->rwlock); |
| 97 | ASSERT(res == 0); |
| 98 | } |
| 99 | |
| 100 | // returns number of queries in log |
| 101 | uint64_t QueriesLog_GetQueriesCount |
no test coverage detected