logger-36 2024.1__py3-none-any.whl → 2025.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logger_36/__init__.py +64 -42
- logger_36/api/logger.py +53 -0
- logger_36/api/storage.py +53 -0
- logger_36/catalog/config/console_rich.py +76 -0
- logger_36/catalog/handler/console.py +117 -0
- logger_36/catalog/handler/console_rich.py +235 -0
- logger_36/catalog/handler/file.py +128 -0
- logger_36/catalog/handler/generic.py +230 -0
- logger_36/catalog/logger/chronos.py +61 -0
- logger_36/catalog/logger/gpu.py +90 -0
- logger_36/catalog/logger/memory.py +129 -0
- logger_36/catalog/logger/system.py +84 -0
- logger_36/config/issue.py +56 -0
- logger_36/config/logger.py +103 -0
- logger_36/config/memory.py +54 -0
- logger_36/config/message.py +66 -0
- logger_36/config/system.py +70 -0
- logger_36/constant/error.py +70 -0
- logger_36/constant/generic.py +58 -0
- logger_36/constant/handler.py +58 -0
- logger_36/constant/issue.py +58 -0
- logger_36/constant/logger.py +67 -0
- logger_36/constant/memory.py +58 -0
- logger_36/constant/message.py +72 -0
- logger_36/constant/record.py +55 -0
- logger_36/constant/system.py +60 -0
- logger_36/content.py +55 -0
- logger_36/exception.py +105 -0
- logger_36/gpu.py +53 -0
- logger_36/handler.py +209 -0
- logger_36/instance/logger.py +55 -0
- logger_36/instance/loggers.py +56 -0
- logger_36/memory.py +60 -0
- logger_36/storage.py +53 -0
- logger_36/system.py +53 -0
- logger_36/task/format/memory.py +132 -0
- logger_36/task/format/message.py +111 -0
- logger_36/task/format/rule.py +74 -0
- logger_36/task/inspection.py +70 -48
- logger_36/task/measure/chronos.py +84 -0
- logger_36/task/measure/memory.py +72 -0
- logger_36/task/storage.py +127 -46
- logger_36/time.py +54 -0
- logger_36/type/handler.py +184 -0
- logger_36/type/issue.py +91 -0
- logger_36/type/logger.py +542 -0
- logger_36/type/loggers.py +78 -0
- logger_36/version.py +53 -32
- logger_36-2025.4.dist-info/METADATA +154 -0
- logger_36-2025.4.dist-info/RECORD +52 -0
- {logger_36-2024.1.dist-info → logger_36-2025.4.dist-info}/WHEEL +1 -1
- logger_36/catalog/gpu.py +0 -56
- logger_36/catalog/memory.py +0 -109
- logger_36/catalog/system.py +0 -84
- logger_36/config.py +0 -48
- logger_36/constant.py +0 -52
- logger_36/instance.py +0 -34
- logger_36/main.py +0 -96
- logger_36/measure/chronos.py +0 -55
- logger_36/measure/memory.py +0 -50
- logger_36/type/console.py +0 -122
- logger_36/type/extension.py +0 -122
- logger_36/type/file.py +0 -52
- logger_36/type/generic.py +0 -115
- logger_36-2024.1.dist-info/METADATA +0 -106
- logger_36-2024.1.dist-info/RECORD +0 -21
- {logger_36-2024.1.dist-info → logger_36-2025.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
8
|
+
import logging as lggg
|
9
|
+
import textwrap as txt_
|
10
|
+
import typing as h
|
11
|
+
from pathlib import Path as path_t
|
12
|
+
|
13
|
+
from logger_36.constant.message import LINE_INDENT
|
14
|
+
from logger_36.constant.record import SHOW_W_RULE_ATTR
|
15
|
+
from logger_36.task.format.rule import RuleAsText
|
16
|
+
from logger_36.type.handler import handler_extension_t
|
17
|
+
|
18
|
+
|
19
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
20
|
+
class file_handler_t(lggg.FileHandler):
|
21
|
+
|
22
|
+
extension: handler_extension_t = d.field(init=False)
|
23
|
+
MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
|
24
|
+
|
25
|
+
name: d.InitVar[str | None] = None
|
26
|
+
level: d.InitVar[int] = lggg.NOTSET
|
27
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
28
|
+
message_width: d.InitVar[int] = -1
|
29
|
+
formatter: d.InitVar[lggg.Formatter | None] = None
|
30
|
+
|
31
|
+
path: d.InitVar[path_t | None] = None
|
32
|
+
handler_args: d.InitVar[tuple[h.Any, ...] | None] = None
|
33
|
+
handler_kwargs: d.InitVar[dict[str, h.Any] | None] = None
|
34
|
+
|
35
|
+
def __post_init__(
|
36
|
+
self,
|
37
|
+
name: str | None,
|
38
|
+
level: int,
|
39
|
+
should_store_memory_usage: bool,
|
40
|
+
message_width: int,
|
41
|
+
formatter: lggg.Formatter | None,
|
42
|
+
path: path_t | None,
|
43
|
+
handler_args: tuple[h.Any, ...] | None,
|
44
|
+
handler_kwargs: dict[str, h.Any] | None,
|
45
|
+
) -> None:
|
46
|
+
""""""
|
47
|
+
lggg.FileHandler.__init__(self, path, *handler_args, **handler_kwargs)
|
48
|
+
|
49
|
+
self.extension = handler_extension_t(
|
50
|
+
name=name,
|
51
|
+
should_store_memory_usage=should_store_memory_usage,
|
52
|
+
handler=self,
|
53
|
+
level=level,
|
54
|
+
message_width=message_width,
|
55
|
+
formatter=formatter,
|
56
|
+
)
|
57
|
+
|
58
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
59
|
+
|
60
|
+
def emit(self, record: lggg.LogRecord, /) -> None:
|
61
|
+
""""""
|
62
|
+
if hasattr(record, SHOW_W_RULE_ATTR):
|
63
|
+
message = RuleAsText(record.msg)
|
64
|
+
else:
|
65
|
+
message = self.MessageFromRecord(record)
|
66
|
+
print(message, file=self.stream)
|
67
|
+
self.stream.flush()
|
68
|
+
|
69
|
+
def ShowMessage(self, message: str, /, *, indented: bool = False) -> None:
|
70
|
+
"""
|
71
|
+
See documentation of
|
72
|
+
logger_36.catalog.handler.generic.generic_handler_t.ShowMessage.
|
73
|
+
"""
|
74
|
+
if indented:
|
75
|
+
message = txt_.indent(message, LINE_INDENT)
|
76
|
+
print(message, file=self.stream)
|
77
|
+
self.stream.flush()
|
78
|
+
|
79
|
+
def DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
80
|
+
""""""
|
81
|
+
self.ShowMessage(RuleAsText(text))
|
82
|
+
|
83
|
+
|
84
|
+
"""
|
85
|
+
COPYRIGHT NOTICE
|
86
|
+
|
87
|
+
This software is governed by the CeCILL license under French law and
|
88
|
+
abiding by the rules of distribution of free software. You can use,
|
89
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
90
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
91
|
+
"http://www.cecill.info".
|
92
|
+
|
93
|
+
As a counterpart to the access to the source code and rights to copy,
|
94
|
+
modify and redistribute granted by the license, users are provided only
|
95
|
+
with a limited warranty and the software's author, the holder of the
|
96
|
+
economic rights, and the successive licensors have only limited
|
97
|
+
liability.
|
98
|
+
|
99
|
+
In this respect, the user's attention is drawn to the risks associated
|
100
|
+
with loading, using, modifying and/or developing or reproducing the
|
101
|
+
software by the user in light of its specific status of free software,
|
102
|
+
that may mean that it is complicated to manipulate, and that also
|
103
|
+
therefore means that it is reserved for developers and experienced
|
104
|
+
professionals having in-depth computer knowledge. Users are therefore
|
105
|
+
encouraged to load and test the software's suitability as regards their
|
106
|
+
requirements in conditions enabling the security of their systems and/or
|
107
|
+
data to be ensured and, more generally, to use and operate it in the
|
108
|
+
same conditions as regards security.
|
109
|
+
|
110
|
+
The fact that you are presently reading this means that you have had
|
111
|
+
knowledge of the CeCILL license and that you accept its terms.
|
112
|
+
|
113
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
114
|
+
|
115
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
116
|
+
member of team Morpheme.
|
117
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
118
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
119
|
+
I3S, and Laboratory iBV.
|
120
|
+
|
121
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
122
|
+
Inria: https://www.inria.fr/en/
|
123
|
+
UniCA: https://univ-cotedazur.eu/
|
124
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
125
|
+
I3S: https://www.i3s.unice.fr/en/
|
126
|
+
iBV: http://ibv.unice.fr/
|
127
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
128
|
+
"""
|
@@ -0,0 +1,230 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
8
|
+
import logging as lggg
|
9
|
+
import typing as h
|
10
|
+
|
11
|
+
try:
|
12
|
+
from logger_36.catalog.config.console_rich import DATE_TIME_COLOR
|
13
|
+
from logger_36.catalog.handler.console_rich import HighlightedVersion
|
14
|
+
from rich.console import Console as console_t # noqa
|
15
|
+
from rich.console import ConsoleOptions as console_options_t # noqa
|
16
|
+
from rich.markup import escape as EscapedForRich # noqa
|
17
|
+
from rich.terminal_theme import DEFAULT_TERMINAL_THEME # noqa
|
18
|
+
except ModuleNotFoundError:
|
19
|
+
console_t = console_options_t = EscapedForRich = DEFAULT_TERMINAL_THEME = None
|
20
|
+
|
21
|
+
from logger_36.constant.record import SHOW_W_RULE_ATTR
|
22
|
+
from logger_36.task.format.rule import Rule, RuleAsText
|
23
|
+
from logger_36.type.handler import handler_extension_t
|
24
|
+
|
25
|
+
|
26
|
+
@h.runtime_checkable
|
27
|
+
class show_message_p(h.Protocol):
|
28
|
+
def __call__(self, message: str, /, *, indented: bool = False) -> None: ...
|
29
|
+
|
30
|
+
|
31
|
+
@h.runtime_checkable
|
32
|
+
class display_rule_p(h.Protocol):
|
33
|
+
def __call__(self, /, *, text: str | None = None, color: str = "white") -> None: ...
|
34
|
+
|
35
|
+
|
36
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
37
|
+
class generic_handler_t(lggg.Handler):
|
38
|
+
"""
|
39
|
+
alternating_lines:
|
40
|
+
- Initial value:
|
41
|
+
- 1: enabled for dark background
|
42
|
+
- 2: enabled for light background
|
43
|
+
- anything else: disabled
|
44
|
+
- Runtime value: 0/1=do not/do highlight next time.
|
45
|
+
|
46
|
+
ShowMessage:
|
47
|
+
Log a message as is, i.e. without formatting. If this is a method, it should
|
48
|
+
contain the same call(s) as the final ones in the emit methods that are used to
|
49
|
+
output the formatted log messages. This means that there is some code
|
50
|
+
duplication, but it avoids a (maybe negligible) slowing down that would arise
|
51
|
+
from calling this method at the end of the emit methods.
|
52
|
+
Here, since, by definition, the generic handler does not know how to output
|
53
|
+
messages, it is a callable attribute that must be set at instantiation time, and
|
54
|
+
it is indeed called at the end of the emit method.
|
55
|
+
"""
|
56
|
+
|
57
|
+
ShowMessage: show_message_p
|
58
|
+
# "None -> h.Any" (twice below) since None | None is invalid.
|
59
|
+
console: console_t | h.Any = None
|
60
|
+
console_options: console_options_t | h.Any = None
|
61
|
+
alternating_lines: int = 0
|
62
|
+
background_is_light: bool = True
|
63
|
+
|
64
|
+
DisplayRule: display_rule_p = d.field(init=False)
|
65
|
+
extension: handler_extension_t = d.field(init=False)
|
66
|
+
MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
|
67
|
+
|
68
|
+
name: d.InitVar[str | None] = None
|
69
|
+
level: d.InitVar[int] = lggg.NOTSET
|
70
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
71
|
+
message_width: d.InitVar[int] = -1
|
72
|
+
formatter: d.InitVar[lggg.Formatter | None] = None
|
73
|
+
|
74
|
+
supports_html: d.InitVar[bool] = False
|
75
|
+
should_record: d.InitVar[bool] = False
|
76
|
+
rich_kwargs: d.InitVar[dict[str, h.Any] | None] = None
|
77
|
+
|
78
|
+
def __post_init__(
|
79
|
+
self,
|
80
|
+
name: str | None,
|
81
|
+
level: int,
|
82
|
+
should_store_memory_usage: bool,
|
83
|
+
message_width: int,
|
84
|
+
formatter: lggg.Formatter | None,
|
85
|
+
supports_html: bool,
|
86
|
+
should_record: bool,
|
87
|
+
rich_kwargs: dict[str, h.Any] | None,
|
88
|
+
) -> None:
|
89
|
+
""""""
|
90
|
+
lggg.Handler.__init__(self)
|
91
|
+
|
92
|
+
self.extension = handler_extension_t(
|
93
|
+
name=name,
|
94
|
+
should_store_memory_usage=should_store_memory_usage,
|
95
|
+
handler=self,
|
96
|
+
level=level,
|
97
|
+
message_width=message_width,
|
98
|
+
formatter=formatter,
|
99
|
+
)
|
100
|
+
|
101
|
+
if supports_html and (console_t is not None):
|
102
|
+
if rich_kwargs is None:
|
103
|
+
rich_kwargs = {}
|
104
|
+
self.console = console_t(
|
105
|
+
highlight=False,
|
106
|
+
force_terminal=True,
|
107
|
+
record=should_record,
|
108
|
+
**rich_kwargs,
|
109
|
+
)
|
110
|
+
self.console_options = self.console.options.update(
|
111
|
+
overflow="ignore", no_wrap=True
|
112
|
+
)
|
113
|
+
self.DisplayRule = self._DisplayRule
|
114
|
+
else:
|
115
|
+
self.DisplayRule = self._DisplayRuleAsText
|
116
|
+
|
117
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
118
|
+
if self.alternating_lines == 1:
|
119
|
+
self.alternating_lines = 0
|
120
|
+
self.background_is_light = False
|
121
|
+
elif self.alternating_lines == 2:
|
122
|
+
self.alternating_lines = 0
|
123
|
+
self.background_is_light = True
|
124
|
+
else:
|
125
|
+
self.alternating_lines = -1
|
126
|
+
|
127
|
+
def emit(self, record: lggg.LogRecord, /) -> None:
|
128
|
+
""""""
|
129
|
+
if self.console is None:
|
130
|
+
if hasattr(record, SHOW_W_RULE_ATTR):
|
131
|
+
message = RuleAsText(record.msg)
|
132
|
+
else:
|
133
|
+
message = self.MessageFromRecord(record)
|
134
|
+
else:
|
135
|
+
if hasattr(record, SHOW_W_RULE_ATTR):
|
136
|
+
richer = Rule(record.msg, DATE_TIME_COLOR)
|
137
|
+
else:
|
138
|
+
message = self.MessageFromRecord(record, PreProcessed=EscapedForRich)
|
139
|
+
should_highlight_back = self.alternating_lines == 1
|
140
|
+
if self.alternating_lines >= 0:
|
141
|
+
self.alternating_lines = (self.alternating_lines + 1) % 2
|
142
|
+
richer = HighlightedVersion(
|
143
|
+
self.console,
|
144
|
+
message,
|
145
|
+
record.levelno,
|
146
|
+
should_highlight_back=should_highlight_back,
|
147
|
+
background_is_light=self.background_is_light,
|
148
|
+
)
|
149
|
+
segments = self.console.render(richer, options=self.console_options)
|
150
|
+
|
151
|
+
# Inspired from the code of: rich.console.export_html.
|
152
|
+
html_segments = []
|
153
|
+
for text, style, _ in segments:
|
154
|
+
if text == "\n":
|
155
|
+
html_segments.append("\n")
|
156
|
+
else:
|
157
|
+
if style is not None:
|
158
|
+
style = style.get_html_style(DEFAULT_TERMINAL_THEME)
|
159
|
+
if (style is not None) and (style.__len__() > 0):
|
160
|
+
text = f'<span style="{style}">{text}</span>'
|
161
|
+
html_segments.append(text)
|
162
|
+
if html_segments[-1] == "\n":
|
163
|
+
html_segments = html_segments[:-1]
|
164
|
+
|
165
|
+
# /!\ For some reason, the widget splits the message into lines, place each
|
166
|
+
# line inside a pre tag, and set margin-bottom of the first and list lines
|
167
|
+
# to 12px. This can be seen by printing self.contents.toHtml(). To avoid the
|
168
|
+
# unwanted extra margins, margin-bottom is set to 0 below.
|
169
|
+
message = (
|
170
|
+
"<pre style='margin-bottom:0px'>" + "".join(html_segments) + "</pre>"
|
171
|
+
)
|
172
|
+
|
173
|
+
self.ShowMessage(message)
|
174
|
+
|
175
|
+
def _DisplayRuleAsText(
|
176
|
+
self, /, *, text: str | None = None, color: str = "white"
|
177
|
+
) -> None:
|
178
|
+
""""""
|
179
|
+
self.ShowMessage(RuleAsText(text))
|
180
|
+
|
181
|
+
def _DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
182
|
+
""""""
|
183
|
+
self.ShowMessage(Rule(text, color))
|
184
|
+
|
185
|
+
|
186
|
+
"""
|
187
|
+
COPYRIGHT NOTICE
|
188
|
+
|
189
|
+
This software is governed by the CeCILL license under French law and
|
190
|
+
abiding by the rules of distribution of free software. You can use,
|
191
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
192
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
193
|
+
"http://www.cecill.info".
|
194
|
+
|
195
|
+
As a counterpart to the access to the source code and rights to copy,
|
196
|
+
modify and redistribute granted by the license, users are provided only
|
197
|
+
with a limited warranty and the software's author, the holder of the
|
198
|
+
economic rights, and the successive licensors have only limited
|
199
|
+
liability.
|
200
|
+
|
201
|
+
In this respect, the user's attention is drawn to the risks associated
|
202
|
+
with loading, using, modifying and/or developing or reproducing the
|
203
|
+
software by the user in light of its specific status of free software,
|
204
|
+
that may mean that it is complicated to manipulate, and that also
|
205
|
+
therefore means that it is reserved for developers and experienced
|
206
|
+
professionals having in-depth computer knowledge. Users are therefore
|
207
|
+
encouraged to load and test the software's suitability as regards their
|
208
|
+
requirements in conditions enabling the security of their systems and/or
|
209
|
+
data to be ensured and, more generally, to use and operate it in the
|
210
|
+
same conditions as regards security.
|
211
|
+
|
212
|
+
The fact that you are presently reading this means that you have had
|
213
|
+
knowledge of the CeCILL license and that you accept its terms.
|
214
|
+
|
215
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
216
|
+
|
217
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
218
|
+
member of team Morpheme.
|
219
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
220
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
221
|
+
I3S, and Laboratory iBV.
|
222
|
+
|
223
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
224
|
+
Inria: https://www.inria.fr/en/
|
225
|
+
UniCA: https://univ-cotedazur.eu/
|
226
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
227
|
+
I3S: https://www.i3s.unice.fr/en/
|
228
|
+
iBV: http://ibv.unice.fr/
|
229
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
230
|
+
"""
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
from logger_36.instance.logger import LOGGER
|
8
|
+
from logger_36.task.measure.chronos import ElapsedTime
|
9
|
+
from logger_36.type.logger import logger_t
|
10
|
+
|
11
|
+
|
12
|
+
def LogElapsedTime(*, logger: logger_t = LOGGER) -> None:
|
13
|
+
""""""
|
14
|
+
logger.info(f"Elapsed Time: {ElapsedTime()}")
|
15
|
+
|
16
|
+
|
17
|
+
"""
|
18
|
+
COPYRIGHT NOTICE
|
19
|
+
|
20
|
+
This software is governed by the CeCILL license under French law and
|
21
|
+
abiding by the rules of distribution of free software. You can use,
|
22
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
23
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
24
|
+
"http://www.cecill.info".
|
25
|
+
|
26
|
+
As a counterpart to the access to the source code and rights to copy,
|
27
|
+
modify and redistribute granted by the license, users are provided only
|
28
|
+
with a limited warranty and the software's author, the holder of the
|
29
|
+
economic rights, and the successive licensors have only limited
|
30
|
+
liability.
|
31
|
+
|
32
|
+
In this respect, the user's attention is drawn to the risks associated
|
33
|
+
with loading, using, modifying and/or developing or reproducing the
|
34
|
+
software by the user in light of its specific status of free software,
|
35
|
+
that may mean that it is complicated to manipulate, and that also
|
36
|
+
therefore means that it is reserved for developers and experienced
|
37
|
+
professionals having in-depth computer knowledge. Users are therefore
|
38
|
+
encouraged to load and test the software's suitability as regards their
|
39
|
+
requirements in conditions enabling the security of their systems and/or
|
40
|
+
data to be ensured and, more generally, to use and operate it in the
|
41
|
+
same conditions as regards security.
|
42
|
+
|
43
|
+
The fact that you are presently reading this means that you have had
|
44
|
+
knowledge of the CeCILL license and that you accept its terms.
|
45
|
+
|
46
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
47
|
+
|
48
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
49
|
+
member of team Morpheme.
|
50
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
51
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
52
|
+
I3S, and Laboratory iBV.
|
53
|
+
|
54
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
55
|
+
Inria: https://www.inria.fr/en/
|
56
|
+
UniCA: https://univ-cotedazur.eu/
|
57
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
58
|
+
I3S: https://www.i3s.unice.fr/en/
|
59
|
+
iBV: http://ibv.unice.fr/
|
60
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
61
|
+
"""
|
@@ -0,0 +1,90 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import sys as sstm
|
8
|
+
|
9
|
+
from logger_36.constant.error import GPU_LOGGING_ERROR
|
10
|
+
from logger_36.instance.logger import LOGGER
|
11
|
+
from logger_36.type.logger import logger_t
|
12
|
+
|
13
|
+
try:
|
14
|
+
import tensorflow as tsfl # noqa
|
15
|
+
import tensorrt as tsrt # noqa
|
16
|
+
|
17
|
+
_GPU_LOGGING_ERROR = None
|
18
|
+
except ModuleNotFoundError:
|
19
|
+
tsfl = tsrt = None
|
20
|
+
_GPU_LOGGING_ERROR = GPU_LOGGING_ERROR
|
21
|
+
|
22
|
+
|
23
|
+
def LogGPURelatedDetails(*, logger: logger_t = LOGGER) -> None:
|
24
|
+
""""""
|
25
|
+
global _GPU_LOGGING_ERROR
|
26
|
+
|
27
|
+
if None in (tsfl, tsrt):
|
28
|
+
if _GPU_LOGGING_ERROR is not None:
|
29
|
+
print(_GPU_LOGGING_ERROR, file=sstm.stderr)
|
30
|
+
_GPU_LOGGING_ERROR = None
|
31
|
+
return
|
32
|
+
|
33
|
+
system_details = tsfl.sysconfig.get_build_info()
|
34
|
+
logger.info(
|
35
|
+
f"GPU-RELATED DETAILS\n"
|
36
|
+
f" GPUs: {tsfl.config.list_physical_devices('GPU')}\n"
|
37
|
+
f" CPUs: {tsfl.config.list_physical_devices('CPU')}\n"
|
38
|
+
f" Cuda: {system_details['cuda_version']}\n"
|
39
|
+
f" CuDNN: {system_details['cudnn_version']}\n"
|
40
|
+
f" Tensorflow: {tsfl.version.VERSION}\n"
|
41
|
+
f" Tensorflow Build: {tsfl.sysconfig.get_build_info()}\n"
|
42
|
+
f" TensorRT: {tsrt.__version__}",
|
43
|
+
)
|
44
|
+
|
45
|
+
|
46
|
+
"""
|
47
|
+
COPYRIGHT NOTICE
|
48
|
+
|
49
|
+
This software is governed by the CeCILL license under French law and
|
50
|
+
abiding by the rules of distribution of free software. You can use,
|
51
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
52
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
53
|
+
"http://www.cecill.info".
|
54
|
+
|
55
|
+
As a counterpart to the access to the source code and rights to copy,
|
56
|
+
modify and redistribute granted by the license, users are provided only
|
57
|
+
with a limited warranty and the software's author, the holder of the
|
58
|
+
economic rights, and the successive licensors have only limited
|
59
|
+
liability.
|
60
|
+
|
61
|
+
In this respect, the user's attention is drawn to the risks associated
|
62
|
+
with loading, using, modifying and/or developing or reproducing the
|
63
|
+
software by the user in light of its specific status of free software,
|
64
|
+
that may mean that it is complicated to manipulate, and that also
|
65
|
+
therefore means that it is reserved for developers and experienced
|
66
|
+
professionals having in-depth computer knowledge. Users are therefore
|
67
|
+
encouraged to load and test the software's suitability as regards their
|
68
|
+
requirements in conditions enabling the security of their systems and/or
|
69
|
+
data to be ensured and, more generally, to use and operate it in the
|
70
|
+
same conditions as regards security.
|
71
|
+
|
72
|
+
The fact that you are presently reading this means that you have had
|
73
|
+
knowledge of the CeCILL license and that you accept its terms.
|
74
|
+
|
75
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
76
|
+
|
77
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
78
|
+
member of team Morpheme.
|
79
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
80
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
81
|
+
I3S, and Laboratory iBV.
|
82
|
+
|
83
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
84
|
+
Inria: https://www.inria.fr/en/
|
85
|
+
UniCA: https://univ-cotedazur.eu/
|
86
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
87
|
+
I3S: https://www.i3s.unice.fr/en/
|
88
|
+
iBV: http://ibv.unice.fr/
|
89
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
90
|
+
"""
|
@@ -0,0 +1,129 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
from logger_36.config.memory import LENGTH_100, MAX_N_SAMPLES
|
8
|
+
from logger_36.constant.memory import storage_units_h
|
9
|
+
from logger_36.instance.logger import LOGGER
|
10
|
+
from logger_36.task.format.memory import FormattedUsage, UsageBar
|
11
|
+
from logger_36.task.format.message import MessageWithActualExpected
|
12
|
+
from logger_36.type.logger import logger_t
|
13
|
+
|
14
|
+
|
15
|
+
def LogMemoryUsages(
|
16
|
+
*,
|
17
|
+
unit: storage_units_h | None = "a",
|
18
|
+
decimals: int = None,
|
19
|
+
max_n_samples: int | None = MAX_N_SAMPLES,
|
20
|
+
length_100: int = LENGTH_100,
|
21
|
+
logger: logger_t = LOGGER,
|
22
|
+
) -> None:
|
23
|
+
""""""
|
24
|
+
if not logger.any_handler_stores_memory:
|
25
|
+
return
|
26
|
+
|
27
|
+
where_s, usages = zip(*logger.memory_usages)
|
28
|
+
|
29
|
+
where, max_usage = logger.max_memory_usage_full
|
30
|
+
value, unit = FormattedUsage(max_usage, unit=unit, decimals=decimals)
|
31
|
+
title = f"Memory Usage: Max={value}{unit} near {where}\n"
|
32
|
+
|
33
|
+
if isinstance(max_n_samples, int):
|
34
|
+
if max_n_samples < 1:
|
35
|
+
raise ValueError(
|
36
|
+
MessageWithActualExpected(
|
37
|
+
"Invalid maximum number of samples",
|
38
|
+
actual=max_n_samples,
|
39
|
+
expected=1,
|
40
|
+
expected_op=">=",
|
41
|
+
)
|
42
|
+
)
|
43
|
+
|
44
|
+
where_s = list(where_s)
|
45
|
+
usages = list(usages)
|
46
|
+
while usages.__len__() > max_n_samples:
|
47
|
+
index = usages.index(min(usages))
|
48
|
+
del where_s[index]
|
49
|
+
del usages[index]
|
50
|
+
|
51
|
+
usages = tuple(round(_elm, 1) for _elm in usages)
|
52
|
+
max_usage = max(usages)
|
53
|
+
|
54
|
+
plot = []
|
55
|
+
max_where_length = max(map(len, where_s))
|
56
|
+
usages_as_str = tuple(map(lambda _elm: f"{_elm:_}", usages))
|
57
|
+
max_usage_length = max(map(len, usages_as_str))
|
58
|
+
for where, usage, usage_as_str in zip(where_s, usages, usages_as_str):
|
59
|
+
bar = UsageBar(usage, max_usage, length_100=length_100)
|
60
|
+
plot.append(
|
61
|
+
f"{where:{max_where_length}} "
|
62
|
+
f"{bar:{length_100}} "
|
63
|
+
f"{usage_as_str: >{max_usage_length}}"
|
64
|
+
)
|
65
|
+
plot = "\n".join(plot)
|
66
|
+
|
67
|
+
logger.info(title + plot)
|
68
|
+
|
69
|
+
|
70
|
+
def LogMaximumMemoryUsage(
|
71
|
+
*,
|
72
|
+
unit: storage_units_h | None = "a",
|
73
|
+
decimals: int | None = None,
|
74
|
+
logger: logger_t = LOGGER,
|
75
|
+
) -> None:
|
76
|
+
"""
|
77
|
+
unit: b or None=bytes, k=kilo, m=mega, g=giga, a=auto
|
78
|
+
"""
|
79
|
+
if logger.any_handler_stores_memory:
|
80
|
+
where, max_usage = logger.max_memory_usage_full
|
81
|
+
value, unit = FormattedUsage(max_usage, unit=unit, decimals=decimals)
|
82
|
+
logger.info(f"Max. Memory Usage: {value}{unit} near {where}")
|
83
|
+
|
84
|
+
|
85
|
+
"""
|
86
|
+
COPYRIGHT NOTICE
|
87
|
+
|
88
|
+
This software is governed by the CeCILL license under French law and
|
89
|
+
abiding by the rules of distribution of free software. You can use,
|
90
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
91
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
92
|
+
"http://www.cecill.info".
|
93
|
+
|
94
|
+
As a counterpart to the access to the source code and rights to copy,
|
95
|
+
modify and redistribute granted by the license, users are provided only
|
96
|
+
with a limited warranty and the software's author, the holder of the
|
97
|
+
economic rights, and the successive licensors have only limited
|
98
|
+
liability.
|
99
|
+
|
100
|
+
In this respect, the user's attention is drawn to the risks associated
|
101
|
+
with loading, using, modifying and/or developing or reproducing the
|
102
|
+
software by the user in light of its specific status of free software,
|
103
|
+
that may mean that it is complicated to manipulate, and that also
|
104
|
+
therefore means that it is reserved for developers and experienced
|
105
|
+
professionals having in-depth computer knowledge. Users are therefore
|
106
|
+
encouraged to load and test the software's suitability as regards their
|
107
|
+
requirements in conditions enabling the security of their systems and/or
|
108
|
+
data to be ensured and, more generally, to use and operate it in the
|
109
|
+
same conditions as regards security.
|
110
|
+
|
111
|
+
The fact that you are presently reading this means that you have had
|
112
|
+
knowledge of the CeCILL license and that you accept its terms.
|
113
|
+
|
114
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
115
|
+
|
116
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
117
|
+
member of team Morpheme.
|
118
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
119
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
120
|
+
I3S, and Laboratory iBV.
|
121
|
+
|
122
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
123
|
+
Inria: https://www.inria.fr/en/
|
124
|
+
UniCA: https://univ-cotedazur.eu/
|
125
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
126
|
+
I3S: https://www.i3s.unice.fr/en/
|
127
|
+
iBV: http://ibv.unice.fr/
|
128
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
129
|
+
"""
|