diff options
author | 2016-04-28 21:38:44 -0800 | |
---|---|---|
committer | 2016-04-28 22:41:52 -0700 | |
commit | 8a3defed8412791faa4a48bfbe063119d38485b9 (patch) | |
tree | f8a92f6261cd8b9e2c4b66e0d1b5868b0e8d8912 | |
parent | c2c4bd08613465a40653860f4fc98c6fa04d21f0 (diff) |
DebugString() for all resources owned by devices.
Change: 121089711
-rw-r--r-- | tensorflow/core/BUILD | 1 | ||||
-rw-r--r-- | tensorflow/core/framework/resource_mgr.cc | 32 | ||||
-rw-r--r-- | tensorflow/core/framework/resource_mgr.h | 3 | ||||
-rw-r--r-- | tensorflow/core/platform/demangle.h | 29 | ||||
-rw-r--r-- | tensorflow/core/platform/posix/port.cc | 2 |
5 files changed, 67 insertions, 0 deletions
diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 2d1ec00e94..c8a059436c 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -797,6 +797,7 @@ cc_library( "lib/strings/regexp.h", "lib/strings/scanner.h", "lib/wav/wav_io.h", + "platform/demangle.h", "platform/denormal.h", "platform/platform.h", "platform/tensor_coding.h", diff --git a/tensorflow/core/framework/resource_mgr.cc b/tensorflow/core/framework/resource_mgr.cc index 60425eedb0..daa1075a3d 100644 --- a/tensorflow/core/framework/resource_mgr.cc +++ b/tensorflow/core/framework/resource_mgr.cc @@ -20,6 +20,8 @@ limitations under the License. #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/strings/scanner.h" +#include "tensorflow/core/lib/strings/stringprintf.h" +#include "tensorflow/core/platform/demangle.h" namespace tensorflow { @@ -41,6 +43,36 @@ void ResourceMgr::Clear() { containers_.clear(); } +string ResourceMgr::DebugString() const { + mutex_lock l(mu_); + struct Line { + const string* container; + const string type; + const string* resource; + const string detail; + }; + std::vector<Line> lines; + for (const auto& p : containers_) { + const string& container = p.first; + for (const auto& q : *p.second) { + const Key& key = q.first; + const char* type = key.first.name(); + const string& resource = key.second; + Line l{&container, port::Demangle(type), &resource, + q.second->DebugString()}; + lines.push_back(l); + } + } + std::vector<string> text; + for (const Line& line : lines) { + text.push_back(strings::Printf( + "%-20s | %-40s | %-40s | %-s", line.container->c_str(), + line.type.c_str(), line.resource->c_str(), line.detail.c_str())); + } + std::sort(text.begin(), text.end()); + return str_util::Join(text, "\n"); +} + Status ResourceMgr::DoCreate(const string& container, TypeIndex type, const string& name, ResourceBase* resource) { { diff --git a/tensorflow/core/framework/resource_mgr.h b/tensorflow/core/framework/resource_mgr.h index 804e2a5a13..6d6ce4150d 100644 --- a/tensorflow/core/framework/resource_mgr.h +++ b/tensorflow/core/framework/resource_mgr.h @@ -123,6 +123,9 @@ class ResourceMgr { // Deletes all resources in all containers. void Clear(); + // Returns a text description for all resources. + string DebugString() const; + private: typedef std::pair<TypeIndex, string> Key; struct KeyHash { diff --git a/tensorflow/core/platform/demangle.h b/tensorflow/core/platform/demangle.h new file mode 100644 index 0000000000..6ddd800589 --- /dev/null +++ b/tensorflow/core/platform/demangle.h @@ -0,0 +1,29 @@ +/* Copyright 2016 Google Inc. 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. +==============================================================================*/ + +#ifndef THIRD_PARTY_TENSORFLOW_CORE_PLATFORM_DEMANGLE_H_ +#define THIRD_PARTY_TENSORFLOW_CORE_PLATFORM_DEMANGLE_H_ + +namespace tensorflow { +namespace port { + +// If the compiler supports, demangle a mangled symbol name and return +// the demangled name. Otherwise, returns 'mangled' as is. +string Demangle(const char* mangled); + +} // namespace port +} // namespace tensorflow + +#endif // THIRD_PARTY_TENSORFLOW_CORE_PLATFORM_DEMANGLE_H_ diff --git a/tensorflow/core/platform/posix/port.cc b/tensorflow/core/platform/posix/port.cc index a0f6338ad9..71357b77c5 100644 --- a/tensorflow/core/platform/posix/port.cc +++ b/tensorflow/core/platform/posix/port.cc @@ -112,5 +112,7 @@ bool Snappy_Uncompress(const char* input, size_t length, char* output) { #endif } +string Demangle(const char* mangled) { return mangled; } + } // namespace port } // namespace tensorflow |