Exemplo n.º 1
0
static PyObject*
perf_counter(_Py_clock_info_t *info)
{
#if defined(WIN32_PERF_COUNTER) || defined(PYMONOTONIC)
    PyObject *res;
#endif
#if defined(WIN32_PERF_COUNTER)
    static int use_perf_counter = 1;
#endif
#ifdef PYMONOTONIC
    static int use_monotonic = 1;
#endif

#ifdef WIN32_PERF_COUNTER
    if (use_perf_counter) {
        if (win_perf_counter(info, &res) == 0)
            return res;
        use_perf_counter = 0;
    }
#endif

#ifdef PYMONOTONIC
    if (use_monotonic) {
        res = pymonotonic(info);
        if (res != NULL)
            return res;
        use_monotonic = 0;
        PyErr_Clear();
    }
#endif

    return floattime(info);
}
Exemplo n.º 2
0
static PyObject *
time_localtime(PyObject *self, PyObject *args)
{
	double when;
	if (PyTuple_Size(args) == 0)
		when = floattime();
	if (!PyArg_ParseTuple(args, "|d:localtime", &when))
		return NULL;
	return time_convert((time_t)when, localtime);
}
Exemplo n.º 3
0
static PyObject *
time_time(PyObject *self, PyObject *unused)
{
	double secs;
	secs = floattime();
	if (secs == 0.0) {
		PyErr_SetFromErrno(PyExc_IOError);
		return NULL;
	}
	return PyFloat_FromDouble(secs);
}
Exemplo n.º 4
0
double clock_now()
{
#ifdef WIN32
    return floattime();
#else
    struct timeval now;

    gettimeofday(&now, NULL);
    return tv2float(&now);
#endif
}
Exemplo n.º 5
0
static PyObject *
time_time(PyObject *self, PyObject *args)
{
	double secs;
	if (!PyArg_ParseTuple(args, ":time"))
		return NULL;
	secs = floattime();
	if (secs == 0.0) {
		PyErr_SetFromErrno(PyExc_IOError);
		return NULL;
	}
	return PyFloat_FromDouble(secs);
}
Exemplo n.º 6
0
void handle_trace(PyFrameObject *frame, Record__RecordType record_type, int n_arguments)
{
  static int count = 0;
  count++;
  record->type = record_type;
  record->n_arguments = n_arguments;
  record->time = floattime();
  record->tid = (long) pthread_self();
  record->depth = get_depth();
  set_string(&(record->module), PYSTR_TO_CHAR(frame->f_code->co_filename));
  set_string(&(record->function), PYSTR_TO_CHAR(frame->f_code->co_name));
  record->lineno = frame->f_code->co_firstlineno;
  record__pack(record, record_buf);
  ring_write(global_ring, record_buf, (unsigned long) record__get_packed_size(record));
  CLEAR_REFS();
}
Exemplo n.º 7
0
/* Parse arg tuple that can contain an optional float-or-None value;
   format needs to be "|O:name".
   Returns non-zero on success (parallels PyArg_ParseTuple).
*/
static int
parse_time_double_args(PyObject *args, char *format, double *pwhen)
{
	PyObject *ot = NULL;

	if (!PyArg_ParseTuple(args, format, &ot))
		return 0;
	if (ot == NULL || ot == Py_None)
		*pwhen = floattime();
	else {
		double when = PyFloat_AsDouble(ot);
		if (PyErr_Occurred())
			return 0;
		*pwhen = when;
	}
	return 1;
}
Exemplo n.º 8
0
static PyObject *
time_time(PyObject *self, PyObject *unused)
{
    return floattime(NULL);
}
Exemplo n.º 9
0
static PyObject *
speedstack_update(PyObject *self, PyObject *args)
{
	speedstack_item *si;
	long current; unsigned short int force; void *sspyco;
	PyArg_ParseTuple(args, "OlH", &sspyco, &current, &force);
	speedstack *ss = (speedstack *) PyCObject_AsVoidPtr(sspyco);
	
	double now = floattime();

	if (ss->stacklen == 0) {
		si = malloc(sizeof(speedstack_item));
		si->ft = now;
		si->next = NULL;
		si->diff = 0;
		ss->stack_head = ss->stack_tail = si;
		ss->stacklen++;
		ss->current = ss->speedlimit_lastcurrent = current;
		ss->speedlimit_lastupdate = now;
		return Py_BuildValue("");
	}


	// perform delay
	if (ss->speedlimit) {
		double timediff = now - ss->speedlimit_lastupdate;
		double bytediff = (double) (current - ss->speedlimit_lastcurrent);
		double delay = (bytediff / ss->speedlimit) - timediff;
		if (0.0 < delay) {
			t.tv_sec = (long) floor(delay);
			t.tv_usec = (long) (fmod(delay, 1.0)*1000000.0);
			select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
		}
		now = floattime();
	}



	
	if ( (now - ss->stack_tail->ft) < ss->updateinterval && !force)
		return Py_BuildValue("");


	si = malloc(sizeof(speedstack_item));
	si->ft = now;
	si->next = NULL;
	si->diff = current - ss->current;
	ss->current = current;
	ss->stack_tail = ss->stack_tail->next = si;
	ss->stacklen++;
	
	if (ss->stacklen > 100 || 2.0 < ss->stack_tail->ft - ss->stack_head->ft) {
		si = ss->stack_head;
		ss->stack_head = si->next;
		free(si);
		ss->stacklen--;
	}

	// calculate the speed
	double speed = 0.0;
	si = ss->stack_head;
	while (si->next) {
		speed += si->next->diff;
		si = si->next;
	}
	speed /= (ss->stack_tail->ft - ss->stack_head->ft);
	

	return PyFloat_FromDouble(speed);
}