#include "util.h"
static PyMethodDef pakfireModuleMethods[] = {
+ {"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL},
{"version_compare", (PyCFunction)version_compare, METH_VARARGS, NULL},
{"get_capabilities", (PyCFunction)get_capabilities, METH_VARARGS, NULL},
{"set_capabilities", (PyCFunction)set_capabilities, METH_VARARGS, NULL},
#include <errno.h>
#include <sched.h>
#include <sys/personality.h>
+#include <time.h>
#include <unistd.h>
#include "constants.h"
return Py_BuildValue("i", ret);
}
+
+static unsigned int fibonnacci(const clock_t* deadline) {
+ clock_t now = clock();
+
+ unsigned long f1 = 1;
+ unsigned long f2 = 1;
+
+ // Count iterations
+ unsigned int counter = 0;
+
+ while (now < *deadline) {
+ unsigned long next = f1 + f2;
+ f1 = f2;
+ f2 = next;
+
+ now = clock();
+ counter++;
+ }
+
+ return counter;
+}
+
+PyObject* performance_index(PyObject* self, PyObject* args) {
+ int seconds = 1;
+
+ if (!PyArg_ParseTuple(args, "|i", &seconds)) {
+ return NULL;
+ }
+
+ if (seconds == 0) {
+ PyErr_SetString(PyExc_ValueError, "Runtime must be one second or longer");
+ return NULL;
+ }
+
+ // Determine the number of online processors
+ int processors = sysconf(_SC_NPROCESSORS_ONLN);
+
+ // Determine deadline
+ clock_t deadline = clock();
+ deadline += CLOCKS_PER_SEC * seconds;
+
+ // Run Fibonnacci until deadline
+ unsigned int iterations = fibonnacci(&deadline);
+
+ // Times the result by the number of processors
+ iterations *= processors;
+
+ // Normalise to a second
+ iterations /= seconds;
+
+ return PyLong_FromUnsignedLong(iterations);
+}
extern PyObject *_sync(PyObject *self, PyObject *args);
extern PyObject *_unshare(PyObject *self, PyObject *args);
extern PyObject *version_compare(PyObject *self, PyObject *args);
+extern PyObject* performance_index(PyObject* self, PyObject* args);
#endif
import distro
import shell
+from . import _pakfire
+
from i18n import _
class System(object):
return ret or _("Could not be determined")
@property
- def cpu_bogomips(self):
- cpuinfo = self.parse_cpuinfo()
-
- for key in ("bogomips", "BogoMIPS"):
- bogomips = cpuinfo.get(key, None)
-
- if bogomips is None:
- continue
-
- return float(bogomips) * self.cpu_count
+ def cpu_bogomips(self):
+ return _pakfire.performance_index()
def get_loadavg(self):
return os.getloadavg()