Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e14679c7
Kaydet (Commit)
e14679c7
authored
Eki 05, 2017
tarafından
pdox
Kaydeden (comit)
Benjamin Peterson
Eki 05, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
closes bpo-31596: Add an interface for pthread_getcpuclockid(3) (#3756)
üst
55fd0660
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
0 deletions
+84
-0
time.rst
Doc/library/time.rst
+16
-0
test_time.py
Lib/test/test_time.py
+20
-0
2017-09-26-11-38-52.bpo-31596.50Eyel.rst
...S.d/next/Library/2017-09-26-11-38-52.bpo-31596.50Eyel.rst
+1
-0
timemodule.c
Modules/timemodule.c
+32
-0
configure
configure
+11
-0
configure.ac
configure.ac
+1
-0
pyconfig.h.in
pyconfig.h.in
+3
-0
No files found.
Doc/library/time.rst
Dosyayı görüntüle @
e14679c7
...
...
@@ -162,6 +162,22 @@ The module defines the following functions and data items:
:func:`perf_counter` or :func:`process_time` instead, depending on your
requirements, to have a well defined behaviour.
.. function:: pthread_getcpuclockid(thread_id)
Return the *clk_id* of the thread-specific CPU-time clock for the specified *thread_id*.
Use :func:`threading.get_ident` or the :attr:`~threading.Thread.ident`
attribute of :class:`threading.Thread` objects to get a suitable value
for *thread_id*.
.. warning::
Passing an invalid or expired *thread_id* may result in
undefined behavior, such as segmentation fault.
Availability: Unix (see the man page for :manpage:`pthread_getcpuclockid(3)` for
further information)
.. versionadded:: 3.7
.. function:: clock_getres(clk_id)
...
...
Lib/test/test_time.py
Dosyayı görüntüle @
e14679c7
...
...
@@ -7,6 +7,7 @@ import platform
import
sys
import
sysconfig
import
time
import
threading
import
unittest
try
:
import
_testcapi
...
...
@@ -80,6 +81,25 @@ class TimeTestCase(unittest.TestCase):
b
=
time
.
clock_gettime
(
time
.
CLOCK_MONOTONIC
)
self
.
assertLessEqual
(
a
,
b
)
@unittest.skipUnless
(
hasattr
(
time
,
'pthread_getcpuclockid'
),
'need time.pthread_getcpuclockid()'
)
@unittest.skipUnless
(
hasattr
(
time
,
'clock_gettime'
),
'need time.clock_gettime()'
)
@unittest.skipUnless
(
hasattr
(
time
,
'CLOCK_THREAD_CPUTIME_ID'
),
'need time.CLOCK_THREAD_CPUTIME_ID'
)
def
test_pthread_getcpuclockid
(
self
):
clk_id
=
time
.
pthread_getcpuclockid
(
threading
.
get_ident
())
self
.
assertTrue
(
type
(
clk_id
)
is
int
)
self
.
assertNotEqual
(
clk_id
,
time
.
CLOCK_THREAD_CPUTIME_ID
)
# This should suffice to show that both calls are measuring the same clock.
t1
=
time
.
clock_gettime
(
clk_id
)
t2
=
time
.
clock_gettime
(
time
.
CLOCK_THREAD_CPUTIME_ID
)
t3
=
time
.
clock_gettime
(
clk_id
)
t4
=
time
.
clock_gettime
(
time
.
CLOCK_THREAD_CPUTIME_ID
)
self
.
assertLessEqual
(
t1
,
t2
)
self
.
assertLessEqual
(
t2
,
t3
)
self
.
assertLessEqual
(
t3
,
t4
)
@unittest.skipUnless
(
hasattr
(
time
,
'clock_getres'
),
'need time.clock_getres()'
)
def
test_clock_getres
(
self
):
...
...
Misc/NEWS.d/next/Library/2017-09-26-11-38-52.bpo-31596.50Eyel.rst
0 → 100644
Dosyayı görüntüle @
e14679c7
Added pthread_getcpuclockid() to the time module
Modules/timemodule.c
Dosyayı görüntüle @
e14679c7
...
...
@@ -20,6 +20,10 @@
#include <io.h>
#endif
#if defined(HAVE_PTHREAD_H)
# include <pthread.h>
#endif
#if defined(__WATCOMC__) && !defined(__QNX__)
#include <i86.h>
#else
...
...
@@ -221,6 +225,31 @@ PyDoc_STRVAR(clock_getres_doc,
Return the resolution (precision) of the specified clock clk_id."
);
#endif
/* HAVE_CLOCK_GETRES */
#ifdef HAVE_PTHREAD_GETCPUCLOCKID
static
PyObject
*
time_pthread_getcpuclockid
(
PyObject
*
self
,
PyObject
*
args
)
{
unsigned
long
thread_id
;
int
err
;
clockid_t
clk_id
;
if
(
!
PyArg_ParseTuple
(
args
,
"k:pthread_getcpuclockid"
,
&
thread_id
))
{
return
NULL
;
}
err
=
pthread_getcpuclockid
((
pthread_t
)
thread_id
,
&
clk_id
);
if
(
err
)
{
errno
=
err
;
PyErr_SetFromErrno
(
PyExc_OSError
);
return
NULL
;
}
return
PyLong_FromLong
(
clk_id
);
}
PyDoc_STRVAR
(
pthread_getcpuclockid_doc
,
"pthread_getcpuclockid(thread_id) -> int
\n
\
\n
\
Return the clk_id of a thread's CPU time clock."
);
#endif
/* HAVE_PTHREAD_GETCPUCLOCKID */
static
PyObject
*
time_sleep
(
PyObject
*
self
,
PyObject
*
obj
)
{
...
...
@@ -1287,6 +1316,9 @@ static PyMethodDef time_methods[] = {
#endif
#ifdef HAVE_CLOCK_GETRES
{
"clock_getres"
,
time_clock_getres
,
METH_VARARGS
,
clock_getres_doc
},
#endif
#ifdef HAVE_PTHREAD_GETCPUCLOCKID
{
"pthread_getcpuclockid"
,
time_pthread_getcpuclockid
,
METH_VARARGS
,
pthread_getcpuclockid_doc
},
#endif
{
"sleep"
,
time_sleep
,
METH_O
,
sleep_doc
},
{
"gmtime"
,
time_gmtime
,
METH_VARARGS
,
gmtime_doc
},
...
...
configure
Dosyayı görüntüle @
e14679c7
...
...
@@ -10480,6 +10480,17 @@ if test "x$ac_cv_func_pthread_atfork" = xyes; then :
#define HAVE_PTHREAD_ATFORK 1
_ACEOF
fi
done
for
ac_func
in
pthread_getcpuclockid
do
:
ac_fn_c_check_func
"
$LINENO
"
"pthread_getcpuclockid"
"ac_cv_func_pthread_getcpuclockid"
if
test
"x
$ac_cv_func_pthread_getcpuclockid
"
=
xyes
;
then
:
cat
>>
confdefs.h
<<
_ACEOF
#define HAVE_PTHREAD_GETCPUCLOCKID 1
_ACEOF
fi
done
...
...
configure.ac
Dosyayı görüntüle @
e14679c7
...
...
@@ -3025,6 +3025,7 @@ if test "$posix_threads" = "yes"; then
;;
esac])
AC_CHECK_FUNCS(pthread_atfork)
AC_CHECK_FUNCS(pthread_getcpuclockid)
fi
...
...
pyconfig.h.in
Dosyayı görüntüle @
e14679c7
...
...
@@ -694,6 +694,9 @@
/* Defined for Solaris 2.6 bug in pthread header. */
#undef HAVE_PTHREAD_DESTRUCTOR
/* Define to 1 if you have the `pthread_getcpuclockid' function. */
#undef HAVE_PTHREAD_GETCPUCLOCKID
/* Define to 1 if you have the <pthread.h> header file. */
#undef HAVE_PTHREAD_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment