summaryrefslogtreecommitdiff
path: root/cdr/cdr_sqlite.c
diff options
context:
space:
mode:
authorBradley Latus <brad.latus@gmail.com>2010-06-08 23:48:17 +0000
committerBradley Latus <brad.latus@gmail.com>2010-06-08 23:48:17 +0000
commit4405813297fa41d441ab2cb28387df09b90aea68 (patch)
treeb9c0a6d9e565124104804ec2cb1e31a3c6b5ea41 /cdr/cdr_sqlite.c
parent3c26b511e03ac9dde860787f2cf3cf2ad06df495 (diff)
Add High Resolution Times to CDRs for Asterisk
People expressed an interest in having access to the exact length of calls to a finer degree than seconds. See the CHANGES and UPGRADE.txt for usage also updated the sample configs to note the change. Patch by snuffy. (closes issue #16559) Reported by: cianmaher Tested by: cianmaher, snuffy Review: https://reviewboard.asterisk.org/r/461/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@269153 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'cdr/cdr_sqlite.c')
-rw-r--r--cdr/cdr_sqlite.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/cdr/cdr_sqlite.c b/cdr/cdr_sqlite.c
index 5a3a4b2ba..d871e8a8a 100644
--- a/cdr/cdr_sqlite.c
+++ b/cdr/cdr_sqlite.c
@@ -49,8 +49,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/utils.h"
#include "asterisk/paths.h"
-#define LOG_UNIQUEID 0
-#define LOG_USERFIELD 0
+#define LOG_UNIQUEID 0
+#define LOG_USERFIELD 0
+#define LOG_HRTIME 0
/* When you change the DATE_FORMAT, be sure to change the CHAR(19) below to something else */
#define DATE_FORMAT "%Y-%m-%d %T"
@@ -74,8 +75,13 @@ static const char sql_create_table[] = "CREATE TABLE cdr ("
" start CHAR(19),"
" answer CHAR(19),"
" end CHAR(19),"
+#if LOG_HRTIME
+" duration FLOAT,"
+" billsec FLOAT,"
+#else
" duration INTEGER,"
" billsec INTEGER,"
+#endif
" disposition INTEGER,"
" amaflags INTEGER,"
" accountcode VARCHAR(20)"
@@ -101,6 +107,10 @@ static int sqlite_log(struct ast_cdr *cdr)
char *zErr = 0;
char startstr[80], answerstr[80], endstr[80];
int count;
+#if LOG_HRTIME
+ double hrbillsec = 0.0;
+ double hrduration;
+#endif
ast_mutex_lock(&sqlite_lock);
@@ -108,6 +118,13 @@ static int sqlite_log(struct ast_cdr *cdr)
format_date(answerstr, sizeof(answerstr), &cdr->answer);
format_date(endstr, sizeof(endstr), &cdr->end);
+#if LOG_HRTIME
+ if (!ast_tvzero(cdr->answer)) {
+ hrbillsec = (double) ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0;
+ }
+ hrduration = (double) ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0;
+#endif
+
for(count=0; count<5; count++) {
res = sqlite_exec_printf(db,
"INSERT INTO cdr ("
@@ -126,7 +143,11 @@ static int sqlite_log(struct ast_cdr *cdr)
"'%q', '%q', '%q', '%q', "
"'%q', '%q', '%q', '%q', "
"'%q', '%q', '%q', "
+#if LOG_HRTIME
+ "%f, %f, %d, %d, "
+#else
"%d, %d, %d, %d, "
+#endif
"'%q'"
# if LOG_UNIQUEID
",'%q'"
@@ -138,7 +159,11 @@ static int sqlite_log(struct ast_cdr *cdr)
cdr->clid, cdr->src, cdr->dst, cdr->dcontext,
cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata,
startstr, answerstr, endstr,
+#if LOG_HRTIME
+ hrduration, hrbillsec, cdr->disposition, cdr->amaflags,
+#else
cdr->duration, cdr->billsec, cdr->disposition, cdr->amaflags,
+#endif
cdr->accountcode
# if LOG_UNIQUEID
,cdr->uniqueid