MCPcopy Create free account
hub / github.com/SIPp/sipp / time_string

Function time_string

src/scenario.cpp:520–551  ·  view source on GitHub ↗

Pretty print a time. */

Source from the content-addressed store, hash-verified

518
519/* Pretty print a time. */
520int time_string(double ms, char *res, int reslen)
521{
522 if (ms < 10000) {
523 /* Less then 10 seconds we represent accurately. */
524 if ((int)(ms + 0.9999) == (int)(ms)) {
525 /* We have an integer, or close enough to it. */
526 return snprintf(res, reslen, "%dms", (int)ms);
527 } else {
528 if (ms < 1000) {
529 return snprintf(res, reslen, "%.2lfms", ms);
530 } else {
531 return snprintf(res, reslen, "%.1lfms", ms);
532 }
533 }
534 } else if (ms < 60000) {
535 /* We round to 100ms for times less than a minute. */
536 return snprintf(res, reslen, "%.1fs", ms/1000);
537 } else if (ms < 60 * 60000) {
538 /* We round to 1s for times more than a minute. */
539 int s = (unsigned int)(ms / 1000);
540 int m = s / 60;
541 s %= 60;
542 return snprintf(res, reslen, "%d:%02d", m, s);
543 } else {
544 int s = (unsigned int)(ms / 1000);
545 int m = s / 60;
546 int h = m / 60;
547 s %= 60;
548 m %= 60;
549 return snprintf(res, reslen, "%d:%02d:%02d", h, m, s);
550 }
551}
552
553/* For backwards compatibility, we assign "true" to slot 1, false to 0, and
554 * allow other valid integers. */

Callers 2

timeDescrMethod · 0.85
scenarioMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected