A
Galatée a dit:
/*
* py_cpu.c
* cpu.so
*
* Created by plumber on 10/02/06.
* Copyright 2006 OpenSpecies. All rights reserved.
*
*/
#include <Python.h>
#include <py_cpu.h>
static PyObject *
Py_processor_number(PyObject *self)
{
unsigned int num_proc = processor_number();
return Py_BuildValue("i",num_proc);
}
static PyObject *
Py_processor_clock_speed(PyObject *self)
{
unsigned long proc_speed = processor_clock_speed();
return Py_BuildValue("l",proc_speed);
}
static PyObject *
Py_processor_clock_speedMHz(PyObject *self)
{
unsigned long proc_speed = processor_clock_speedMHz();
return Py_BuildValue("l",proc_speed);
}
static PyObject *
Py_processor_info(PyObject *self)
{
unsigned long proc_speed = processor_clock_speedMHz();
unsigned long bus_speed = processor_bus_speedMHz();
unsigned long proc_cache_size = processor_cache_linesize();
unsigned long RAMsize = RAM_sizeMB();
/*
char speed_str[200];
sprintf(speed_str,\
"bus frequence : %d MHz\ncore frequence : %i MHz\nmemory : %i MB\nL1 cache : %i",\
bus_speed,proc_speed,RAMsize,proc_cache_size);
return Py_BuildValue("s",speed_str);
*/
return Py_BuildValue("{s:i,s:i,s:i,s:i}",\
"CORE",proc_speed,\
"BUS",bus_speed,\
"L1",proc_cache_size,\
"RAM",RAMsize\
);
}
static PyObject *
Py_is_i386(PyObject *self)
{
unsigned int _is_i386 = is_i386();
if(_is_i386 == 1)
return Py_True;
return Py_False;
}
static PyObject *
Py_is_ppc(PyObject *self)
{
unsigned int _is_ppc = is_ppc();
if(_is_ppc == 1)
return Py_True;
return Py_False;
}
static PyObject *
Py_is_ppc64(PyObject *self)
{
unsigned int _is_ppc_64 = is_ppc64();
if(_is_ppc_64 == 1)
return Py_True;
return Py_False;
}
static PyObject *
Py_is_ppcG3(PyObject *self)
{
unsigned int _is_ppc_g3 = is_ppcG3();
if(_is_ppc_g3 == 1)
return Py_True;
return Py_False;
}
static PyObject *
Py_is_ppcG4(PyObject *self)
{
unsigned int _is_ppc_g4 = is_ppcG4();
if(_is_ppc_g4 == 1)
return Py_True;
return Py_False;
}
static PyObject *
Py_is_ppcG5(PyObject *self)
{
unsigned int _is_ppc_g5 = is_ppcG5();
if(_is_ppc_g5 == 1)
return Py_True;
return Py_False;
}
static struct PyMethodDef py_cpu_methods[] = {
{"proc_number",Py_processor_number,1},
{"proc_speed",Py_processor_clock_speed,1},
{"proc_speedMHz",Py_processor_clock_speedMHz,1},
{"proc_info",Py_processor_info,1},
{"is_i386",Py_is_i386,1},
{"is_ppc",Py_is_ppc,1},
{"is_ppc64",Py_is_ppc64,1},
{"is_ppcG3",Py_is_ppcG3,1},
{"is_ppcG4",Py_is_ppcG4,1},
{"is_ppcG5",Py_is_ppcG5,1},
{NULL,NULL}
};
void initcpu()
{
(void) Py_InitModule("cpu",py_cpu_methods);
}
canto il faut qu'il arrete je sais pas quoi mais faut qu'il arrete l'anglais en tout les casstook a dit: