def test_analyser_proposal(self): """Test the function of querying the proposals from multiple different proposers""" expect_result = { "minddata_device_queue": [1, 1, 0, 1], "minddata_get_next_queue": [0, 3], "minddata_pipeline-dataset_op": ["ImageFolderOp_3"], "minddata_pipeline-general": ["ImageFolderOp_3"] } step_trace_condition = { "filter_condition": { "mode": "proc", "proc_name": "iteration_interval", "step_id": 0 } } options = {'step_trace': {"iter_interval": step_trace_condition}} proposal_type_list = [ 'step_trace', 'minddata', 'minddata_pipeline', 'common' ] proposal_obj = ComposeProposal(self.profiler, '1', proposal_type_list) proposal_info = proposal_obj.get_proposal(options) assert expect_result["minddata_device_queue"] == proposal_info[ "minddata_device_queue"] assert expect_result["minddata_get_next_queue"] == proposal_info[ "minddata_get_next_queue"] assert expect_result["minddata_pipeline-dataset_op"] == proposal_info[ "minddata_pipeline-dataset_op"] assert expect_result["minddata_pipeline-general"] == proposal_info[ "minddata_pipeline-general"]
def get_profile_summary_proposal(): """ Get summary profiling proposal. Returns: str, the summary profiling proposal. Raises: ParamValueError: If the parameters contain some errors. Examples: >>> GET http://xxxx/v1/mindinsight/profile/summary/propose """ profiler_dir = get_profiler_dir(request) train_id = get_train_id(request) device_id = get_device_id(request) if not profiler_dir or not train_id: raise ParamValueError("No profiler_dir or train_id.") to_int(device_id, 'device_id') profiler_dir_abs = os.path.join(settings.SUMMARY_BASE_DIR, train_id, profiler_dir) try: profiler_dir_abs = validate_and_normalize_path(profiler_dir_abs, "profiler") except ValidationError: raise ParamValueError("Invalid profiler dir") check_train_job_and_profiler_dir(profiler_dir_abs) step_trace_condition = { "filter_condition": { "mode": "proc", "proc_name": "iteration_interval", "step_id": 0 } } options = {'step_trace': {"iter_interval": step_trace_condition}} proposal_type_list = [ 'step_trace', 'minddata', 'minddata_pipeline', 'common' ] proposal_obj = ComposeProposal(profiler_dir_abs, device_id, proposal_type_list) proposal_info = proposal_obj.get_proposal(options) # Use json.dumps for orderly return return CustomResponse(json.dumps(proposal_info), mimetype='application/json')
def test_propose_compose(self): """Test the class of ComposeProposal.""" proposal_dict = OrderedDict() proposal_dict["step_trace-proposer_type_label"] = None proposal_dict.update(self.step_trace_proposal_dict) proposal_dict["common-proposer_type_label"] = None proposal_dict.update(self.common_proposal_dict) type_list = ['step_trace', 'minddata', 'minddata_pipeline', 'common'] condition = { "filter_condition": { 'mode': "proc", "proc_name": "iteration_interval", "step_id": 0 } } options = {'step_trace': {"iter_interval": condition}} cp = ComposeProposal(self.profiling_dir, self.device_id, type_list) result = cp.get_proposal(options=options) self.assertDictEqual(proposal_dict, result)
def test_propose_compose_exception(self): """Test the class of ComposeProposal.""" profiling_dir = os.path.realpath( os.path.join(os.path.dirname(__file__), '../../../utils/resource/')) proposal_dict = OrderedDict() proposal_dict["common-proposer_type_label"] = None proposal_dict.update(self.common_proposal_dict) type_list = ['step_trace', 'common'] condition = { "filter_condition": { 'mode': "proc", "proc_name": "iteration_interval", "step_id": 0 } } options = {'step_trace': {"iter_interval": condition}} cp = ComposeProposal(profiling_dir, self.device_id, type_list) result = cp.get_proposal(options=options) self.assertDictEqual(proposal_dict, result)