Nuitka
The Python compiler
Loading...
Searching...
No Matches
tracing.h
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_TRACING_H__
4#define __NUITKA_TRACING_H__
5
6/* Stupid tracing, intended to help where debugging is not an option
7 * and to give kind of progress record of startup and the running of
8 * the program.
9 */
10
11#ifdef _NUITKA_TRACE
12
13#define NUITKA_PRINT_TRACE(value) \
14 { \
15 puts(value); \
16 fflush(stdout); \
17 }
18#define NUITKA_PRINTF_TRACE(...) \
19 { \
20 printf(__VA_ARGS__); \
21 fflush(stdout); \
22 }
23
24#else
25#define NUITKA_PRINT_TRACE(value)
26#define NUITKA_PRINTF_TRACE(...)
27
28#endif
29
30#if defined(_NUITKA_EXPERIMENTAL_SHOW_STARTUP_TIME)
31
32#if defined(_WIN32)
33
34#include <windows.h>
35static void inline PRINT_TIME_STAMP(void) {
36 SYSTEMTIME t;
37 GetSystemTime(&t); // or GetLocalTime(&t)
38 printf("%02d:%02d:%02d.%03d:", t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
39}
40#else
41static void inline PRINT_TIME_STAMP(void) {
42 struct timeval tv;
43 gettimeofday(&tv, NULL);
44
45 time_t now_time = tv.tv_sec;
46 struct tm *now_tm = localtime(&now_time);
47
48 char tm_buf[64];
49 strftime(tm_buf, sizeof(tm_buf), "%Y-%m-%d %H:%M:%S", now_tm);
50 printf("%s.%03ld ", tm_buf, tv.tv_usec / 1000);
51}
52#endif
53
54#define NUITKA_PRINT_TIMING(value) \
55 { \
56 PRINT_TIME_STAMP(); \
57 puts(value); \
58 fflush(stdout); \
59 }
60
61#else
62
63#define NUITKA_PRINT_TIMING(value) NUITKA_PRINT_TRACE(value)
64
65#endif
66
67#endif
68
69// Part of "Nuitka", an optimizing Python compiler that is compatible and
70// integrates with CPython, but also works on its own.
71//
72// Licensed under the Apache License, Version 2.0 (the "License");
73// you may not use this file except in compliance with the License.
74// You may obtain a copy of the License at
75//
76// http://www.apache.org/licenses/LICENSE-2.0
77//
78// Unless required by applicable law or agreed to in writing, software
79// distributed under the License is distributed on an "AS IS" BASIS,
80// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81// See the License for the specific language governing permissions and
82// limitations under the License.