summaryrefslogtreecommitdiffstats
path: root/base/vlog.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-29 00:39:48 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-29 00:39:48 +0000
commitb0d38d4c40304f92bf1b06027b225ac807fef702 (patch)
tree588e5dae9930f8ad2e6de6800761975b80325c3e /base/vlog.cc
parent41703f7ec3774c1f9766b263ce3e9a93c03c4765 (diff)
downloadchromium_src-b0d38d4c40304f92bf1b06027b225ac807fef702.zip
chromium_src-b0d38d4c40304f92bf1b06027b225ac807fef702.tar.gz
chromium_src-b0d38d4c40304f92bf1b06027b225ac807fef702.tar.bz2
Added support for filtering on the entire pathname to --vmodule.
Also cleaned up spurious warning when --vmodule is used but --v is not. Removed slow perf unittest from vlog_unittest.cc. BUG=61123 TEST=New vlog unittests Review URL: http://codereview.chromium.org/4140007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/vlog.cc')
-rw-r--r--base/vlog.cc78
1 files changed, 55 insertions, 23 deletions
diff --git a/base/vlog.cc b/base/vlog.cc
index 6075b0b..3e892d3 100644
--- a/base/vlog.cc
+++ b/base/vlog.cc
@@ -13,11 +13,34 @@ namespace logging {
const int VlogInfo::kDefaultVlogLevel = 0;
+VlogInfo::VmodulePattern::VmodulePattern(const std::string& pattern)
+ : pattern(pattern),
+ vlog_level(VlogInfo::kDefaultVlogLevel),
+ match_target(MATCH_MODULE) {
+ // If the pattern contains a {forward,back} slash, we assume that
+ // it's meant to be tested against the entire __FILE__ string.
+ std::string::size_type first_slash = pattern.find_first_of("\\/");
+ if (first_slash != std::string::npos) {
+ // The backslash is an escape character for patterns, so we need
+ // to escape it. This is okay, because it's highly unlikely that
+ // the user would want to match literal *s or ?s. However, we may
+ // want to have our own simpler version of MatchPattern() to avoid
+ // these sorts of hacks.
+ ReplaceSubstringsAfterOffset(&this->pattern, first_slash, "\\", "\\\\");
+ match_target = MATCH_FILE;
+ }
+}
+
+VlogInfo::VmodulePattern::VmodulePattern()
+ : vlog_level(VlogInfo::kDefaultVlogLevel),
+ match_target(MATCH_MODULE) {}
+
VlogInfo::VlogInfo(const std::string& v_switch,
const std::string& vmodule_switch)
: max_vlog_level_(kDefaultVlogLevel) {
typedef std::pair<std::string, std::string> KVPair;
- if (!base::StringToInt(v_switch, &max_vlog_level_)) {
+ if (!v_switch.empty() &&
+ !base::StringToInt(v_switch, &max_vlog_level_)) {
LOG(WARNING) << "Parsed v switch \""
<< v_switch << "\" as " << max_vlog_level_;
}
@@ -29,40 +52,49 @@ VlogInfo::VlogInfo(const std::string& v_switch,
}
for (std::vector<KVPair>::const_iterator it = kv_pairs.begin();
it != kv_pairs.end(); ++it) {
- int vlog_level = kDefaultVlogLevel;
- if (!base::StringToInt(it->second, &vlog_level)) {
+ VmodulePattern pattern(it->first);
+ if (!base::StringToInt(it->second, &pattern.vlog_level)) {
LOG(WARNING) << "Parsed vlog level for \""
<< it->first << "=" << it->second
- << "\" as " << vlog_level;
+ << "\" as " << pattern.vlog_level;
}
- vmodule_levels_.push_back(std::make_pair(it->first, vlog_level));
+ vmodule_levels_.push_back(pattern);
}
}
VlogInfo::~VlogInfo() {}
+namespace {
+
+// Given a path, returns the basename with the extension chopped off
+// (and any -inl suffix). We avoid using FilePath to minimize the
+// number of dependencies the logging system has.
+base::StringPiece GetModule(const base::StringPiece& file) {
+ base::StringPiece module(file);
+ base::StringPiece::size_type last_slash_pos =
+ module.find_last_of("\\/");
+ if (last_slash_pos != base::StringPiece::npos)
+ module.remove_prefix(last_slash_pos + 1);
+ base::StringPiece::size_type extension_start = module.rfind('.');
+ module = module.substr(0, extension_start);
+ static const char kInlSuffix[] = "-inl";
+ static const int kInlSuffixLen = arraysize(kInlSuffix) - 1;
+ if (module.ends_with(kInlSuffix))
+ module.remove_suffix(kInlSuffixLen);
+ return module;
+}
+
+} // namespace
+
int VlogInfo::GetVlogLevel(const base::StringPiece& file) {
if (!vmodule_levels_.empty()) {
- base::StringPiece module(file);
- base::StringPiece::size_type last_slash_pos =
- module.find_last_of("\\/");
- if (last_slash_pos != base::StringPiece::npos) {
- module.remove_prefix(last_slash_pos + 1);
- }
- base::StringPiece::size_type extension_start = module.find('.');
- module = module.substr(0, extension_start);
- static const char kInlSuffix[] = "-inl";
- static const int kInlSuffixLen = arraysize(kInlSuffix) - 1;
- if (module.ends_with(kInlSuffix)) {
- module.remove_suffix(kInlSuffixLen);
- }
+ base::StringPiece module(GetModule(file));
for (std::vector<VmodulePattern>::const_iterator it =
vmodule_levels_.begin(); it != vmodule_levels_.end(); ++it) {
- // TODO(akalin): Use a less-heavyweight version of MatchPattern
- // (we can pretty much assume we're dealing with ASCII).
- if (MatchPattern(module, it->first)) {
- return it->second;
- }
+ base::StringPiece target(
+ (it->match_target == VmodulePattern::MATCH_FILE) ? file : module);
+ if (MatchPattern(target, it->pattern))
+ return it->vlog_level;
}
}
return max_vlog_level_;