-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PIR] remove log simply name mechnism from phi to common.
- Loading branch information
1 parent
c0d6d7d
commit f12e2e5
Showing
12 changed files
with
220 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
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. */ | ||
|
||
#include "paddle/common/enforce.h" | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
REGISTER_LOG_SIMPLY_STR(std::string); | ||
|
||
namespace { | ||
class StrSizeCmp { | ||
public: | ||
bool operator()(const std::string& lhs, const std::string& rhs) const { | ||
return lhs.size() > rhs.size(); | ||
} | ||
}; | ||
|
||
using LogSimplyStrMap = std::map<std::string, std::string, StrSizeCmp>; | ||
|
||
LogSimplyStrMap& GetLogStrSimplyMap() { | ||
static LogSimplyStrMap str_simply_map; | ||
return str_simply_map; | ||
} | ||
|
||
std::string SimplifyDemangleStr(std::string str) { | ||
auto& str_map = GetLogStrSimplyMap(); | ||
for (auto& value : str_map) { | ||
size_t start_pos = 0; | ||
while ((start_pos = str.find(value.first, start_pos)) != | ||
std::string::npos) { | ||
str.replace(start_pos, value.first.length(), value.second); | ||
start_pos += value.second.length(); | ||
} | ||
} | ||
return str; | ||
} | ||
} // namespace | ||
|
||
namespace common { | ||
namespace enforce { | ||
|
||
bool RegisterLogSimplyStr(const std::string& type_name, | ||
const std::string& simply_name) { | ||
return GetLogStrSimplyMap() | ||
.emplace(std::make_pair(type_name, simply_name)) | ||
.second; | ||
} | ||
|
||
std::string GetCurrentTraceBackString(bool for_signal) { | ||
std::ostringstream sout; | ||
|
||
if (!for_signal) { | ||
sout << "\n\n--------------------------------------\n"; | ||
sout << "C++ Traceback (most recent call last):"; | ||
sout << "\n--------------------------------------\n"; | ||
} | ||
#if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL) | ||
static constexpr int TRACE_STACK_LIMIT = 100; | ||
|
||
std::array<void*, TRACE_STACK_LIMIT> call_stack; | ||
auto size = backtrace(call_stack.data(), TRACE_STACK_LIMIT); | ||
auto symbols = backtrace_symbols(call_stack.data(), size); | ||
Dl_info info; | ||
int idx = 0; | ||
// `for_signal` used to remove the stack trace introduced by | ||
// obtaining the error stack trace when the signal error occurred, | ||
// that is not related to the signal error self, remove it to | ||
// avoid misleading users and developers | ||
int end_idx = for_signal ? 2 : 0; | ||
for (int i = size - 1; i >= end_idx; --i) { | ||
if (dladdr(call_stack[i], &info) && info.dli_sname) { | ||
auto demangled = common::demangle(info.dli_sname); | ||
std::string path(info.dli_fname); | ||
// C++ traceback info are from core.so | ||
if (path.substr(path.length() - 3).compare(".so") == 0) { | ||
sout << paddle::string::Sprintf( | ||
"%-3d %s\n", idx++, SimplifyDemangleStr(demangled)); | ||
} | ||
} | ||
} | ||
free(symbols); // NOLINT | ||
#else | ||
sout << "Not support stack backtrace yet.\n"; | ||
#endif | ||
return sout.str(); | ||
} | ||
|
||
} // namespace enforce | ||
} // namespace common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
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. */ | ||
|
||
#include "paddle/fluid/framework/type_defs.h" | ||
|
||
#include "paddle/common/enforce.h" | ||
|
||
namespace paddle { | ||
|
||
using namespace framework; // NOLINT | ||
template class variant<paddle::blank, | ||
int, | ||
float, | ||
std::string, | ||
std::vector<int>, | ||
std::vector<float>, | ||
std::vector<std::string>, | ||
bool, | ||
std::vector<bool>, | ||
BlockDesc*, | ||
int64_t, | ||
std::vector<BlockDesc*>, | ||
std::vector<int64_t>, | ||
std::vector<double>, | ||
VarDesc*, | ||
std::vector<VarDesc*>, | ||
double, | ||
paddle::experimental::Scalar, | ||
std::vector<paddle::experimental::Scalar>, | ||
::pir::Block*, | ||
std::vector<::pir::Value>>; | ||
} // namespace paddle | ||
REGISTER_LOG_SIMPLY_STR(paddle::framework::AttributeMap); | ||
REGISTER_LOG_SIMPLY_STR(paddle::framework::Attribute); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
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. */ | ||
|
||
#include "paddle/fluid/imperative/type_defs.h" | ||
|
||
#include "paddle/common/enforce.h" | ||
|
||
REGISTER_LOG_SIMPLY_STR(paddle::imperative::NameTensorMap); | ||
REGISTER_LOG_SIMPLY_STR(paddle::imperative::NameVarBaseMap); | ||
REGISTER_LOG_SIMPLY_STR(paddle::imperative::NameVariableWrapperMap); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.