reduce event to info for print compile message

This commit is contained in:
huanghui 2022-09-23 16:30:29 +08:00
parent dbf9e21c0d
commit 62792c8983
6 changed files with 10 additions and 104 deletions

View File

@ -20,22 +20,20 @@
namespace mindspore {
namespace pipeline {
void EventMessage::PrintCompileStartMsg(const std::string &phase) {
void EventMessage::PrintCompileStartMsg(const std::string &phase, const std::string &obj_desc) {
if (IsPhaseLoadFromMindIR(phase)) {
return;
}
PrintEventMessage("Start compiling and it will take a while. Please wait...");
PrintEventMessage("Start compiling " + obj_desc + " and it will take a while. Please wait...");
}
void EventMessage::PrintCompileEndMsg(const std::string &phase) {
void EventMessage::PrintCompileEndMsg(const std::string &phase, const std::string &obj_desc) {
if (IsPhaseLoadFromMindIR(phase)) {
return;
}
PrintEventMessage("End compiling.");
PrintEventMessage("End compiling " + obj_desc + ".");
}
void EventMessage::PrintEventMessage(const std::string &message) {
std::cout << "[EVENT] (PID" << getpid() << ") " << GetTimeString() << " " << message << std::endl;
}
void EventMessage::PrintEventMessage(const std::string &message) { MS_LOG(INFO) << message; }
} // namespace pipeline
} // namespace mindspore

View File

@ -24,8 +24,8 @@ namespace mindspore {
namespace pipeline {
class EventMessage {
public:
static void PrintCompileStartMsg(const std::string &phase);
static void PrintCompileEndMsg(const std::string &phase);
static void PrintCompileStartMsg(const std::string &phase, const std::string &obj_desc);
static void PrintCompileEndMsg(const std::string &phase, const std::string &obj_desc);
static void PrintEventMessage(const std::string &message);
};

View File

@ -821,9 +821,10 @@ bool GraphExecutorPy::CompileInner(const py::object &source_obj, const py::tuple
auto phase = py::cast<std::string>(phase_obj);
phase_ = phase;
auto obj_desc = GetObjDesc(source_obj);
MS_LOG(INFO) << "Start compiling, phase: " << phase;
MS_LOG(DEBUG) << "source: {" << py::str(source_obj) << "}\nargs: " << py::str(const_cast<py::tuple &>(args));
EventMessage::PrintCompileStartMsg(phase);
EventMessage::PrintCompileStartMsg(phase, obj_desc);
ExecutorInfoPtr executor_info = std::make_shared<ExecutorInfo>();
ResourcePtr resource = std::make_shared<Resource>(source_obj);
@ -899,7 +900,7 @@ bool GraphExecutorPy::CompileInner(const py::object &source_obj, const py::tuple
ReclaimOptimizer();
// Clean cache used while compile
resource->Clean();
EventMessage::PrintCompileEndMsg(phase);
EventMessage::PrintCompileEndMsg(phase, obj_desc);
MS_LOG(INFO) << "Finish compiling.";
return true;
}

View File

@ -1,30 +0,0 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
from mindspore import nn, Tensor
def run_cell():
class Net(nn.Cell):
def construct(self, x):
return x + 1
net = Net()
a = Tensor([0])
net(a)
if __name__ == "__main__":
run_cell()

View File

@ -1,19 +0,0 @@
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
set -e
python ./run.py > ./tmp.log 2>&1
exit 0

View File

@ -1,44 +0,0 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
import os
import re
import pytest
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_compile_remind_msg():
"""
Feature: Compile start and end remind message print.
Description: Test start and end remind message.
Expectation: Run success.
"""
sh_path = os.path.split(os.path.realpath(__file__))[0]
ret = os.system(f"sh {sh_path}/run.sh")
assert ret == 0
file_name = f"{sh_path}/tmp.log"
assert os.path.exists(file_name)
with open(os.path.join(file_name), 'r') as f:
contend = f.read()
assert len(re.findall(r"EVENT", contend)) == 2
assert len(re.findall(r"PID", contend)) == 2
assert len(
re.findall(r"Start compiling and it will take a while. Please wait...", contend)) == 1
assert len(re.findall(r"End compiling.", contend)) == 1
os.remove(file_name)