/src/cpython/Modules/clinic/timemodule.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #include "pycore_modsupport.h" // _PyArg_CheckPositional() |
6 | | #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() |
7 | | |
8 | | PyDoc_STRVAR(time_time__doc__, |
9 | | "time($module, /)\n" |
10 | | "--\n" |
11 | | "\n" |
12 | | "Return the current time in seconds since the Epoch.\n" |
13 | | "\n" |
14 | | "Fractions of a second may be present if the system clock provides\n" |
15 | | "them."); |
16 | | |
17 | | #define TIME_TIME_METHODDEF \ |
18 | | {"time", (PyCFunction)time_time, METH_NOARGS, time_time__doc__}, |
19 | | |
20 | | static double |
21 | | time_time_impl(PyObject *module); |
22 | | |
23 | | static PyObject * |
24 | | time_time(PyObject *module, PyObject *Py_UNUSED(ignored)) |
25 | 12 | { |
26 | 12 | PyObject *return_value = NULL; |
27 | 12 | double _return_value; |
28 | | |
29 | 12 | _return_value = time_time_impl(module); |
30 | 12 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
31 | 0 | goto exit; |
32 | 0 | } |
33 | 12 | return_value = PyFloat_FromDouble(_return_value); |
34 | | |
35 | 12 | exit: |
36 | 12 | return return_value; |
37 | 12 | } |
38 | | |
39 | | PyDoc_STRVAR(time_time_ns__doc__, |
40 | | "time_ns($module, /)\n" |
41 | | "--\n" |
42 | | "\n" |
43 | | "Return the current time in nanoseconds since the Epoch."); |
44 | | |
45 | | #define TIME_TIME_NS_METHODDEF \ |
46 | | {"time_ns", (PyCFunction)time_time_ns, METH_NOARGS, time_time_ns__doc__}, |
47 | | |
48 | | static PyObject * |
49 | | time_time_ns_impl(PyObject *module); |
50 | | |
51 | | static PyObject * |
52 | | time_time_ns(PyObject *module, PyObject *Py_UNUSED(ignored)) |
53 | 0 | { |
54 | 0 | return time_time_ns_impl(module); |
55 | 0 | } |
56 | | |
57 | | #if defined(HAVE_CLOCK_GETTIME) |
58 | | |
59 | | PyDoc_STRVAR(time_clock_gettime__doc__, |
60 | | "clock_gettime($module, clk_id, /)\n" |
61 | | "--\n" |
62 | | "\n" |
63 | | "Return the time of the specified clock clk_id as a float."); |
64 | | |
65 | | #define TIME_CLOCK_GETTIME_METHODDEF \ |
66 | | {"clock_gettime", (PyCFunction)time_clock_gettime, METH_O, time_clock_gettime__doc__}, |
67 | | |
68 | | static PyObject * |
69 | | time_clock_gettime_impl(PyObject *module, clockid_t clk_id); |
70 | | |
71 | | static PyObject * |
72 | | time_clock_gettime(PyObject *module, PyObject *arg) |
73 | 0 | { |
74 | 0 | PyObject *return_value = NULL; |
75 | 0 | clockid_t clk_id; |
76 | |
|
77 | 0 | if (!time_clockid_converter(arg, &clk_id)) { |
78 | 0 | goto exit; |
79 | 0 | } |
80 | 0 | return_value = time_clock_gettime_impl(module, clk_id); |
81 | |
|
82 | 0 | exit: |
83 | 0 | return return_value; |
84 | 0 | } |
85 | | |
86 | | #endif /* defined(HAVE_CLOCK_GETTIME) */ |
87 | | |
88 | | #if defined(HAVE_CLOCK_GETTIME) |
89 | | |
90 | | PyDoc_STRVAR(time_clock_gettime_ns__doc__, |
91 | | "clock_gettime_ns($module, clk_id, /)\n" |
92 | | "--\n" |
93 | | "\n" |
94 | | "Return the time of the specified clock clk_id as nanoseconds (int)."); |
95 | | |
96 | | #define TIME_CLOCK_GETTIME_NS_METHODDEF \ |
97 | | {"clock_gettime_ns", (PyCFunction)time_clock_gettime_ns, METH_O, time_clock_gettime_ns__doc__}, |
98 | | |
99 | | static PyObject * |
100 | | time_clock_gettime_ns_impl(PyObject *module, clockid_t clk_id); |
101 | | |
102 | | static PyObject * |
103 | | time_clock_gettime_ns(PyObject *module, PyObject *arg) |
104 | 0 | { |
105 | 0 | PyObject *return_value = NULL; |
106 | 0 | clockid_t clk_id; |
107 | |
|
108 | 0 | if (!time_clockid_converter(arg, &clk_id)) { |
109 | 0 | goto exit; |
110 | 0 | } |
111 | 0 | return_value = time_clock_gettime_ns_impl(module, clk_id); |
112 | |
|
113 | 0 | exit: |
114 | 0 | return return_value; |
115 | 0 | } |
116 | | |
117 | | #endif /* defined(HAVE_CLOCK_GETTIME) */ |
118 | | |
119 | | #if defined(HAVE_CLOCK_SETTIME) |
120 | | |
121 | | PyDoc_STRVAR(time_clock_settime__doc__, |
122 | | "clock_settime($module, clk_id, time, /)\n" |
123 | | "--\n" |
124 | | "\n" |
125 | | "Set the time of the specified clock clk_id."); |
126 | | |
127 | | #define TIME_CLOCK_SETTIME_METHODDEF \ |
128 | | {"clock_settime", _PyCFunction_CAST(time_clock_settime), METH_FASTCALL, time_clock_settime__doc__}, |
129 | | |
130 | | static PyObject * |
131 | | time_clock_settime_impl(PyObject *module, int clk_id, PyObject *obj); |
132 | | |
133 | | static PyObject * |
134 | | time_clock_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
135 | 0 | { |
136 | 0 | PyObject *return_value = NULL; |
137 | 0 | int clk_id; |
138 | 0 | PyObject *obj; |
139 | |
|
140 | 0 | if (!_PyArg_CheckPositional("clock_settime", nargs, 2, 2)) { |
141 | 0 | goto exit; |
142 | 0 | } |
143 | 0 | clk_id = PyLong_AsInt(args[0]); |
144 | 0 | if (clk_id == -1 && PyErr_Occurred()) { |
145 | 0 | goto exit; |
146 | 0 | } |
147 | 0 | obj = args[1]; |
148 | 0 | return_value = time_clock_settime_impl(module, clk_id, obj); |
149 | |
|
150 | 0 | exit: |
151 | 0 | return return_value; |
152 | 0 | } |
153 | | |
154 | | #endif /* defined(HAVE_CLOCK_SETTIME) */ |
155 | | |
156 | | #if defined(HAVE_CLOCK_SETTIME) |
157 | | |
158 | | PyDoc_STRVAR(time_clock_settime_ns__doc__, |
159 | | "clock_settime_ns($module, clk_id, time, /)\n" |
160 | | "--\n" |
161 | | "\n" |
162 | | "Set the time of the specified clock clk_id with nanoseconds."); |
163 | | |
164 | | #define TIME_CLOCK_SETTIME_NS_METHODDEF \ |
165 | | {"clock_settime_ns", _PyCFunction_CAST(time_clock_settime_ns), METH_FASTCALL, time_clock_settime_ns__doc__}, |
166 | | |
167 | | static PyObject * |
168 | | time_clock_settime_ns_impl(PyObject *module, int clk_id, PyObject *obj); |
169 | | |
170 | | static PyObject * |
171 | | time_clock_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
172 | 0 | { |
173 | 0 | PyObject *return_value = NULL; |
174 | 0 | int clk_id; |
175 | 0 | PyObject *obj; |
176 | |
|
177 | 0 | if (!_PyArg_CheckPositional("clock_settime_ns", nargs, 2, 2)) { |
178 | 0 | goto exit; |
179 | 0 | } |
180 | 0 | clk_id = PyLong_AsInt(args[0]); |
181 | 0 | if (clk_id == -1 && PyErr_Occurred()) { |
182 | 0 | goto exit; |
183 | 0 | } |
184 | 0 | obj = args[1]; |
185 | 0 | return_value = time_clock_settime_ns_impl(module, clk_id, obj); |
186 | |
|
187 | 0 | exit: |
188 | 0 | return return_value; |
189 | 0 | } |
190 | | |
191 | | #endif /* defined(HAVE_CLOCK_SETTIME) */ |
192 | | |
193 | | #if defined(HAVE_CLOCK_GETRES) |
194 | | |
195 | | PyDoc_STRVAR(time_clock_getres__doc__, |
196 | | "clock_getres($module, clk_id, /)\n" |
197 | | "--\n" |
198 | | "\n" |
199 | | "Return the resolution (precision) of the specified clock clk_id."); |
200 | | |
201 | | #define TIME_CLOCK_GETRES_METHODDEF \ |
202 | | {"clock_getres", (PyCFunction)time_clock_getres, METH_O, time_clock_getres__doc__}, |
203 | | |
204 | | static double |
205 | | time_clock_getres_impl(PyObject *module, int clk_id); |
206 | | |
207 | | static PyObject * |
208 | | time_clock_getres(PyObject *module, PyObject *arg) |
209 | 0 | { |
210 | 0 | PyObject *return_value = NULL; |
211 | 0 | int clk_id; |
212 | 0 | double _return_value; |
213 | |
|
214 | 0 | clk_id = PyLong_AsInt(arg); |
215 | 0 | if (clk_id == -1 && PyErr_Occurred()) { |
216 | 0 | goto exit; |
217 | 0 | } |
218 | 0 | _return_value = time_clock_getres_impl(module, clk_id); |
219 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
220 | 0 | goto exit; |
221 | 0 | } |
222 | 0 | return_value = PyFloat_FromDouble(_return_value); |
223 | |
|
224 | 0 | exit: |
225 | 0 | return return_value; |
226 | 0 | } |
227 | | |
228 | | #endif /* defined(HAVE_CLOCK_GETRES) */ |
229 | | |
230 | | #if defined(HAVE_PTHREAD_GETCPUCLOCKID) |
231 | | |
232 | | PyDoc_STRVAR(time_pthread_getcpuclockid__doc__, |
233 | | "pthread_getcpuclockid($module, thread_id, /)\n" |
234 | | "--\n" |
235 | | "\n" |
236 | | "Return the clk_id of a thread\'s CPU time clock."); |
237 | | |
238 | | #define TIME_PTHREAD_GETCPUCLOCKID_METHODDEF \ |
239 | | {"pthread_getcpuclockid", (PyCFunction)time_pthread_getcpuclockid, METH_O, time_pthread_getcpuclockid__doc__}, |
240 | | |
241 | | static PyObject * |
242 | | time_pthread_getcpuclockid_impl(PyObject *module, unsigned long thread_id); |
243 | | |
244 | | static PyObject * |
245 | | time_pthread_getcpuclockid(PyObject *module, PyObject *arg) |
246 | 0 | { |
247 | 0 | PyObject *return_value = NULL; |
248 | 0 | unsigned long thread_id; |
249 | |
|
250 | 0 | if (!PyIndex_Check(arg)) { |
251 | 0 | _PyArg_BadArgument("pthread_getcpuclockid", "argument", "int", arg); |
252 | 0 | goto exit; |
253 | 0 | } |
254 | 0 | { |
255 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(arg, &thread_id, sizeof(unsigned long), |
256 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
257 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
258 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
259 | 0 | if (_bytes < 0) { |
260 | 0 | goto exit; |
261 | 0 | } |
262 | 0 | if ((size_t)_bytes > sizeof(unsigned long)) { |
263 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
264 | 0 | "integer value out of range", 1) < 0) |
265 | 0 | { |
266 | 0 | goto exit; |
267 | 0 | } |
268 | 0 | } |
269 | 0 | } |
270 | 0 | return_value = time_pthread_getcpuclockid_impl(module, thread_id); |
271 | |
|
272 | 0 | exit: |
273 | 0 | return return_value; |
274 | 0 | } |
275 | | |
276 | | #endif /* defined(HAVE_PTHREAD_GETCPUCLOCKID) */ |
277 | | |
278 | | PyDoc_STRVAR(time_sleep__doc__, |
279 | | "sleep($module, seconds, /)\n" |
280 | | "--\n" |
281 | | "\n" |
282 | | "Delay execution for a given number of seconds.\n" |
283 | | "\n" |
284 | | "The argument may be a floating-point number for subsecond precision."); |
285 | | |
286 | | #define TIME_SLEEP_METHODDEF \ |
287 | | {"sleep", (PyCFunction)time_sleep, METH_O, time_sleep__doc__}, |
288 | | |
289 | | PyDoc_STRVAR(time_gmtime__doc__, |
290 | | "gmtime($module, seconds=None, /)\n" |
291 | | "--\n" |
292 | | "\n" |
293 | | "Convert seconds since the Epoch to a time tuple expressing UTC.\n" |
294 | | "\n" |
295 | | "That is, Greenwich Mean Time. When \'seconds\' is not passed in, convert\n" |
296 | | "the current time instead.\n" |
297 | | "\n" |
298 | | "If the platform supports the tm_gmtoff and tm_zone, they are available\n" |
299 | | "as attributes only."); |
300 | | |
301 | | #define TIME_GMTIME_METHODDEF \ |
302 | | {"gmtime", _PyCFunction_CAST(time_gmtime), METH_FASTCALL, time_gmtime__doc__}, |
303 | | |
304 | | static PyObject * |
305 | | time_gmtime_impl(PyObject *module, PyObject *ot); |
306 | | |
307 | | static PyObject * |
308 | | time_gmtime(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
309 | 0 | { |
310 | 0 | PyObject *return_value = NULL; |
311 | 0 | PyObject *ot = Py_None; |
312 | |
|
313 | 0 | if (!_PyArg_CheckPositional("gmtime", nargs, 0, 1)) { |
314 | 0 | goto exit; |
315 | 0 | } |
316 | 0 | if (nargs < 1) { |
317 | 0 | goto skip_optional; |
318 | 0 | } |
319 | 0 | ot = args[0]; |
320 | 0 | skip_optional: |
321 | 0 | return_value = time_gmtime_impl(module, ot); |
322 | |
|
323 | 0 | exit: |
324 | 0 | return return_value; |
325 | 0 | } |
326 | | |
327 | | PyDoc_STRVAR(time_localtime__doc__, |
328 | | "localtime($module, seconds=None, /)\n" |
329 | | "--\n" |
330 | | "\n" |
331 | | "Convert seconds since the Epoch to a time tuple expressing local time.\n" |
332 | | "\n" |
333 | | "When \'seconds\' is not passed in, convert the current time instead."); |
334 | | |
335 | | #define TIME_LOCALTIME_METHODDEF \ |
336 | | {"localtime", _PyCFunction_CAST(time_localtime), METH_FASTCALL, time_localtime__doc__}, |
337 | | |
338 | | static PyObject * |
339 | | time_localtime_impl(PyObject *module, PyObject *ot); |
340 | | |
341 | | static PyObject * |
342 | | time_localtime(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
343 | 0 | { |
344 | 0 | PyObject *return_value = NULL; |
345 | 0 | PyObject *ot = Py_None; |
346 | |
|
347 | 0 | if (!_PyArg_CheckPositional("localtime", nargs, 0, 1)) { |
348 | 0 | goto exit; |
349 | 0 | } |
350 | 0 | if (nargs < 1) { |
351 | 0 | goto skip_optional; |
352 | 0 | } |
353 | 0 | ot = args[0]; |
354 | 0 | skip_optional: |
355 | 0 | return_value = time_localtime_impl(module, ot); |
356 | |
|
357 | 0 | exit: |
358 | 0 | return return_value; |
359 | 0 | } |
360 | | |
361 | | PyDoc_STRVAR(time_asctime__doc__, |
362 | | "asctime($module, time_tuple=<unrepresentable>, /)\n" |
363 | | "--\n" |
364 | | "\n" |
365 | | "Convert a time tuple to a string, e.g. \'Sat Jun 06 16:26:11 1998\'.\n" |
366 | | "\n" |
367 | | "When the time tuple is not present, current time as returned by\n" |
368 | | "localtime() is used."); |
369 | | |
370 | | #define TIME_ASCTIME_METHODDEF \ |
371 | | {"asctime", _PyCFunction_CAST(time_asctime), METH_FASTCALL, time_asctime__doc__}, |
372 | | |
373 | | static PyObject * |
374 | | time_asctime_impl(PyObject *module, PyObject *tup); |
375 | | |
376 | | static PyObject * |
377 | | time_asctime(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
378 | 0 | { |
379 | 0 | PyObject *return_value = NULL; |
380 | 0 | PyObject *tup = NULL; |
381 | |
|
382 | 0 | if (!_PyArg_CheckPositional("asctime", nargs, 0, 1)) { |
383 | 0 | goto exit; |
384 | 0 | } |
385 | 0 | if (nargs < 1) { |
386 | 0 | goto skip_optional; |
387 | 0 | } |
388 | 0 | tup = args[0]; |
389 | 0 | skip_optional: |
390 | 0 | return_value = time_asctime_impl(module, tup); |
391 | |
|
392 | 0 | exit: |
393 | 0 | return return_value; |
394 | 0 | } |
395 | | |
396 | | PyDoc_STRVAR(time_ctime__doc__, |
397 | | "ctime($module, seconds=None, /)\n" |
398 | | "--\n" |
399 | | "\n" |
400 | | "Convert a time in seconds since the Epoch to a string in local time.\n" |
401 | | "\n" |
402 | | "This is equivalent to asctime(localtime(seconds)). When \'seconds\' is\n" |
403 | | "not passed in, convert the current time instead."); |
404 | | |
405 | | #define TIME_CTIME_METHODDEF \ |
406 | | {"ctime", _PyCFunction_CAST(time_ctime), METH_FASTCALL, time_ctime__doc__}, |
407 | | |
408 | | static PyObject * |
409 | | time_ctime_impl(PyObject *module, PyObject *ot); |
410 | | |
411 | | static PyObject * |
412 | | time_ctime(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
413 | 0 | { |
414 | 0 | PyObject *return_value = NULL; |
415 | 0 | PyObject *ot = Py_None; |
416 | |
|
417 | 0 | if (!_PyArg_CheckPositional("ctime", nargs, 0, 1)) { |
418 | 0 | goto exit; |
419 | 0 | } |
420 | 0 | if (nargs < 1) { |
421 | 0 | goto skip_optional; |
422 | 0 | } |
423 | 0 | ot = args[0]; |
424 | 0 | skip_optional: |
425 | 0 | return_value = time_ctime_impl(module, ot); |
426 | |
|
427 | 0 | exit: |
428 | 0 | return return_value; |
429 | 0 | } |
430 | | |
431 | | #if defined(HAVE_MKTIME) |
432 | | |
433 | | PyDoc_STRVAR(time_mktime__doc__, |
434 | | "mktime($module, time_tuple, /)\n" |
435 | | "--\n" |
436 | | "\n" |
437 | | "Convert a time tuple in local time to seconds since the Epoch.\n" |
438 | | "\n" |
439 | | "Note that mktime(gmtime(0)) will not generally return zero for most\n" |
440 | | "time zones; instead the returned value will either be equal to that of\n" |
441 | | "the timezone or altzone attributes on the time module."); |
442 | | |
443 | | #define TIME_MKTIME_METHODDEF \ |
444 | | {"mktime", (PyCFunction)time_mktime, METH_O, time_mktime__doc__}, |
445 | | |
446 | | #endif /* defined(HAVE_MKTIME) */ |
447 | | |
448 | | #if defined(HAVE_WORKING_TZSET) |
449 | | |
450 | | PyDoc_STRVAR(time_tzset__doc__, |
451 | | "tzset($module, /)\n" |
452 | | "--\n" |
453 | | "\n" |
454 | | "Initialize, or reinitialize, the local timezone.\n" |
455 | | "\n" |
456 | | "The local timezone is set to the value stored in os.environ[\'TZ\']. The\n" |
457 | | "TZ environment variable should be specified in standard Unix timezone\n" |
458 | | "format as documented in the tzset man page (eg. \'US/Eastern\',\n" |
459 | | "\'Europe/Amsterdam\'). Unknown timezones will silently fall back to UTC.\n" |
460 | | "If the TZ environment variable is not set, the local timezone is set to\n" |
461 | | "the systems best guess of wallclock time. Changing the TZ environment\n" |
462 | | "variable without calling tzset *may* change the local timezone used by\n" |
463 | | "methods such as localtime, but this behaviour should not be relied on."); |
464 | | |
465 | | #define TIME_TZSET_METHODDEF \ |
466 | | {"tzset", (PyCFunction)time_tzset, METH_NOARGS, time_tzset__doc__}, |
467 | | |
468 | | static PyObject * |
469 | | time_tzset_impl(PyObject *module); |
470 | | |
471 | | static PyObject * |
472 | | time_tzset(PyObject *module, PyObject *Py_UNUSED(ignored)) |
473 | 0 | { |
474 | 0 | return time_tzset_impl(module); |
475 | 0 | } |
476 | | |
477 | | #endif /* defined(HAVE_WORKING_TZSET) */ |
478 | | |
479 | | PyDoc_STRVAR(time_monotonic__doc__, |
480 | | "monotonic($module, /)\n" |
481 | | "--\n" |
482 | | "\n" |
483 | | "Monotonic clock, cannot go backward."); |
484 | | |
485 | | #define TIME_MONOTONIC_METHODDEF \ |
486 | | {"monotonic", (PyCFunction)time_monotonic, METH_NOARGS, time_monotonic__doc__}, |
487 | | |
488 | | static double |
489 | | time_monotonic_impl(PyObject *module); |
490 | | |
491 | | static PyObject * |
492 | | time_monotonic(PyObject *module, PyObject *Py_UNUSED(ignored)) |
493 | 0 | { |
494 | 0 | PyObject *return_value = NULL; |
495 | 0 | double _return_value; |
496 | |
|
497 | 0 | _return_value = time_monotonic_impl(module); |
498 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
499 | 0 | goto exit; |
500 | 0 | } |
501 | 0 | return_value = PyFloat_FromDouble(_return_value); |
502 | |
|
503 | 0 | exit: |
504 | 0 | return return_value; |
505 | 0 | } |
506 | | |
507 | | PyDoc_STRVAR(time_monotonic_ns__doc__, |
508 | | "monotonic_ns($module, /)\n" |
509 | | "--\n" |
510 | | "\n" |
511 | | "Monotonic clock, cannot go backward, as nanoseconds."); |
512 | | |
513 | | #define TIME_MONOTONIC_NS_METHODDEF \ |
514 | | {"monotonic_ns", (PyCFunction)time_monotonic_ns, METH_NOARGS, time_monotonic_ns__doc__}, |
515 | | |
516 | | static PyObject * |
517 | | time_monotonic_ns_impl(PyObject *module); |
518 | | |
519 | | static PyObject * |
520 | | time_monotonic_ns(PyObject *module, PyObject *Py_UNUSED(ignored)) |
521 | 0 | { |
522 | 0 | return time_monotonic_ns_impl(module); |
523 | 0 | } |
524 | | |
525 | | PyDoc_STRVAR(time_perf_counter__doc__, |
526 | | "perf_counter($module, /)\n" |
527 | | "--\n" |
528 | | "\n" |
529 | | "Performance counter for benchmarking."); |
530 | | |
531 | | #define TIME_PERF_COUNTER_METHODDEF \ |
532 | | {"perf_counter", (PyCFunction)time_perf_counter, METH_NOARGS, time_perf_counter__doc__}, |
533 | | |
534 | | static double |
535 | | time_perf_counter_impl(PyObject *module); |
536 | | |
537 | | static PyObject * |
538 | | time_perf_counter(PyObject *module, PyObject *Py_UNUSED(ignored)) |
539 | 24.1k | { |
540 | 24.1k | PyObject *return_value = NULL; |
541 | 24.1k | double _return_value; |
542 | | |
543 | 24.1k | _return_value = time_perf_counter_impl(module); |
544 | 24.1k | if ((_return_value == -1.0) && PyErr_Occurred()) { |
545 | 0 | goto exit; |
546 | 0 | } |
547 | 24.1k | return_value = PyFloat_FromDouble(_return_value); |
548 | | |
549 | 24.1k | exit: |
550 | 24.1k | return return_value; |
551 | 24.1k | } |
552 | | |
553 | | PyDoc_STRVAR(time_perf_counter_ns__doc__, |
554 | | "perf_counter_ns($module, /)\n" |
555 | | "--\n" |
556 | | "\n" |
557 | | "Performance counter for benchmarking as nanoseconds."); |
558 | | |
559 | | #define TIME_PERF_COUNTER_NS_METHODDEF \ |
560 | | {"perf_counter_ns", (PyCFunction)time_perf_counter_ns, METH_NOARGS, time_perf_counter_ns__doc__}, |
561 | | |
562 | | static PyObject * |
563 | | time_perf_counter_ns_impl(PyObject *module); |
564 | | |
565 | | static PyObject * |
566 | | time_perf_counter_ns(PyObject *module, PyObject *Py_UNUSED(ignored)) |
567 | 0 | { |
568 | 0 | return time_perf_counter_ns_impl(module); |
569 | 0 | } |
570 | | |
571 | | PyDoc_STRVAR(time_process_time__doc__, |
572 | | "process_time($module, /)\n" |
573 | | "--\n" |
574 | | "\n" |
575 | | "Process time for profiling.\n" |
576 | | "\n" |
577 | | "That is the sum of the kernel and user-space CPU time."); |
578 | | |
579 | | #define TIME_PROCESS_TIME_METHODDEF \ |
580 | | {"process_time", (PyCFunction)time_process_time, METH_NOARGS, time_process_time__doc__}, |
581 | | |
582 | | static double |
583 | | time_process_time_impl(PyObject *module); |
584 | | |
585 | | static PyObject * |
586 | | time_process_time(PyObject *module, PyObject *Py_UNUSED(ignored)) |
587 | 0 | { |
588 | 0 | PyObject *return_value = NULL; |
589 | 0 | double _return_value; |
590 | |
|
591 | 0 | _return_value = time_process_time_impl(module); |
592 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
593 | 0 | goto exit; |
594 | 0 | } |
595 | 0 | return_value = PyFloat_FromDouble(_return_value); |
596 | |
|
597 | 0 | exit: |
598 | 0 | return return_value; |
599 | 0 | } |
600 | | |
601 | | PyDoc_STRVAR(time_process_time_ns__doc__, |
602 | | "process_time_ns($module, /)\n" |
603 | | "--\n" |
604 | | "\n" |
605 | | "Process time for profiling as nanoseconds.\n" |
606 | | "\n" |
607 | | "That is the sum of the kernel and user-space CPU time."); |
608 | | |
609 | | #define TIME_PROCESS_TIME_NS_METHODDEF \ |
610 | | {"process_time_ns", (PyCFunction)time_process_time_ns, METH_NOARGS, time_process_time_ns__doc__}, |
611 | | |
612 | | static PyObject * |
613 | | time_process_time_ns_impl(PyObject *module); |
614 | | |
615 | | static PyObject * |
616 | | time_process_time_ns(PyObject *module, PyObject *Py_UNUSED(ignored)) |
617 | 0 | { |
618 | 0 | return time_process_time_ns_impl(module); |
619 | 0 | } |
620 | | |
621 | | #if defined(HAVE_THREAD_TIME) |
622 | | |
623 | | PyDoc_STRVAR(time_thread_time__doc__, |
624 | | "thread_time($module, /)\n" |
625 | | "--\n" |
626 | | "\n" |
627 | | "Thread time for profiling.\n" |
628 | | "\n" |
629 | | "That is the sum of the kernel and user-space CPU time."); |
630 | | |
631 | | #define TIME_THREAD_TIME_METHODDEF \ |
632 | | {"thread_time", (PyCFunction)time_thread_time, METH_NOARGS, time_thread_time__doc__}, |
633 | | |
634 | | static double |
635 | | time_thread_time_impl(PyObject *module); |
636 | | |
637 | | static PyObject * |
638 | | time_thread_time(PyObject *module, PyObject *Py_UNUSED(ignored)) |
639 | 0 | { |
640 | 0 | PyObject *return_value = NULL; |
641 | 0 | double _return_value; |
642 | |
|
643 | 0 | _return_value = time_thread_time_impl(module); |
644 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
645 | 0 | goto exit; |
646 | 0 | } |
647 | 0 | return_value = PyFloat_FromDouble(_return_value); |
648 | |
|
649 | 0 | exit: |
650 | 0 | return return_value; |
651 | 0 | } |
652 | | |
653 | | #endif /* defined(HAVE_THREAD_TIME) */ |
654 | | |
655 | | #if defined(HAVE_THREAD_TIME) |
656 | | |
657 | | PyDoc_STRVAR(time_thread_time_ns__doc__, |
658 | | "thread_time_ns($module, /)\n" |
659 | | "--\n" |
660 | | "\n" |
661 | | "Thread time for profiling as nanoseconds.\n" |
662 | | "\n" |
663 | | "That is the sum of the kernel and user-space CPU time."); |
664 | | |
665 | | #define TIME_THREAD_TIME_NS_METHODDEF \ |
666 | | {"thread_time_ns", (PyCFunction)time_thread_time_ns, METH_NOARGS, time_thread_time_ns__doc__}, |
667 | | |
668 | | static PyObject * |
669 | | time_thread_time_ns_impl(PyObject *module); |
670 | | |
671 | | static PyObject * |
672 | | time_thread_time_ns(PyObject *module, PyObject *Py_UNUSED(ignored)) |
673 | 0 | { |
674 | 0 | return time_thread_time_ns_impl(module); |
675 | 0 | } |
676 | | |
677 | | #endif /* defined(HAVE_THREAD_TIME) */ |
678 | | |
679 | | PyDoc_STRVAR(time_get_clock_info__doc__, |
680 | | "get_clock_info($module, name, /)\n" |
681 | | "--\n" |
682 | | "\n" |
683 | | "Get information of the specified clock."); |
684 | | |
685 | | #define TIME_GET_CLOCK_INFO_METHODDEF \ |
686 | | {"get_clock_info", (PyCFunction)time_get_clock_info, METH_O, time_get_clock_info__doc__}, |
687 | | |
688 | | static PyObject * |
689 | | time_get_clock_info_impl(PyObject *module, const char *name); |
690 | | |
691 | | static PyObject * |
692 | | time_get_clock_info(PyObject *module, PyObject *arg) |
693 | 0 | { |
694 | 0 | PyObject *return_value = NULL; |
695 | 0 | const char *name; |
696 | |
|
697 | 0 | if (!PyUnicode_Check(arg)) { |
698 | 0 | _PyArg_BadArgument("get_clock_info", "argument", "str", arg); |
699 | 0 | goto exit; |
700 | 0 | } |
701 | 0 | name = _PyUnicode_AsUTF8NoNUL(arg); |
702 | 0 | if (name == NULL) { |
703 | 0 | goto exit; |
704 | 0 | } |
705 | 0 | return_value = time_get_clock_info_impl(module, name); |
706 | |
|
707 | 0 | exit: |
708 | 0 | return return_value; |
709 | 0 | } |
710 | | |
711 | | #ifndef TIME_CLOCK_GETTIME_METHODDEF |
712 | | #define TIME_CLOCK_GETTIME_METHODDEF |
713 | | #endif /* !defined(TIME_CLOCK_GETTIME_METHODDEF) */ |
714 | | |
715 | | #ifndef TIME_CLOCK_GETTIME_NS_METHODDEF |
716 | | #define TIME_CLOCK_GETTIME_NS_METHODDEF |
717 | | #endif /* !defined(TIME_CLOCK_GETTIME_NS_METHODDEF) */ |
718 | | |
719 | | #ifndef TIME_CLOCK_SETTIME_METHODDEF |
720 | | #define TIME_CLOCK_SETTIME_METHODDEF |
721 | | #endif /* !defined(TIME_CLOCK_SETTIME_METHODDEF) */ |
722 | | |
723 | | #ifndef TIME_CLOCK_SETTIME_NS_METHODDEF |
724 | | #define TIME_CLOCK_SETTIME_NS_METHODDEF |
725 | | #endif /* !defined(TIME_CLOCK_SETTIME_NS_METHODDEF) */ |
726 | | |
727 | | #ifndef TIME_CLOCK_GETRES_METHODDEF |
728 | | #define TIME_CLOCK_GETRES_METHODDEF |
729 | | #endif /* !defined(TIME_CLOCK_GETRES_METHODDEF) */ |
730 | | |
731 | | #ifndef TIME_PTHREAD_GETCPUCLOCKID_METHODDEF |
732 | | #define TIME_PTHREAD_GETCPUCLOCKID_METHODDEF |
733 | | #endif /* !defined(TIME_PTHREAD_GETCPUCLOCKID_METHODDEF) */ |
734 | | |
735 | | #ifndef TIME_MKTIME_METHODDEF |
736 | | #define TIME_MKTIME_METHODDEF |
737 | | #endif /* !defined(TIME_MKTIME_METHODDEF) */ |
738 | | |
739 | | #ifndef TIME_TZSET_METHODDEF |
740 | | #define TIME_TZSET_METHODDEF |
741 | | #endif /* !defined(TIME_TZSET_METHODDEF) */ |
742 | | |
743 | | #ifndef TIME_THREAD_TIME_METHODDEF |
744 | | #define TIME_THREAD_TIME_METHODDEF |
745 | | #endif /* !defined(TIME_THREAD_TIME_METHODDEF) */ |
746 | | |
747 | | #ifndef TIME_THREAD_TIME_NS_METHODDEF |
748 | | #define TIME_THREAD_TIME_NS_METHODDEF |
749 | | #endif /* !defined(TIME_THREAD_TIME_NS_METHODDEF) */ |
750 | | /*[clinic end generated code: output=d89be8cc2b2a7b05 input=a9049054013a1b77]*/ |