User:MarkFinkle/ctypes
From MozillaWiki
let libc = ctypes.open("libc.so.6"); let timeval = ctypes.StructType('timeval', [{'tv_sec': ctypes.long}, {'tv_usec': ctypes.long}]); let rusage = ctypes.StructType('rusage', [{'ru_utime': timeval}, {'ru_stime': timeval}, {'ru_maxrss': ctypes.long}, {'ru_ixrss': ctypes.long}, {'ru_idrss': ctypes.long}, {'ru_isrss': ctypes.long}, {'ru_minflt': ctypes.long}, {'ru_majflt': ctypes.long}, {'ru_nswap': ctypes.long}, {'ru_inblock': ctypes.long}, {'ru_oublock': ctypes.long}, {'ru_msgsnd': ctypes.long}, {'ru_msgrcv': ctypes.long}, {'ru_nsignals': ctypes.long}, {'ru_nvcsw': ctypes.long}, {'ru_nivcsw': ctypes.long}]); let getrusage = libc.declare("getrusage", ctypes.default_abi, ctypes.int, ctypes.int, rusage.ptr); let usage = new rusage(); const RUSAGE_SELF = 0; getrusage(RUSAGE_SELF, usage.address()); LOG("utime: " + usage.ru_utime); LOG("stime: " + usage.ru_stime);