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
This commit is contained in:
Bradley Latus
2010-06-08 23:48:17 +00:00
parent 3c26b511e0
commit 4405813297
14 changed files with 258 additions and 12 deletions

View File

@@ -87,6 +87,7 @@ struct cdr_tds_config {
AST_STRING_FIELD(table);
AST_STRING_FIELD(charset);
AST_STRING_FIELD(language);
AST_STRING_FIELD(hrtime);
);
DBPROCESS *dbproc;
unsigned int connected:1;
@@ -149,7 +150,36 @@ retry:
}
if (settings->has_userfield) {
erc = dbfcmd(settings->dbproc,
if (settings->hrtime) {
double hrbillsec = 0.0;
double hrduration;
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);
erc = dbfcmd(settings->dbproc,
"INSERT INTO %s "
"("
"accountcode, src, dst, dcontext, clid, channel, "
"dstchannel, lastapp, lastdata, start, answer, [end], duration, "
"billsec, disposition, amaflags, uniqueid, userfield"
") "
"VALUES "
"("
"'%s', '%s', '%s', '%s', '%s', '%s', "
"'%s', '%s', '%s', %s, %s, %s, %lf, "
"%lf, '%s', '%s', '%s', '%s'"
")",
settings->table,
accountcode, src, dst, dcontext, clid, channel,
dstchannel, lastapp, lastdata, start, answer, end, hrduration,
hrbillsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid,
userfield
);
} else {
erc = dbfcmd(settings->dbproc,
"INSERT INTO %s "
"("
"accountcode, src, dst, dcontext, clid, channel, "
@@ -168,8 +198,37 @@ retry:
cdr->billsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid,
userfield
);
}
} else {
erc = dbfcmd(settings->dbproc,
if (settings->hrtime) {
double hrbillsec = 0.0;
double hrduration;
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);
erc = dbfcmd(settings->dbproc,
"INSERT INTO %s "
"("
"accountcode, src, dst, dcontext, clid, channel, "
"dstchannel, lastapp, lastdata, start, answer, [end], duration, "
"billsec, disposition, amaflags, uniqueid"
") "
"VALUES "
"("
"'%s', '%s', '%s', '%s', '%s', '%s', "
"'%s', '%s', '%s', %s, %s, %s, %lf, "
"%lf, '%s', '%s', '%s'"
")",
settings->table,
accountcode, src, dst, dcontext, clid, channel,
dstchannel, lastapp, lastdata, start, answer, end, hrduration,
hrbillsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid
);
} else {
erc = dbfcmd(settings->dbproc,
"INSERT INTO %s "
"("
"accountcode, src, dst, dcontext, clid, channel, "
@@ -187,6 +246,7 @@ retry:
dstchannel, lastapp, lastdata, start, answer, end, cdr->duration,
cdr->billsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid
);
}
}
if (erc == FAIL) {
@@ -502,6 +562,13 @@ static int tds_load_module(int reload)
ast_string_field_set(settings, table, "cdr");
}
ptr = ast_variable_retrieve(cfg, "global", "hrtime");
if (ptr && ast_true(ptr)) {
ast_string_field_set(settings, hrtime, ptr);
} else {
ast_log(LOG_NOTICE, "High Resolution Time not found, using integers for billsec and duration fields by default.\n");
}
mssql_disconnect();
if (mssql_connect()) {