logger-36 2023.13__py3-none-any.whl → 2025.3__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. logger_36/__init__.py +65 -41
  2. logger_36/api/logger.py +53 -0
  3. logger_36/api/storage.py +53 -0
  4. logger_36/catalog/config/console_rich.py +76 -0
  5. logger_36/catalog/handler/console.py +117 -0
  6. logger_36/catalog/handler/console_rich.py +235 -0
  7. logger_36/catalog/handler/file.py +128 -0
  8. logger_36/catalog/handler/generic.py +228 -0
  9. logger_36/catalog/logger/chronos.py +61 -0
  10. logger_36/catalog/logger/gpu.py +90 -0
  11. logger_36/catalog/logger/memory.py +129 -0
  12. logger_36/catalog/logger/system.py +84 -0
  13. logger_36/config/issue.py +56 -0
  14. logger_36/config/logger.py +103 -0
  15. logger_36/config/memory.py +54 -0
  16. logger_36/config/message.py +66 -0
  17. logger_36/config/system.py +70 -0
  18. logger_36/constant/error.py +70 -0
  19. logger_36/constant/generic.py +58 -0
  20. logger_36/constant/handler.py +58 -0
  21. logger_36/constant/issue.py +58 -0
  22. logger_36/constant/logger.py +67 -0
  23. logger_36/constant/memory.py +58 -0
  24. logger_36/constant/message.py +72 -0
  25. logger_36/constant/record.py +55 -0
  26. logger_36/constant/system.py +60 -0
  27. logger_36/content.py +55 -0
  28. logger_36/exception.py +105 -0
  29. logger_36/gpu.py +53 -0
  30. logger_36/handler.py +209 -0
  31. logger_36/instance/logger.py +55 -0
  32. logger_36/instance/loggers.py +56 -0
  33. logger_36/memory.py +60 -0
  34. logger_36/storage.py +53 -0
  35. logger_36/system.py +53 -0
  36. logger_36/task/format/memory.py +132 -0
  37. logger_36/task/format/message.py +111 -0
  38. logger_36/task/format/rule.py +74 -0
  39. logger_36/task/inspection.py +70 -48
  40. logger_36/task/measure/chronos.py +84 -0
  41. logger_36/task/measure/memory.py +72 -0
  42. logger_36/task/storage.py +164 -0
  43. logger_36/time.py +54 -0
  44. logger_36/type/handler.py +184 -0
  45. logger_36/type/issue.py +91 -0
  46. logger_36/type/logger.py +542 -0
  47. logger_36/type/loggers.py +78 -0
  48. logger_36/version.py +53 -32
  49. logger_36-2025.3.dist-info/METADATA +154 -0
  50. logger_36-2025.3.dist-info/RECORD +52 -0
  51. {logger_36-2023.13.dist-info → logger_36-2025.3.dist-info}/WHEEL +1 -1
  52. logger_36/config.py +0 -66
  53. logger_36/constant.py +0 -57
  54. logger_36/main.py +0 -185
  55. logger_36/measure/chronos.py +0 -55
  56. logger_36/measure/memory.py +0 -102
  57. logger_36/type/console.py +0 -122
  58. logger_36/type/extension.py +0 -122
  59. logger_36/type/file.py +0 -52
  60. logger_36/type/generic.py +0 -116
  61. logger_36-2023.13.dist-info/METADATA +0 -106
  62. logger_36-2023.13.dist-info/RECORD +0 -16
  63. {logger_36-2023.13.dist-info → logger_36-2025.3.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,228 @@
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
+ class show_message_p(h.Protocol):
27
+ def __call__(self, message: str, /, *, indented: bool = False) -> None: ...
28
+
29
+
30
+ class display_rule_p(h.Protocol):
31
+ def __call__(self, /, *, text: str | None = None, color: str = "white") -> None: ...
32
+
33
+
34
+ @d.dataclass(slots=True, repr=False, eq=False)
35
+ class generic_handler_t(lggg.Handler):
36
+ """
37
+ alternating_lines:
38
+ - Initial value:
39
+ - 1: enabled for dark background
40
+ - 2: enabled for light background
41
+ - anything else: disabled
42
+ - Runtime value: 0/1=do not/do highlight next time.
43
+
44
+ ShowMessage:
45
+ Log a message as is, i.e. without formatting. If this is a method, it should
46
+ contain the same call(s) as the final ones in the emit methods that are used to
47
+ output the formatted log messages. This means that there is some code
48
+ duplication, but it avoids a (maybe negligible) slowing down that would arise
49
+ from calling this method at the end of the emit methods.
50
+ Here, since, by definition, the generic handler does not know how to output
51
+ messages, it is a callable attribute that must be set at instantiation time, and
52
+ it is indeed called at the end of the emit method.
53
+ """
54
+
55
+ ShowMessage: show_message_p
56
+ # "None -> h.Any" (twice below) since None | None is invalid.
57
+ console: console_t | h.Any = None
58
+ console_options: console_options_t | h.Any = None
59
+ alternating_lines: int = 0
60
+ background_is_light: bool = True
61
+
62
+ DisplayRule: display_rule_p = d.field(init=False)
63
+ extension: handler_extension_t = d.field(init=False)
64
+ MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
65
+
66
+ name: d.InitVar[str | None] = None
67
+ level: d.InitVar[int] = lggg.NOTSET
68
+ should_store_memory_usage: d.InitVar[bool] = False
69
+ message_width: d.InitVar[int] = -1
70
+ formatter: d.InitVar[lggg.Formatter | None] = None
71
+
72
+ supports_html: d.InitVar[bool] = False
73
+ should_record: d.InitVar[bool] = False
74
+ rich_kwargs: d.InitVar[dict[str, h.Any] | None] = None
75
+
76
+ def __post_init__(
77
+ self,
78
+ name: str | None,
79
+ level: int,
80
+ should_store_memory_usage: bool,
81
+ message_width: int,
82
+ formatter: lggg.Formatter | None,
83
+ supports_html: bool,
84
+ should_record: bool,
85
+ rich_kwargs: dict[str, h.Any] | None,
86
+ ) -> None:
87
+ """"""
88
+ lggg.Handler.__init__(self)
89
+
90
+ self.extension = handler_extension_t(
91
+ name=name,
92
+ should_store_memory_usage=should_store_memory_usage,
93
+ handler=self,
94
+ level=level,
95
+ message_width=message_width,
96
+ formatter=formatter,
97
+ )
98
+
99
+ if supports_html and (console_t is not None):
100
+ if rich_kwargs is None:
101
+ rich_kwargs = {}
102
+ self.console = console_t(
103
+ highlight=False,
104
+ force_terminal=True,
105
+ record=should_record,
106
+ **rich_kwargs,
107
+ )
108
+ self.console_options = self.console.options.update(
109
+ overflow="ignore", no_wrap=True
110
+ )
111
+ self.DisplayRule = self._DisplayRule
112
+ else:
113
+ self.DisplayRule = self._DisplayRuleAsText
114
+
115
+ self.MessageFromRecord = self.extension.MessageFromRecord
116
+ if self.alternating_lines == 1:
117
+ self.alternating_lines = 0
118
+ self.background_is_light = False
119
+ elif self.alternating_lines == 2:
120
+ self.alternating_lines = 0
121
+ self.background_is_light = True
122
+ else:
123
+ self.alternating_lines = -1
124
+
125
+ def emit(self, record: lggg.LogRecord, /) -> None:
126
+ """"""
127
+ if self.console is None:
128
+ if hasattr(record, SHOW_W_RULE_ATTR):
129
+ message = RuleAsText(record.msg)
130
+ else:
131
+ message = self.MessageFromRecord(record)
132
+ else:
133
+ if hasattr(record, SHOW_W_RULE_ATTR):
134
+ richer = Rule(record.msg, DATE_TIME_COLOR)
135
+ else:
136
+ message = self.MessageFromRecord(record, PreProcessed=EscapedForRich)
137
+ should_highlight_back = self.alternating_lines == 1
138
+ if self.alternating_lines >= 0:
139
+ self.alternating_lines = (self.alternating_lines + 1) % 2
140
+ richer = HighlightedVersion(
141
+ self.console,
142
+ message,
143
+ record.levelno,
144
+ should_highlight_back=should_highlight_back,
145
+ background_is_light=self.background_is_light,
146
+ )
147
+ segments = self.console.render(richer, options=self.console_options)
148
+
149
+ # Inspired from the code of: rich.console.export_html.
150
+ html_segments = []
151
+ for text, style, _ in segments:
152
+ if text == "\n":
153
+ html_segments.append("\n")
154
+ else:
155
+ if style is not None:
156
+ style = style.get_html_style(DEFAULT_TERMINAL_THEME)
157
+ if (style is not None) and (style.__len__() > 0):
158
+ text = f'<span style="{style}">{text}</span>'
159
+ html_segments.append(text)
160
+ if html_segments[-1] == "\n":
161
+ html_segments = html_segments[:-1]
162
+
163
+ # /!\ For some reason, the widget splits the message into lines, place each
164
+ # line inside a pre tag, and set margin-bottom of the first and list lines
165
+ # to 12px. This can be seen by printing self.contents.toHtml(). To avoid the
166
+ # unwanted extra margins, margin-bottom is set to 0 below.
167
+ message = (
168
+ "<pre style='margin-bottom:0px'>" + "".join(html_segments) + "</pre>"
169
+ )
170
+
171
+ self.ShowMessage(message)
172
+
173
+ def _DisplayRuleAsText(
174
+ self, /, *, text: str | None = None, color: str = "white"
175
+ ) -> None:
176
+ """"""
177
+ self.ShowMessage(RuleAsText(text))
178
+
179
+ def _DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
180
+ """"""
181
+ self.ShowMessage(Rule(text, color))
182
+
183
+
184
+ """
185
+ COPYRIGHT NOTICE
186
+
187
+ This software is governed by the CeCILL license under French law and
188
+ abiding by the rules of distribution of free software. You can use,
189
+ modify and/ or redistribute the software under the terms of the CeCILL
190
+ license as circulated by CEA, CNRS and INRIA at the following URL
191
+ "http://www.cecill.info".
192
+
193
+ As a counterpart to the access to the source code and rights to copy,
194
+ modify and redistribute granted by the license, users are provided only
195
+ with a limited warranty and the software's author, the holder of the
196
+ economic rights, and the successive licensors have only limited
197
+ liability.
198
+
199
+ In this respect, the user's attention is drawn to the risks associated
200
+ with loading, using, modifying and/or developing or reproducing the
201
+ software by the user in light of its specific status of free software,
202
+ that may mean that it is complicated to manipulate, and that also
203
+ therefore means that it is reserved for developers and experienced
204
+ professionals having in-depth computer knowledge. Users are therefore
205
+ encouraged to load and test the software's suitability as regards their
206
+ requirements in conditions enabling the security of their systems and/or
207
+ data to be ensured and, more generally, to use and operate it in the
208
+ same conditions as regards security.
209
+
210
+ The fact that you are presently reading this means that you have had
211
+ knowledge of the CeCILL license and that you accept its terms.
212
+
213
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
214
+
215
+ This software is being developed by Eric Debreuve, a CNRS employee and
216
+ member of team Morpheme.
217
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
218
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
219
+ I3S, and Laboratory iBV.
220
+
221
+ CNRS: https://www.cnrs.fr/index.php/en
222
+ Inria: https://www.inria.fr/en/
223
+ UniCA: https://univ-cotedazur.eu/
224
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
225
+ I3S: https://www.i3s.unice.fr/en/
226
+ iBV: http://ibv.unice.fr/
227
+ Team Morpheme: https://team.inria.fr/morpheme/
228
+ """
@@ -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
+ """