Skip to content

Commit 3cc40af

Browse files
committed
Use _PyTime_AsSecondsDouble
1 parent f0aae45 commit 3cc40af

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Modules/_lsprof.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,15 @@ typedef struct {
491491
double factor;
492492
} statscollector_t;
493493

494+
static double
495+
scale_to_sec(statscollector_t *collect, long long t)
496+
{
497+
if (collect->factor == 0.0) {
498+
return _PyTime_AsSecondsDouble((_PyTime_t)t);
499+
}
500+
return t * collect->factor;
501+
}
502+
494503
static int statsForSubEntry(rotating_node_t *node, void *arg)
495504
{
496505
ProfilerSubEntry *sentry = (ProfilerSubEntry*) node;
@@ -503,8 +512,8 @@ static int statsForSubEntry(rotating_node_t *node, void *arg)
503512
entry->userObj,
504513
sentry->callcount,
505514
sentry->recursivecallcount,
506-
collect->factor * sentry->tt,
507-
collect->factor * sentry->it);
515+
scale_to_sec(collect, sentry->tt),
516+
scale_to_sec(collect, sentry->it));
508517
if (sinfo == NULL)
509518
return -1;
510519
err = PyList_Append(collect->sublist, sinfo);
@@ -541,8 +550,8 @@ static int statsForEntry(rotating_node_t *node, void *arg)
541550
entry->userObj,
542551
entry->callcount,
543552
entry->recursivecallcount,
544-
collect->factor * entry->tt,
545-
collect->factor * entry->it,
553+
scale_to_sec(collect, entry->tt),
554+
scale_to_sec(collect, entry->it),
546555
collect->sublist);
547556
Py_DECREF(collect->sublist);
548557
if (info == NULL)
@@ -583,7 +592,7 @@ profiler_getstats(ProfilerObject *pObj, PyObject* noarg)
583592
if (pending_exception(pObj))
584593
return NULL;
585594
if (!pObj->externalTimer)
586-
collect.factor = 1e-9; // _Py_time_t is nanosecond
595+
collect.factor = 0.0;
587596
else if (pObj->externalTimerUnit > 0.0)
588597
collect.factor = pObj->externalTimerUnit;
589598
else

0 commit comments

Comments
 (0)