cars 1.0.0rc1__cp313-cp313-musllinux_1_2_i686.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.
Potentially problematic release.
This version of cars might be problematic. Click here for more details.
- cars/__init__.py +74 -0
- cars/applications/__init__.py +37 -0
- cars/applications/application.py +117 -0
- cars/applications/application_constants.py +29 -0
- cars/applications/application_template.py +146 -0
- cars/applications/auxiliary_filling/__init__.py +29 -0
- cars/applications/auxiliary_filling/abstract_auxiliary_filling_app.py +104 -0
- cars/applications/auxiliary_filling/auxiliary_filling_algo.py +475 -0
- cars/applications/auxiliary_filling/auxiliary_filling_from_sensors_app.py +630 -0
- cars/applications/auxiliary_filling/auxiliary_filling_wrappers.py +90 -0
- cars/applications/dem_generation/__init__.py +30 -0
- cars/applications/dem_generation/abstract_dem_generation_app.py +116 -0
- cars/applications/dem_generation/bulldozer_config/base_config.yaml +42 -0
- cars/applications/dem_generation/bulldozer_dem_app.py +655 -0
- cars/applications/dem_generation/bulldozer_memory.py +55 -0
- cars/applications/dem_generation/dem_generation_algo.py +107 -0
- cars/applications/dem_generation/dem_generation_constants.py +32 -0
- cars/applications/dem_generation/dem_generation_wrappers.py +323 -0
- cars/applications/dense_match_filling/__init__.py +30 -0
- cars/applications/dense_match_filling/abstract_dense_match_filling_app.py +242 -0
- cars/applications/dense_match_filling/fill_disp_algo.py +113 -0
- cars/applications/dense_match_filling/fill_disp_constants.py +39 -0
- cars/applications/dense_match_filling/fill_disp_wrappers.py +83 -0
- cars/applications/dense_match_filling/zero_padding_app.py +302 -0
- cars/applications/dense_matching/__init__.py +30 -0
- cars/applications/dense_matching/abstract_dense_matching_app.py +261 -0
- cars/applications/dense_matching/census_mccnn_sgm_app.py +1460 -0
- cars/applications/dense_matching/cpp/__init__.py +0 -0
- cars/applications/dense_matching/cpp/dense_matching_cpp.cpython-313-i386-linux-musl.so +0 -0
- cars/applications/dense_matching/cpp/dense_matching_cpp.py +94 -0
- cars/applications/dense_matching/cpp/includes/dense_matching.hpp +58 -0
- cars/applications/dense_matching/cpp/meson.build +9 -0
- cars/applications/dense_matching/cpp/src/bindings.cpp +13 -0
- cars/applications/dense_matching/cpp/src/dense_matching.cpp +207 -0
- cars/applications/dense_matching/dense_matching_algo.py +401 -0
- cars/applications/dense_matching/dense_matching_constants.py +89 -0
- cars/applications/dense_matching/dense_matching_wrappers.py +951 -0
- cars/applications/dense_matching/disparity_grid_algo.py +588 -0
- cars/applications/dense_matching/loaders/__init__.py +23 -0
- cars/applications/dense_matching/loaders/config_census_sgm_default.json +31 -0
- cars/applications/dense_matching/loaders/config_census_sgm_homogeneous.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_mountain_and_vegetation.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_shadow.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_sparse.json +36 -0
- cars/applications/dense_matching/loaders/config_census_sgm_urban.json +30 -0
- cars/applications/dense_matching/loaders/config_mapping.json +13 -0
- cars/applications/dense_matching/loaders/config_mccnn.json +28 -0
- cars/applications/dense_matching/loaders/global_land_cover_map.tif +0 -0
- cars/applications/dense_matching/loaders/pandora_loader.py +593 -0
- cars/applications/dsm_filling/__init__.py +32 -0
- cars/applications/dsm_filling/abstract_dsm_filling_app.py +101 -0
- cars/applications/dsm_filling/border_interpolation_app.py +270 -0
- cars/applications/dsm_filling/bulldozer_config/base_config.yaml +44 -0
- cars/applications/dsm_filling/bulldozer_filling_app.py +279 -0
- cars/applications/dsm_filling/exogenous_filling_app.py +333 -0
- cars/applications/grid_generation/__init__.py +30 -0
- cars/applications/grid_generation/abstract_grid_generation_app.py +142 -0
- cars/applications/grid_generation/epipolar_grid_generation_app.py +327 -0
- cars/applications/grid_generation/grid_correction_app.py +496 -0
- cars/applications/grid_generation/grid_generation_algo.py +388 -0
- cars/applications/grid_generation/grid_generation_constants.py +46 -0
- cars/applications/grid_generation/transform_grid.py +88 -0
- cars/applications/ground_truth_reprojection/__init__.py +30 -0
- cars/applications/ground_truth_reprojection/abstract_ground_truth_reprojection_app.py +137 -0
- cars/applications/ground_truth_reprojection/direct_localization_app.py +629 -0
- cars/applications/ground_truth_reprojection/ground_truth_reprojection_algo.py +275 -0
- cars/applications/point_cloud_outlier_removal/__init__.py +30 -0
- cars/applications/point_cloud_outlier_removal/abstract_outlier_removal_app.py +385 -0
- cars/applications/point_cloud_outlier_removal/outlier_removal_algo.py +392 -0
- cars/applications/point_cloud_outlier_removal/outlier_removal_constants.py +43 -0
- cars/applications/point_cloud_outlier_removal/small_components_app.py +527 -0
- cars/applications/point_cloud_outlier_removal/statistical_app.py +531 -0
- cars/applications/rasterization/__init__.py +30 -0
- cars/applications/rasterization/abstract_pc_rasterization_app.py +183 -0
- cars/applications/rasterization/rasterization_algo.py +534 -0
- cars/applications/rasterization/rasterization_constants.py +38 -0
- cars/applications/rasterization/rasterization_wrappers.py +634 -0
- cars/applications/rasterization/simple_gaussian_app.py +1152 -0
- cars/applications/resampling/__init__.py +28 -0
- cars/applications/resampling/abstract_resampling_app.py +187 -0
- cars/applications/resampling/bicubic_resampling_app.py +762 -0
- cars/applications/resampling/resampling_algo.py +614 -0
- cars/applications/resampling/resampling_constants.py +36 -0
- cars/applications/resampling/resampling_wrappers.py +309 -0
- cars/applications/sparse_matching/__init__.py +30 -0
- cars/applications/sparse_matching/abstract_sparse_matching_app.py +498 -0
- cars/applications/sparse_matching/sift_app.py +735 -0
- cars/applications/sparse_matching/sparse_matching_algo.py +360 -0
- cars/applications/sparse_matching/sparse_matching_constants.py +68 -0
- cars/applications/sparse_matching/sparse_matching_wrappers.py +238 -0
- cars/applications/triangulation/__init__.py +32 -0
- cars/applications/triangulation/abstract_triangulation_app.py +227 -0
- cars/applications/triangulation/line_of_sight_intersection_app.py +1243 -0
- cars/applications/triangulation/pc_transform.py +552 -0
- cars/applications/triangulation/triangulation_algo.py +371 -0
- cars/applications/triangulation/triangulation_constants.py +38 -0
- cars/applications/triangulation/triangulation_wrappers.py +259 -0
- cars/bundleadjustment.py +757 -0
- cars/cars.py +177 -0
- cars/conf/__init__.py +23 -0
- cars/conf/geoid/egm96.grd +0 -0
- cars/conf/geoid/egm96.grd.hdr +15 -0
- cars/conf/input_parameters.py +156 -0
- cars/conf/mask_cst.py +35 -0
- cars/core/__init__.py +23 -0
- cars/core/cars_logging.py +402 -0
- cars/core/constants.py +191 -0
- cars/core/constants_disparity.py +50 -0
- cars/core/datasets.py +140 -0
- cars/core/geometry/__init__.py +27 -0
- cars/core/geometry/abstract_geometry.py +1119 -0
- cars/core/geometry/shareloc_geometry.py +598 -0
- cars/core/inputs.py +568 -0
- cars/core/outputs.py +176 -0
- cars/core/preprocessing.py +722 -0
- cars/core/projection.py +843 -0
- cars/core/roi_tools.py +215 -0
- cars/core/tiling.py +774 -0
- cars/core/utils.py +164 -0
- cars/data_structures/__init__.py +23 -0
- cars/data_structures/cars_dataset.py +1541 -0
- cars/data_structures/cars_dict.py +74 -0
- cars/data_structures/corresponding_tiles_tools.py +186 -0
- cars/data_structures/dataframe_converter.py +185 -0
- cars/data_structures/format_transformation.py +297 -0
- cars/devibrate.py +689 -0
- cars/extractroi.py +264 -0
- cars/orchestrator/__init__.py +23 -0
- cars/orchestrator/achievement_tracker.py +125 -0
- cars/orchestrator/cluster/__init__.py +37 -0
- cars/orchestrator/cluster/abstract_cluster.py +244 -0
- cars/orchestrator/cluster/abstract_dask_cluster.py +375 -0
- cars/orchestrator/cluster/dask_cluster_tools.py +103 -0
- cars/orchestrator/cluster/dask_config/README.md +94 -0
- cars/orchestrator/cluster/dask_config/dask.yaml +21 -0
- cars/orchestrator/cluster/dask_config/distributed.yaml +70 -0
- cars/orchestrator/cluster/dask_config/jobqueue.yaml +26 -0
- cars/orchestrator/cluster/dask_config/reference_confs/dask-schema.yaml +137 -0
- cars/orchestrator/cluster/dask_config/reference_confs/dask.yaml +26 -0
- cars/orchestrator/cluster/dask_config/reference_confs/distributed-schema.yaml +1009 -0
- cars/orchestrator/cluster/dask_config/reference_confs/distributed.yaml +273 -0
- cars/orchestrator/cluster/dask_config/reference_confs/jobqueue.yaml +212 -0
- cars/orchestrator/cluster/dask_jobqueue_utils.py +204 -0
- cars/orchestrator/cluster/local_dask_cluster.py +116 -0
- cars/orchestrator/cluster/log_wrapper.py +1075 -0
- cars/orchestrator/cluster/mp_cluster/__init__.py +27 -0
- cars/orchestrator/cluster/mp_cluster/mp_factorizer.py +212 -0
- cars/orchestrator/cluster/mp_cluster/mp_objects.py +535 -0
- cars/orchestrator/cluster/mp_cluster/mp_tools.py +93 -0
- cars/orchestrator/cluster/mp_cluster/mp_wrapper.py +505 -0
- cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py +873 -0
- cars/orchestrator/cluster/mp_cluster/multiprocessing_profiler.py +399 -0
- cars/orchestrator/cluster/pbs_dask_cluster.py +207 -0
- cars/orchestrator/cluster/sequential_cluster.py +139 -0
- cars/orchestrator/cluster/slurm_dask_cluster.py +234 -0
- cars/orchestrator/orchestrator.py +905 -0
- cars/orchestrator/orchestrator_constants.py +29 -0
- cars/orchestrator/registry/__init__.py +23 -0
- cars/orchestrator/registry/abstract_registry.py +143 -0
- cars/orchestrator/registry/compute_registry.py +106 -0
- cars/orchestrator/registry/id_generator.py +116 -0
- cars/orchestrator/registry/replacer_registry.py +213 -0
- cars/orchestrator/registry/saver_registry.py +363 -0
- cars/orchestrator/registry/unseen_registry.py +118 -0
- cars/orchestrator/tiles_profiler.py +279 -0
- cars/pipelines/__init__.py +26 -0
- cars/pipelines/conf_resolution/conf_final_resolution.yaml +5 -0
- cars/pipelines/conf_resolution/conf_first_resolution.yaml +2 -0
- cars/pipelines/conf_resolution/conf_intermediate_resolution.yaml +2 -0
- cars/pipelines/default/__init__.py +26 -0
- cars/pipelines/default/default_pipeline.py +786 -0
- cars/pipelines/parameters/__init__.py +0 -0
- cars/pipelines/parameters/advanced_parameters.py +417 -0
- cars/pipelines/parameters/advanced_parameters_constants.py +69 -0
- cars/pipelines/parameters/application_parameters.py +71 -0
- cars/pipelines/parameters/depth_map_inputs.py +0 -0
- cars/pipelines/parameters/dsm_inputs.py +918 -0
- cars/pipelines/parameters/dsm_inputs_constants.py +25 -0
- cars/pipelines/parameters/output_constants.py +52 -0
- cars/pipelines/parameters/output_parameters.py +454 -0
- cars/pipelines/parameters/sensor_inputs.py +842 -0
- cars/pipelines/parameters/sensor_inputs_constants.py +49 -0
- cars/pipelines/parameters/sensor_loaders/__init__.py +29 -0
- cars/pipelines/parameters/sensor_loaders/basic_classif_loader.py +86 -0
- cars/pipelines/parameters/sensor_loaders/basic_image_loader.py +98 -0
- cars/pipelines/parameters/sensor_loaders/pivot_classif_loader.py +90 -0
- cars/pipelines/parameters/sensor_loaders/pivot_image_loader.py +105 -0
- cars/pipelines/parameters/sensor_loaders/sensor_loader.py +93 -0
- cars/pipelines/parameters/sensor_loaders/sensor_loader_template.py +71 -0
- cars/pipelines/parameters/sensor_loaders/slurp_classif_loader.py +86 -0
- cars/pipelines/pipeline.py +119 -0
- cars/pipelines/pipeline_constants.py +31 -0
- cars/pipelines/pipeline_template.py +139 -0
- cars/pipelines/unit/__init__.py +26 -0
- cars/pipelines/unit/unit_pipeline.py +2850 -0
- cars/starter.py +167 -0
- cars-1.0.0rc1.dist-info/METADATA +292 -0
- cars-1.0.0rc1.dist-info/RECORD +202 -0
- cars-1.0.0rc1.dist-info/WHEEL +5 -0
- cars-1.0.0rc1.dist-info/entry_points.txt +8 -0
- cars.libs/libgcc_s-1257a076.so.1 +0 -0
- cars.libs/libstdc++-0530927c.so.6.0.32 +0 -0
|
@@ -0,0 +1,1075 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf8
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
|
|
5
|
+
#
|
|
6
|
+
# This file is part of CARS
|
|
7
|
+
# (see https://github.com/CNES/cars).
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
"""
|
|
22
|
+
Contains functions for wrapper logs
|
|
23
|
+
"""
|
|
24
|
+
# pylint: disable=C0302
|
|
25
|
+
|
|
26
|
+
import copy
|
|
27
|
+
import cProfile
|
|
28
|
+
import datetime
|
|
29
|
+
import functools
|
|
30
|
+
import gc
|
|
31
|
+
import io
|
|
32
|
+
import logging
|
|
33
|
+
import os
|
|
34
|
+
import pstats
|
|
35
|
+
import shutil
|
|
36
|
+
import time
|
|
37
|
+
import uuid
|
|
38
|
+
from abc import ABCMeta, abstractmethod
|
|
39
|
+
from importlib import import_module
|
|
40
|
+
from multiprocessing import Pipe
|
|
41
|
+
from threading import Thread
|
|
42
|
+
|
|
43
|
+
import matplotlib.pyplot as plt
|
|
44
|
+
import numpy as np
|
|
45
|
+
import pandas as pd
|
|
46
|
+
import psutil
|
|
47
|
+
from json_checker import Checker
|
|
48
|
+
from matplotlib.backends.backend_pdf import PdfPages
|
|
49
|
+
from PIL import Image
|
|
50
|
+
|
|
51
|
+
from cars.core import cars_logging
|
|
52
|
+
from cars.core.utils import safe_makedirs
|
|
53
|
+
|
|
54
|
+
THREAD_TIMEOUT = 2
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# pylint: disable=too-few-public-methods
|
|
58
|
+
class AbstractLogWrapper(metaclass=ABCMeta):
|
|
59
|
+
"""
|
|
60
|
+
AbstractLogWrapper
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
available_modes = {}
|
|
64
|
+
|
|
65
|
+
def __new__(cls, conf_profiling, out_dir): # pylint: disable=W0613
|
|
66
|
+
"""
|
|
67
|
+
Return Log wrapper
|
|
68
|
+
"""
|
|
69
|
+
profiling_mode = "cars_profiling"
|
|
70
|
+
|
|
71
|
+
if "mode" not in conf_profiling:
|
|
72
|
+
logging.debug("Profiling mode not defined, default is used")
|
|
73
|
+
else:
|
|
74
|
+
profiling_mode = conf_profiling["mode"]
|
|
75
|
+
|
|
76
|
+
return super(AbstractLogWrapper, cls).__new__(
|
|
77
|
+
cls.available_modes[profiling_mode]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def __init__(self, conf_profiling, out_dir):
|
|
81
|
+
# Check conf
|
|
82
|
+
self.checked_conf_profiling = self.check_conf(conf_profiling)
|
|
83
|
+
self.out_dir = out_dir
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def register_subclass(cls, short_name: str):
|
|
87
|
+
"""
|
|
88
|
+
Allows to register the subclass with its short name
|
|
89
|
+
:param short_name: the subclass to be registered
|
|
90
|
+
:type short_name: string
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def decorator(subclass):
|
|
94
|
+
"""
|
|
95
|
+
Registers the subclass in the available methods
|
|
96
|
+
:param subclass: the subclass to be registered
|
|
97
|
+
:type subclass: object
|
|
98
|
+
"""
|
|
99
|
+
cls.available_modes[short_name] = subclass
|
|
100
|
+
return subclass
|
|
101
|
+
|
|
102
|
+
return decorator
|
|
103
|
+
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def check_conf(self, conf):
|
|
106
|
+
"""
|
|
107
|
+
Check configuration
|
|
108
|
+
|
|
109
|
+
:param conf: configuration to check
|
|
110
|
+
:type conf: dict
|
|
111
|
+
|
|
112
|
+
:return: overloaded configuration
|
|
113
|
+
:rtype: dict
|
|
114
|
+
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
@abstractmethod
|
|
118
|
+
def get_func_args_plus(self, func):
|
|
119
|
+
"""
|
|
120
|
+
getter for the args of the future function
|
|
121
|
+
|
|
122
|
+
:param: function to apply
|
|
123
|
+
|
|
124
|
+
:return: function to apply, overloaded key arguments
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@AbstractLogWrapper.register_subclass("cars_profiling")
|
|
129
|
+
class LogWrapper(AbstractLogWrapper):
|
|
130
|
+
"""
|
|
131
|
+
LogWrapper
|
|
132
|
+
|
|
133
|
+
simple log wrapper doing nothing
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
def __init__(self, conf_profiling, out_dir):
|
|
137
|
+
self.out_dir = out_dir
|
|
138
|
+
# call parent init
|
|
139
|
+
super().__init__(conf_profiling, out_dir)
|
|
140
|
+
self.loop_testing = self.checked_conf_profiling["loop_testing"]
|
|
141
|
+
|
|
142
|
+
def check_conf(self, conf):
|
|
143
|
+
"""
|
|
144
|
+
Check configuration
|
|
145
|
+
|
|
146
|
+
:param conf: configuration to check
|
|
147
|
+
:type conf: dict
|
|
148
|
+
|
|
149
|
+
:return: overloaded configuration
|
|
150
|
+
:rtype: dict
|
|
151
|
+
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
# init conf
|
|
155
|
+
if conf is not None:
|
|
156
|
+
overloaded_conf = conf.copy()
|
|
157
|
+
else:
|
|
158
|
+
conf = {}
|
|
159
|
+
overloaded_conf = {}
|
|
160
|
+
|
|
161
|
+
# Overload conf
|
|
162
|
+
overloaded_conf["mode"] = conf.get("mode", "cars_profiling")
|
|
163
|
+
overloaded_conf["loop_testing"] = conf.get("loop_testing", False)
|
|
164
|
+
|
|
165
|
+
cluster_schema = {"mode": str, "loop_testing": bool}
|
|
166
|
+
|
|
167
|
+
# Check conf
|
|
168
|
+
checker = Checker(cluster_schema)
|
|
169
|
+
checker.validate(overloaded_conf)
|
|
170
|
+
|
|
171
|
+
return overloaded_conf
|
|
172
|
+
|
|
173
|
+
def get_func_args_plus(self, func):
|
|
174
|
+
fun = log_function
|
|
175
|
+
new_kwarg = {
|
|
176
|
+
"fun_log_wrapper": func,
|
|
177
|
+
"loop_testing": self.loop_testing,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return fun, new_kwarg
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@AbstractLogWrapper.register_subclass("cprofile")
|
|
184
|
+
class CProfileWrapper(AbstractLogWrapper):
|
|
185
|
+
"""
|
|
186
|
+
CProfileWrapper
|
|
187
|
+
|
|
188
|
+
log wrapper to analyze the internal time consuming of the function.
|
|
189
|
+
The wrapper use cprofile API.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
def __init__(self, conf_profiling, out_dir):
|
|
193
|
+
self.out_dir = out_dir
|
|
194
|
+
# call parent init
|
|
195
|
+
super().__init__(conf_profiling, out_dir)
|
|
196
|
+
|
|
197
|
+
def check_conf(self, conf):
|
|
198
|
+
"""
|
|
199
|
+
Check configuration
|
|
200
|
+
|
|
201
|
+
:param conf: configuration to check
|
|
202
|
+
:type conf: dict
|
|
203
|
+
|
|
204
|
+
:return: overloaded configuration
|
|
205
|
+
:rtype: dict
|
|
206
|
+
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
# init conf
|
|
210
|
+
if conf is not None:
|
|
211
|
+
overloaded_conf = conf.copy()
|
|
212
|
+
else:
|
|
213
|
+
conf = {}
|
|
214
|
+
overloaded_conf = {}
|
|
215
|
+
|
|
216
|
+
# Overload conf
|
|
217
|
+
overloaded_conf["mode"] = conf.get("mode", "cars_profiling")
|
|
218
|
+
cluster_schema = {"mode": str}
|
|
219
|
+
|
|
220
|
+
# Check conf
|
|
221
|
+
checker = Checker(cluster_schema)
|
|
222
|
+
checker.validate(overloaded_conf)
|
|
223
|
+
|
|
224
|
+
return overloaded_conf
|
|
225
|
+
|
|
226
|
+
def get_func_args_plus(self, func):
|
|
227
|
+
fun = time_profiling_function
|
|
228
|
+
new_kwarg = {"fun_log_wrapper": func}
|
|
229
|
+
|
|
230
|
+
return fun, new_kwarg
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@AbstractLogWrapper.register_subclass("memray")
|
|
234
|
+
class MemrayWrapper(AbstractLogWrapper):
|
|
235
|
+
"""
|
|
236
|
+
MemrayWrapper
|
|
237
|
+
|
|
238
|
+
log wrapper to analyze the internal allocation
|
|
239
|
+
memory consuming of the function.
|
|
240
|
+
The wrapper use cprofile API.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
def __init__(self, conf_profiling, out_dir):
|
|
244
|
+
self.out_dir = out_dir
|
|
245
|
+
profiling_memory_dir = os.path.join(
|
|
246
|
+
out_dir, "logs", "profiling", "memray"
|
|
247
|
+
)
|
|
248
|
+
safe_makedirs(profiling_memory_dir, cleanup=True)
|
|
249
|
+
# call parent init
|
|
250
|
+
super().__init__(conf_profiling, out_dir)
|
|
251
|
+
self.loop_testing = self.checked_conf_profiling["loop_testing"]
|
|
252
|
+
|
|
253
|
+
def check_conf(self, conf):
|
|
254
|
+
"""
|
|
255
|
+
Check configuration
|
|
256
|
+
|
|
257
|
+
:param conf: configuration to check
|
|
258
|
+
:type conf: dict
|
|
259
|
+
|
|
260
|
+
:return: overloaded configuration
|
|
261
|
+
:rtype: dict
|
|
262
|
+
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
# init conf
|
|
266
|
+
if conf is not None:
|
|
267
|
+
overloaded_conf = conf.copy()
|
|
268
|
+
else:
|
|
269
|
+
conf = {}
|
|
270
|
+
overloaded_conf = {}
|
|
271
|
+
|
|
272
|
+
# Overload conf
|
|
273
|
+
overloaded_conf["mode"] = conf.get("mode", "cars_profiling")
|
|
274
|
+
overloaded_conf["loop_testing"] = conf.get("loop_testing", False)
|
|
275
|
+
|
|
276
|
+
cluster_schema = {"mode": str, "loop_testing": bool}
|
|
277
|
+
|
|
278
|
+
# Check conf
|
|
279
|
+
checker = Checker(cluster_schema)
|
|
280
|
+
checker.validate(overloaded_conf)
|
|
281
|
+
|
|
282
|
+
return overloaded_conf
|
|
283
|
+
|
|
284
|
+
def get_func_args_plus(self, func):
|
|
285
|
+
fun = memory_profiling_function
|
|
286
|
+
new_kwarg = {
|
|
287
|
+
"fun_log_wrapper": func,
|
|
288
|
+
"loop_testing": self.loop_testing,
|
|
289
|
+
"out_dir": self.out_dir,
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return fun, new_kwarg
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def log_function(*argv, **kwargs):
|
|
296
|
+
"""
|
|
297
|
+
Create a wrapper for function running it
|
|
298
|
+
|
|
299
|
+
:param argv: args of func
|
|
300
|
+
:param kwargs: kwargs of func
|
|
301
|
+
|
|
302
|
+
:return: path to results
|
|
303
|
+
"""
|
|
304
|
+
func = kwargs["fun_log_wrapper"]
|
|
305
|
+
loop_testing = kwargs["loop_testing"]
|
|
306
|
+
kwargs.pop("fun_log_wrapper")
|
|
307
|
+
kwargs.pop("loop_testing")
|
|
308
|
+
|
|
309
|
+
if loop_testing:
|
|
310
|
+
# Profile
|
|
311
|
+
res = cars_profile(name=func.__name__ + "_looped", interval=0.2)(
|
|
312
|
+
loop_function
|
|
313
|
+
)(argv, kwargs, func)
|
|
314
|
+
else:
|
|
315
|
+
res = cars_profile(interval=0.2)(func)(*argv, **kwargs)
|
|
316
|
+
|
|
317
|
+
return res
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def time_profiling_function(*argv, **kwargs):
|
|
321
|
+
"""
|
|
322
|
+
Create a wrapper to profile the function elapse time
|
|
323
|
+
|
|
324
|
+
:param argv: args of func
|
|
325
|
+
:param kwargs: kwargs of func
|
|
326
|
+
|
|
327
|
+
:return: path to results
|
|
328
|
+
"""
|
|
329
|
+
func = kwargs["fun_log_wrapper"]
|
|
330
|
+
kwargs.pop("fun_log_wrapper")
|
|
331
|
+
# Monitor time
|
|
332
|
+
start_time = time.time()
|
|
333
|
+
# Profile time
|
|
334
|
+
profiler = cProfile.Profile()
|
|
335
|
+
profiler.enable()
|
|
336
|
+
res = func(*argv, **kwargs)
|
|
337
|
+
profiler.disable()
|
|
338
|
+
total_time = time.time() - start_time
|
|
339
|
+
|
|
340
|
+
switch_messages(func, total_time)
|
|
341
|
+
print("## PROF STATs")
|
|
342
|
+
|
|
343
|
+
stream_cumtime = io.StringIO()
|
|
344
|
+
stream_calls = io.StringIO()
|
|
345
|
+
pstats.Stats(profiler, stream=stream_cumtime).sort_stats(
|
|
346
|
+
"tottime"
|
|
347
|
+
).print_stats(5)
|
|
348
|
+
pstats.Stats(profiler, stream=stream_calls).sort_stats("calls").print_stats(
|
|
349
|
+
5
|
|
350
|
+
)
|
|
351
|
+
logging.info(stream_cumtime.getvalue())
|
|
352
|
+
print(stream_cumtime.getvalue())
|
|
353
|
+
logging.info(stream_calls.getvalue())
|
|
354
|
+
print(stream_calls.getvalue())
|
|
355
|
+
print("----------")
|
|
356
|
+
return res
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def memory_profiling_function(*argv, **kwargs):
|
|
360
|
+
"""
|
|
361
|
+
Create a wrapper to profile the function occupation memory
|
|
362
|
+
|
|
363
|
+
:param argv: args of func
|
|
364
|
+
:param kwargs: kwargs of func
|
|
365
|
+
|
|
366
|
+
:return: path to results
|
|
367
|
+
"""
|
|
368
|
+
func = kwargs["fun_log_wrapper"]
|
|
369
|
+
loop_testing = kwargs["loop_testing"]
|
|
370
|
+
outputdir = kwargs["out_dir"]
|
|
371
|
+
|
|
372
|
+
kwargs.pop("fun_log_wrapper")
|
|
373
|
+
kwargs.pop("loop_testing")
|
|
374
|
+
kwargs.pop("out_dir")
|
|
375
|
+
|
|
376
|
+
# Monitor time
|
|
377
|
+
memray = import_module("memray")
|
|
378
|
+
start_time = time.time()
|
|
379
|
+
unique_filename = str(uuid.uuid4())
|
|
380
|
+
# Profile memory
|
|
381
|
+
with memray.Tracker(
|
|
382
|
+
os.path.join(
|
|
383
|
+
outputdir,
|
|
384
|
+
"profiling",
|
|
385
|
+
"memray",
|
|
386
|
+
func.__name__ + "-" + unique_filename + ".bin",
|
|
387
|
+
)
|
|
388
|
+
):
|
|
389
|
+
if loop_testing:
|
|
390
|
+
res = loop_function(argv, kwargs, func)
|
|
391
|
+
else:
|
|
392
|
+
res = func(*argv, **kwargs)
|
|
393
|
+
total_time = time.time() - start_time
|
|
394
|
+
|
|
395
|
+
switch_messages(func, total_time)
|
|
396
|
+
print("----------")
|
|
397
|
+
return res
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def switch_messages(func, total_time, max_memory=None):
|
|
401
|
+
"""
|
|
402
|
+
create profile message with specific message
|
|
403
|
+
depends on elapsed time (LONG, FAST...).
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
:param func : profiled function
|
|
407
|
+
:param total_time : elapsed time of the function
|
|
408
|
+
"""
|
|
409
|
+
message = "Clock# %{}%: %{:.4f}% s Max ram : {} MiB".format(
|
|
410
|
+
func.__name__.capitalize(), total_time, max_memory
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
if total_time >= 1:
|
|
414
|
+
message += " LONG"
|
|
415
|
+
elif 1 > total_time >= 0.001:
|
|
416
|
+
message += " FAST"
|
|
417
|
+
elif 0.001 > total_time >= 0.000001:
|
|
418
|
+
message += " VERY FAST"
|
|
419
|
+
else:
|
|
420
|
+
message += " TOO FAST"
|
|
421
|
+
|
|
422
|
+
log_message(func, message)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def log_message(func, message):
|
|
426
|
+
"""
|
|
427
|
+
log profiling message
|
|
428
|
+
|
|
429
|
+
:param func : logged function
|
|
430
|
+
:param message : log message
|
|
431
|
+
"""
|
|
432
|
+
cars_logging.add_profiling_message(message)
|
|
433
|
+
cars_logging.add_profiling_message(func.__module__)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def loop_function(argv, kwargs, func, nb_iteration=5):
|
|
437
|
+
"""
|
|
438
|
+
generate a loop on each cluster function to eval possible leak
|
|
439
|
+
|
|
440
|
+
:param argv : input argv
|
|
441
|
+
:param kwargs : input kwargs
|
|
442
|
+
:param func : function to evaluation
|
|
443
|
+
:param nb_iteration (int, optional): number of the iteration loop.
|
|
444
|
+
:param Defaults to 5.
|
|
445
|
+
|
|
446
|
+
Returns:
|
|
447
|
+
_type_: result of the function
|
|
448
|
+
"""
|
|
449
|
+
logging.info("{} {}".format(func.__module__, func.__name__.capitalize()))
|
|
450
|
+
argv_temp = copy.copy(argv)
|
|
451
|
+
kwargs_temp = copy.deepcopy(kwargs)
|
|
452
|
+
# execute sevral time the function to observe possible leaks
|
|
453
|
+
for k in range(1, nb_iteration):
|
|
454
|
+
logging.info("loop iteration {}".format(k))
|
|
455
|
+
func(*argv, **kwargs)
|
|
456
|
+
del argv
|
|
457
|
+
del kwargs
|
|
458
|
+
gc.collect()
|
|
459
|
+
argv = copy.deepcopy(argv_temp)
|
|
460
|
+
kwargs = copy.deepcopy(kwargs_temp)
|
|
461
|
+
return func(*argv, **kwargs)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def get_current_memory():
|
|
465
|
+
"""
|
|
466
|
+
Get current memory of process
|
|
467
|
+
|
|
468
|
+
:return: memory
|
|
469
|
+
:rtype: float
|
|
470
|
+
|
|
471
|
+
"""
|
|
472
|
+
|
|
473
|
+
# Use psutil to capture python process memory as well
|
|
474
|
+
process = psutil.Process(os.getpid())
|
|
475
|
+
process_memory = process.memory_info().rss
|
|
476
|
+
|
|
477
|
+
# Convert nbytes size for logger
|
|
478
|
+
process_memory = float(process_memory) / 1000000
|
|
479
|
+
|
|
480
|
+
return process_memory
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def log_delta_memory(func, memory_start, memory_end):
|
|
484
|
+
"""
|
|
485
|
+
Log memory infos
|
|
486
|
+
|
|
487
|
+
:param func: profiled function
|
|
488
|
+
:param memory_start: memory before the run of function
|
|
489
|
+
:type memory_start: float
|
|
490
|
+
:param memory_end: memory after the run of function
|
|
491
|
+
:type memory_end: float
|
|
492
|
+
|
|
493
|
+
"""
|
|
494
|
+
|
|
495
|
+
message = "Memory before run: {}Mb, Memory after run: {}Mb".format(
|
|
496
|
+
str(memory_start), str(memory_end)
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
log_message(func, message)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def exception_safe(func):
|
|
503
|
+
"""
|
|
504
|
+
Decorator for consistent exception handling in profiling functions
|
|
505
|
+
|
|
506
|
+
:param func: function to wrap
|
|
507
|
+
:return: wrapped function
|
|
508
|
+
"""
|
|
509
|
+
|
|
510
|
+
@functools.wraps(func)
|
|
511
|
+
def wrapper(*args, **kwargs):
|
|
512
|
+
"""
|
|
513
|
+
Catch error
|
|
514
|
+
"""
|
|
515
|
+
try:
|
|
516
|
+
return func(*args, **kwargs)
|
|
517
|
+
except Exception as exc:
|
|
518
|
+
error_msg = (
|
|
519
|
+
f"Error in {func.__name__}: {type(exc).__name__}: {str(exc)}"
|
|
520
|
+
)
|
|
521
|
+
logging.error(error_msg)
|
|
522
|
+
cars_logging.add_profiling_message(f"ERROR - {error_msg}")
|
|
523
|
+
return None
|
|
524
|
+
|
|
525
|
+
return wrapper
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
@exception_safe
|
|
529
|
+
def generate_summary(out_dir, used_conf, clean_worker_logs=False):
|
|
530
|
+
"""
|
|
531
|
+
Generate Profiling summary
|
|
532
|
+
"""
|
|
533
|
+
nb_workers = 1
|
|
534
|
+
if "orchestrator" not in used_conf:
|
|
535
|
+
first_key = next(iter(used_conf))
|
|
536
|
+
if "nb_workers" in used_conf[first_key]["orchestrator"]:
|
|
537
|
+
nb_workers = used_conf[first_key]["orchestrator"]["nb_workers"]
|
|
538
|
+
else:
|
|
539
|
+
if "nb_workers" in used_conf["orchestrator"]:
|
|
540
|
+
nb_workers = used_conf["orchestrator"]["nb_workers"]
|
|
541
|
+
|
|
542
|
+
workers_log_dir = os.path.join(out_dir, "workers_log")
|
|
543
|
+
os.makedirs(workers_log_dir, exist_ok=True)
|
|
544
|
+
|
|
545
|
+
log_file_main = os.path.join(
|
|
546
|
+
workers_log_dir,
|
|
547
|
+
"profiling.log",
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
out_profiling_main = os.path.join(out_dir, "profiling", "profiling.log")
|
|
551
|
+
|
|
552
|
+
log_files = [log_file_main, out_profiling_main]
|
|
553
|
+
|
|
554
|
+
names = []
|
|
555
|
+
times = []
|
|
556
|
+
max_ram = []
|
|
557
|
+
start_ram = []
|
|
558
|
+
end_ram = []
|
|
559
|
+
max_cpu = []
|
|
560
|
+
|
|
561
|
+
for log_file in log_files:
|
|
562
|
+
if not os.path.exists(log_file):
|
|
563
|
+
logging.debug("{} log file does not exist".format(log_file))
|
|
564
|
+
return
|
|
565
|
+
|
|
566
|
+
with open(log_file, encoding="UTF-8") as file_desc:
|
|
567
|
+
for item in file_desc:
|
|
568
|
+
if "CarsProfiling" in item:
|
|
569
|
+
splited_items = item.split("%")
|
|
570
|
+
names.append(splited_items[1])
|
|
571
|
+
times.append(float(splited_items[3]))
|
|
572
|
+
max_ram.append(float(splited_items[5]))
|
|
573
|
+
start_ram.append(float(splited_items[7]))
|
|
574
|
+
end_ram.append(float(splited_items[9]))
|
|
575
|
+
max_cpu.append(float(splited_items[11]))
|
|
576
|
+
|
|
577
|
+
times_df = pd.DataFrame(
|
|
578
|
+
{
|
|
579
|
+
"name": names,
|
|
580
|
+
"time": times,
|
|
581
|
+
"max_ram": max_ram,
|
|
582
|
+
"start_ram": start_ram,
|
|
583
|
+
"end_ram": end_ram,
|
|
584
|
+
"max_cpu": max_cpu,
|
|
585
|
+
}
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
# Generate summary message
|
|
589
|
+
cars_logging.add_profiling_message(
|
|
590
|
+
"\n \n \n "
|
|
591
|
+
"----------------------------------------"
|
|
592
|
+
" SUMMARY PROFILLING "
|
|
593
|
+
"----------------------------------------"
|
|
594
|
+
" \n \n \n"
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
summary_names = []
|
|
598
|
+
summary_max_ram = []
|
|
599
|
+
summary_max_ram_err_min = []
|
|
600
|
+
summary_max_ram_err_max = []
|
|
601
|
+
summary_max_ram_relative = []
|
|
602
|
+
summary_mean_time_per_task = []
|
|
603
|
+
summary_mean_time_per_task_err_min = []
|
|
604
|
+
summary_mean_time_per_task_err_max = []
|
|
605
|
+
summary_total_time = []
|
|
606
|
+
summary_max_cpu = []
|
|
607
|
+
summary_nb_calls = []
|
|
608
|
+
full_max_ram = []
|
|
609
|
+
full_added_ram = []
|
|
610
|
+
full_time = []
|
|
611
|
+
full_max_cpu = []
|
|
612
|
+
|
|
613
|
+
for name in pd.unique(times_df["name"]):
|
|
614
|
+
current_df = times_df.loc[times_df["name"] == name]
|
|
615
|
+
|
|
616
|
+
current_med_time = current_df["time"].mean()
|
|
617
|
+
current_med_time_err_min = current_med_time - current_df["time"].min()
|
|
618
|
+
current_med_time_err_max = current_df["time"].max() - current_med_time
|
|
619
|
+
total_time = current_df["time"].sum()
|
|
620
|
+
max_ram = current_df["max_ram"].mean()
|
|
621
|
+
max_ram_err_min = max_ram - current_df["max_ram"].min()
|
|
622
|
+
max_ram_err_max = current_df["max_ram"].max() - max_ram
|
|
623
|
+
max_cpu = current_df["max_cpu"].max()
|
|
624
|
+
max_ram_without_start = (
|
|
625
|
+
current_df["max_ram"] - current_df["start_ram"]
|
|
626
|
+
).max()
|
|
627
|
+
diff_end_start = (current_df["end_ram"] - current_df["start_ram"]).max()
|
|
628
|
+
nb_values = len(current_df)
|
|
629
|
+
|
|
630
|
+
# Fill lists with all data
|
|
631
|
+
full_max_ram.append(list(current_df["max_ram"]))
|
|
632
|
+
full_added_ram.append(
|
|
633
|
+
list(current_df["max_ram"] - current_df["start_ram"])
|
|
634
|
+
)
|
|
635
|
+
full_time.append(list(current_df["time"]))
|
|
636
|
+
full_max_cpu.append(list(current_df["max_cpu"]))
|
|
637
|
+
|
|
638
|
+
# fill lists for figures
|
|
639
|
+
summary_names.append(name)
|
|
640
|
+
summary_max_ram.append(max_ram)
|
|
641
|
+
summary_max_ram_err_min.append(max_ram_err_min)
|
|
642
|
+
summary_max_ram_err_max.append(max_ram_err_max)
|
|
643
|
+
summary_max_ram_relative.append(max_ram_without_start)
|
|
644
|
+
summary_mean_time_per_task.append(current_med_time)
|
|
645
|
+
summary_mean_time_per_task_err_min.append(current_med_time_err_min)
|
|
646
|
+
summary_mean_time_per_task_err_max.append(current_med_time_err_max)
|
|
647
|
+
summary_total_time.append(total_time)
|
|
648
|
+
summary_max_cpu.append(max_cpu)
|
|
649
|
+
summary_nb_calls.append(nb_values)
|
|
650
|
+
|
|
651
|
+
message = (
|
|
652
|
+
"Task {} ran {} times, with mean time {} sec, "
|
|
653
|
+
"total time: {} sec, Max cpu: {} %"
|
|
654
|
+
" max ram in process during task: {} MiB, "
|
|
655
|
+
"max ram - start ram: {}, "
|
|
656
|
+
" end - start ram : {}".format(
|
|
657
|
+
name,
|
|
658
|
+
nb_values,
|
|
659
|
+
current_med_time,
|
|
660
|
+
total_time,
|
|
661
|
+
max_cpu,
|
|
662
|
+
max_ram,
|
|
663
|
+
max_ram_without_start,
|
|
664
|
+
diff_end_start,
|
|
665
|
+
)
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
cars_logging.add_profiling_message(message)
|
|
669
|
+
|
|
670
|
+
# Generate png
|
|
671
|
+
_, axs = plt.subplots(3, 2, figsize=(20, 20), layout="tight")
|
|
672
|
+
# Fill
|
|
673
|
+
|
|
674
|
+
generate_boxplot(
|
|
675
|
+
axs.flat[0], summary_names, full_max_cpu, "Max CPU usage", "%"
|
|
676
|
+
)
|
|
677
|
+
generate_histo(
|
|
678
|
+
axs.flat[1], summary_names, summary_total_time, "Total Time", "s"
|
|
679
|
+
)
|
|
680
|
+
|
|
681
|
+
(
|
|
682
|
+
summary_names_without_pipeline,
|
|
683
|
+
total_full_time_without_pipeline,
|
|
684
|
+
) = filter_lists(
|
|
685
|
+
summary_names,
|
|
686
|
+
full_time,
|
|
687
|
+
lambda name: "pipeline" not in name,
|
|
688
|
+
)
|
|
689
|
+
generate_boxplot(
|
|
690
|
+
axs.flat[2],
|
|
691
|
+
summary_names_without_pipeline,
|
|
692
|
+
total_full_time_without_pipeline,
|
|
693
|
+
"Time per task",
|
|
694
|
+
"s",
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
generate_boxplot(
|
|
698
|
+
axs.flat[3],
|
|
699
|
+
summary_names,
|
|
700
|
+
full_max_ram,
|
|
701
|
+
"Max RAM used",
|
|
702
|
+
"MiB",
|
|
703
|
+
)
|
|
704
|
+
|
|
705
|
+
generate_boxplot(
|
|
706
|
+
axs.flat[4],
|
|
707
|
+
summary_names,
|
|
708
|
+
full_added_ram,
|
|
709
|
+
"Max RAM added",
|
|
710
|
+
"MiB",
|
|
711
|
+
)
|
|
712
|
+
generate_histo(
|
|
713
|
+
axs.flat[5],
|
|
714
|
+
summary_names,
|
|
715
|
+
summary_nb_calls,
|
|
716
|
+
"NB calls",
|
|
717
|
+
"calls",
|
|
718
|
+
)
|
|
719
|
+
|
|
720
|
+
# file_name
|
|
721
|
+
profiling_plot = os.path.join(
|
|
722
|
+
out_dir,
|
|
723
|
+
"profiling",
|
|
724
|
+
"profiling_plots_histograms.png",
|
|
725
|
+
)
|
|
726
|
+
plt.savefig(profiling_plot)
|
|
727
|
+
|
|
728
|
+
# Pie chart
|
|
729
|
+
|
|
730
|
+
(name_task_workers, summary_workers) = filter_lists(
|
|
731
|
+
summary_names, summary_total_time, lambda name: "wrapper" in name
|
|
732
|
+
)
|
|
733
|
+
|
|
734
|
+
(name_task_main, summary_main) = filter_lists(
|
|
735
|
+
summary_names,
|
|
736
|
+
summary_total_time,
|
|
737
|
+
lambda name: "wrapper" not in name
|
|
738
|
+
and "pipeline" not in name
|
|
739
|
+
and "Compute futures" not in name,
|
|
740
|
+
)
|
|
741
|
+
|
|
742
|
+
(_, [pipeline_time]) = filter_lists(
|
|
743
|
+
summary_names, summary_total_time, lambda name: "unit_pipeline" in name
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
(_, [multiprocessing_time]) = filter_lists(
|
|
747
|
+
summary_names,
|
|
748
|
+
summary_total_time,
|
|
749
|
+
lambda name: "Compute futures" in name,
|
|
750
|
+
)
|
|
751
|
+
|
|
752
|
+
sequential_time = pipeline_time - multiprocessing_time
|
|
753
|
+
|
|
754
|
+
total_time_workers = nb_workers * multiprocessing_time
|
|
755
|
+
|
|
756
|
+
_, axs2 = plt.subplots(2, 1, figsize=(40, 40), layout="tight")
|
|
757
|
+
|
|
758
|
+
generate_pie_chart(
|
|
759
|
+
axs2.flat[0],
|
|
760
|
+
name_task_workers,
|
|
761
|
+
100 * np.array(summary_workers) / total_time_workers,
|
|
762
|
+
"Total time in parallel tasks ({} workers) : {}".format(
|
|
763
|
+
nb_workers,
|
|
764
|
+
str(datetime.timedelta(seconds=int(multiprocessing_time))),
|
|
765
|
+
),
|
|
766
|
+
)
|
|
767
|
+
|
|
768
|
+
generate_pie_chart(
|
|
769
|
+
axs2.flat[1],
|
|
770
|
+
name_task_main,
|
|
771
|
+
100 * np.array(summary_main) / sequential_time,
|
|
772
|
+
"Total time in sequential tasks : {}".format(
|
|
773
|
+
str(datetime.timedelta(seconds=int(sequential_time)))
|
|
774
|
+
),
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
profiling_plot2 = os.path.join(
|
|
778
|
+
out_dir,
|
|
779
|
+
"profiling",
|
|
780
|
+
"profiling_plots_pie_chart.png",
|
|
781
|
+
)
|
|
782
|
+
plt.savefig(profiling_plot2)
|
|
783
|
+
|
|
784
|
+
if clean_worker_logs and os.path.exists(workers_log_dir):
|
|
785
|
+
shutil.rmtree(workers_log_dir)
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
def generate_pdf_profiling(log_dir):
|
|
789
|
+
"""
|
|
790
|
+
Generate PDF profiling summary for all res
|
|
791
|
+
"""
|
|
792
|
+
|
|
793
|
+
pages_data = {}
|
|
794
|
+
resolutions = []
|
|
795
|
+
|
|
796
|
+
for item in os.listdir(log_dir):
|
|
797
|
+
item_path = os.path.join(log_dir, item)
|
|
798
|
+
if os.path.isdir(item_path) and item.startswith("res"):
|
|
799
|
+
# Get resolution
|
|
800
|
+
res = int(item[4:])
|
|
801
|
+
resolutions.append(res)
|
|
802
|
+
|
|
803
|
+
# Add paths
|
|
804
|
+
pages_data[res] = {
|
|
805
|
+
"function_profiling_histo": os.path.join(
|
|
806
|
+
item_path, "profiling", "profiling_plots_histo.png"
|
|
807
|
+
),
|
|
808
|
+
"function_profiling_pie_chart": os.path.join(
|
|
809
|
+
item_path, "profiling", "profiling_plots_pie_chart.png"
|
|
810
|
+
),
|
|
811
|
+
"global_profiling": os.path.join(
|
|
812
|
+
item_path, "profiling", "memory_profiling.png"
|
|
813
|
+
),
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
# ordered resolutions
|
|
817
|
+
resolutions.sort(reverse=True)
|
|
818
|
+
|
|
819
|
+
# Build pdf
|
|
820
|
+
pdf_path = os.path.join(log_dir, "profiling_summary.pdf")
|
|
821
|
+
|
|
822
|
+
with PdfPages(pdf_path) as pdf:
|
|
823
|
+
for res in resolutions:
|
|
824
|
+
# function_profiling
|
|
825
|
+
if os.path.exists(pages_data[res]["function_profiling_histo"]):
|
|
826
|
+
img = Image.open(pages_data[res]["function_profiling_histo"])
|
|
827
|
+
fig, axis = plt.subplots(1, 1, figsize=(11.69, 8.27), dpi=300)
|
|
828
|
+
axis.imshow(img, interpolation="none")
|
|
829
|
+
axis.set_title(
|
|
830
|
+
f"Function Profiling Histograms - "
|
|
831
|
+
f"Epipolar Resolution {res}",
|
|
832
|
+
fontsize=16,
|
|
833
|
+
fontweight="bold",
|
|
834
|
+
)
|
|
835
|
+
axis.axis("off")
|
|
836
|
+
plt.subplots_adjust(left=0, right=1, top=0.95, bottom=0)
|
|
837
|
+
pdf.savefig(fig, bbox_inches="tight", dpi=300)
|
|
838
|
+
plt.close(fig)
|
|
839
|
+
|
|
840
|
+
if os.path.exists(pages_data[res]["function_profiling_pie_chart"]):
|
|
841
|
+
img = Image.open(
|
|
842
|
+
pages_data[res]["function_profiling_pie_chart"]
|
|
843
|
+
)
|
|
844
|
+
fig, axis = plt.subplots(1, 1, figsize=(11.69, 8.27), dpi=300)
|
|
845
|
+
axis.imshow(img, interpolation="none")
|
|
846
|
+
axis.set_title(
|
|
847
|
+
f"Function Profiling Pie Chart - Epipolar Resolution {res}",
|
|
848
|
+
fontsize=16,
|
|
849
|
+
fontweight="bold",
|
|
850
|
+
)
|
|
851
|
+
axis.axis("off")
|
|
852
|
+
plt.subplots_adjust(left=0, right=1, top=0.95, bottom=0)
|
|
853
|
+
pdf.savefig(fig, bbox_inches="tight", dpi=300)
|
|
854
|
+
plt.close(fig)
|
|
855
|
+
|
|
856
|
+
# global_profiling
|
|
857
|
+
if os.path.exists(pages_data[res]["global_profiling"]):
|
|
858
|
+
img = Image.open(pages_data[res]["global_profiling"])
|
|
859
|
+
fig, axis = plt.subplots(1, 1, figsize=(11.69, 8.27), dpi=300)
|
|
860
|
+
axis.imshow(img, interpolation="none")
|
|
861
|
+
axis.set_title(
|
|
862
|
+
f"Global Profiling - Epipolar Resolution {res}",
|
|
863
|
+
fontsize=16,
|
|
864
|
+
fontweight="bold",
|
|
865
|
+
)
|
|
866
|
+
axis.axis("off")
|
|
867
|
+
plt.subplots_adjust(left=0, right=1, top=0.95, bottom=0)
|
|
868
|
+
pdf.savefig(fig, bbox_inches="tight", dpi=300)
|
|
869
|
+
plt.close(fig)
|
|
870
|
+
|
|
871
|
+
logging.info("PDF profiling summary generated: {}".format(pdf_path))
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
def filter_lists(names, data, cond):
|
|
875
|
+
"""
|
|
876
|
+
Filter lists with condition on name
|
|
877
|
+
"""
|
|
878
|
+
|
|
879
|
+
filtered_names = []
|
|
880
|
+
filtered_data = []
|
|
881
|
+
|
|
882
|
+
for name, dat in zip(names, data): # noqa: B905
|
|
883
|
+
if cond(name):
|
|
884
|
+
filtered_names.append(name)
|
|
885
|
+
filtered_data.append(dat)
|
|
886
|
+
|
|
887
|
+
return filtered_names, filtered_data
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def generate_boxplot(axis, names, data_full, title, data_type):
|
|
891
|
+
"""
|
|
892
|
+
Generate boxplot
|
|
893
|
+
"""
|
|
894
|
+
|
|
895
|
+
axis.boxplot(data_full, vert=False, showfliers=False, labels=names)
|
|
896
|
+
axis.invert_yaxis()
|
|
897
|
+
axis.set_xlabel(data_type)
|
|
898
|
+
axis.set_title(title)
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
def generate_histo( # pylint: disable=too-many-positional-arguments
|
|
902
|
+
axis, names, data, title, data_type, data_min_err=None, data_max_err=None
|
|
903
|
+
):
|
|
904
|
+
"""
|
|
905
|
+
Generate histogram
|
|
906
|
+
"""
|
|
907
|
+
y_pos = np.arange(len(names))
|
|
908
|
+
if None not in (data_min_err, data_max_err):
|
|
909
|
+
data_min_err = np.array(data_min_err)
|
|
910
|
+
data_max_err = np.array(data_max_err)
|
|
911
|
+
xerr = np.empty((2, data_min_err.shape[0]))
|
|
912
|
+
xerr[0, :] = data_min_err
|
|
913
|
+
xerr[1, :] = data_max_err
|
|
914
|
+
axis.barh(y_pos, data, xerr=xerr, align="center")
|
|
915
|
+
else:
|
|
916
|
+
axis.barh(y_pos, data, align="center")
|
|
917
|
+
axis.set_yticks(y_pos, labels=names)
|
|
918
|
+
axis.invert_yaxis()
|
|
919
|
+
axis.set_xlabel(data_type)
|
|
920
|
+
axis.set_title(title)
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
def generate_pie_chart(axis, names, data, title):
|
|
924
|
+
"""
|
|
925
|
+
Generate pie chart, data in %
|
|
926
|
+
"""
|
|
927
|
+
names = list(names)
|
|
928
|
+
data = list(data)
|
|
929
|
+
|
|
930
|
+
if np.sum(data) > 100:
|
|
931
|
+
cars_logging.add_profiling_message(
|
|
932
|
+
"Chart: sum of data {}> 100%".format(title)
|
|
933
|
+
)
|
|
934
|
+
title += " (with sum > 100%) "
|
|
935
|
+
else:
|
|
936
|
+
others = 100 - np.sum(data)
|
|
937
|
+
data.append(others)
|
|
938
|
+
names.append("other")
|
|
939
|
+
|
|
940
|
+
axis.pie(
|
|
941
|
+
data,
|
|
942
|
+
labels=names,
|
|
943
|
+
autopct="%1.1f%%",
|
|
944
|
+
labeldistance=1.1,
|
|
945
|
+
textprops={"fontsize": 30},
|
|
946
|
+
)
|
|
947
|
+
axis.set_title(title, fontsize=40)
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
def cars_profile(name=None, interval=0.1):
|
|
951
|
+
"""
|
|
952
|
+
CARS profiling decorator
|
|
953
|
+
|
|
954
|
+
:param: func: function to monitor
|
|
955
|
+
|
|
956
|
+
"""
|
|
957
|
+
|
|
958
|
+
def decorator_generator(func):
|
|
959
|
+
"""
|
|
960
|
+
Inner function
|
|
961
|
+
"""
|
|
962
|
+
|
|
963
|
+
def wrapper_cars_profile(*args, **kwargs):
|
|
964
|
+
"""
|
|
965
|
+
Profiling wrapper
|
|
966
|
+
|
|
967
|
+
Generate profiling logs of functio, run
|
|
968
|
+
|
|
969
|
+
:return: func(*args, **kwargs)
|
|
970
|
+
|
|
971
|
+
"""
|
|
972
|
+
start_time = time.time()
|
|
973
|
+
|
|
974
|
+
memory_start = get_current_memory()
|
|
975
|
+
|
|
976
|
+
# Launch memory profiling thread
|
|
977
|
+
child_pipe, parent_pipe = Pipe()
|
|
978
|
+
thread_monitoring = CarsMemProf(
|
|
979
|
+
os.getpid(), child_pipe, interval=interval
|
|
980
|
+
)
|
|
981
|
+
thread_monitoring.start()
|
|
982
|
+
if parent_pipe.poll(THREAD_TIMEOUT):
|
|
983
|
+
parent_pipe.recv()
|
|
984
|
+
|
|
985
|
+
res = func(*args, **kwargs)
|
|
986
|
+
total_time = time.time() - start_time
|
|
987
|
+
|
|
988
|
+
# end memprofiling monitoring
|
|
989
|
+
parent_pipe.send(0)
|
|
990
|
+
max_memory = None
|
|
991
|
+
max_cpu = None
|
|
992
|
+
if parent_pipe.poll(THREAD_TIMEOUT):
|
|
993
|
+
max_memory = parent_pipe.recv()
|
|
994
|
+
if parent_pipe.poll(THREAD_TIMEOUT):
|
|
995
|
+
max_cpu = parent_pipe.recv()
|
|
996
|
+
memory_end = get_current_memory()
|
|
997
|
+
|
|
998
|
+
func_name = name
|
|
999
|
+
if name is None:
|
|
1000
|
+
func_name = func.__name__.capitalize()
|
|
1001
|
+
|
|
1002
|
+
message = (
|
|
1003
|
+
"CarsProfiling# %{}%: %{:.4f}% s Max ram : %{}% MiB"
|
|
1004
|
+
" Start Ram: %{}% MiB, End Ram: %{}% MiB, "
|
|
1005
|
+
" Max CPU usage: %{}%".format(
|
|
1006
|
+
func_name,
|
|
1007
|
+
total_time,
|
|
1008
|
+
max_memory,
|
|
1009
|
+
memory_start,
|
|
1010
|
+
memory_end,
|
|
1011
|
+
max_cpu,
|
|
1012
|
+
)
|
|
1013
|
+
)
|
|
1014
|
+
|
|
1015
|
+
cars_logging.add_profiling_message(message)
|
|
1016
|
+
|
|
1017
|
+
return res
|
|
1018
|
+
|
|
1019
|
+
return wrapper_cars_profile
|
|
1020
|
+
|
|
1021
|
+
return decorator_generator
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
class CarsMemProf(Thread):
|
|
1025
|
+
"""
|
|
1026
|
+
CarsMemProf
|
|
1027
|
+
|
|
1028
|
+
Profiling thread
|
|
1029
|
+
"""
|
|
1030
|
+
|
|
1031
|
+
def __init__(self, pid, pipe, interval=0.1):
|
|
1032
|
+
"""
|
|
1033
|
+
Init function of CarsMemProf
|
|
1034
|
+
"""
|
|
1035
|
+
super().__init__()
|
|
1036
|
+
self.pipe = pipe
|
|
1037
|
+
self.interval = interval
|
|
1038
|
+
self.cpu_interval = 0.1
|
|
1039
|
+
self.process = psutil.Process(pid)
|
|
1040
|
+
|
|
1041
|
+
def run(self):
|
|
1042
|
+
"""
|
|
1043
|
+
Run
|
|
1044
|
+
"""
|
|
1045
|
+
|
|
1046
|
+
try:
|
|
1047
|
+
max_mem = 0
|
|
1048
|
+
max_cpu = 0
|
|
1049
|
+
|
|
1050
|
+
# tell parent profiling is ready
|
|
1051
|
+
self.pipe.send(0)
|
|
1052
|
+
stop = False
|
|
1053
|
+
while True:
|
|
1054
|
+
# Get memory
|
|
1055
|
+
current_mem = self.process.memory_info().rss
|
|
1056
|
+
|
|
1057
|
+
max_mem = max(max_mem, current_mem)
|
|
1058
|
+
|
|
1059
|
+
# Get cpu max
|
|
1060
|
+
current_cpu = self.process.cpu_percent(
|
|
1061
|
+
interval=self.cpu_interval
|
|
1062
|
+
)
|
|
1063
|
+
|
|
1064
|
+
max_cpu = max(max_cpu, current_cpu)
|
|
1065
|
+
|
|
1066
|
+
if stop:
|
|
1067
|
+
break
|
|
1068
|
+
stop = self.pipe.poll(self.interval)
|
|
1069
|
+
|
|
1070
|
+
# Convert nbytes size for logger
|
|
1071
|
+
self.pipe.send(float(max_mem) / 1000000)
|
|
1072
|
+
self.pipe.send(max_cpu)
|
|
1073
|
+
|
|
1074
|
+
except BrokenPipeError:
|
|
1075
|
+
logging.debug("broken pipe error in log wrapper ")
|