Skip to content

Commit

Permalink
Tweak some printed debugging for style.
Browse files Browse the repository at this point in the history
Change-Id: Idf26536195c850db997e0ab3fc7e25735028b54e
Reviewed-on: https://code-review.googlesource.com/c/re2/+/47630
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Oct 29, 2019
1 parent dadeb5c commit eecfdbf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
15 changes: 6 additions & 9 deletions re2/dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ DFA::DFA(Prog* prog, Prog::MatchKind kind, int64_t max_mem)
q1_(NULL),
mem_budget_(max_mem) {
if (ExtraDebug)
fprintf(stderr, "\nkind %d\n%s\n", (int)kind_, prog_->DumpUnanchored().c_str());
fprintf(stderr, "\nkind %d\n%s\n", kind_, prog_->DumpUnanchored().c_str());
int nmark = 0;
if (kind_ == Prog::kLongestMatch)
nmark = prog_->size();
Expand Down Expand Up @@ -989,8 +989,8 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
}

if (ExtraDebug)
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n", DumpWorkq(oldq).c_str(),
c, flag, DumpWorkq(newq).c_str(), *ismatch);
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
DumpWorkq(oldq).c_str(), c, flag, DumpWorkq(newq).c_str(), *ismatch);
}

// Processes input byte c in state, returning new state.
Expand Down Expand Up @@ -1367,8 +1367,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,

while (p != ep) {
if (ExtraDebug)
fprintf(stderr, "@%td: %s\n",
p - bp, DumpState(s).c_str());
fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());

if (have_first_byte && s == start) {
// In start state, only way out is to find first_byte,
Expand Down Expand Up @@ -1476,8 +1475,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
else
lastmatch = p + 1;
if (ExtraDebug)
fprintf(stderr, "match @%td! [%s]\n",
lastmatch - bp, DumpState(s).c_str());
fprintf(stderr, "match @%td! [%s]\n", lastmatch - bp, DumpState(s).c_str());
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
Expand Down Expand Up @@ -1780,8 +1778,7 @@ bool DFA::Search(const StringPiece& text,
if (ExtraDebug) {
fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str());
fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n",
std::string(text).c_str(), anchored, want_earliest_match,
run_forward, kind_);
std::string(text).c_str(), anchored, want_earliest_match, run_forward, kind_);
}

RWLocker l(&cache_mutex_);
Expand Down
16 changes: 8 additions & 8 deletions re2/nfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ std::string NFA::FormatCapture(const char** capture) {
if (capture[i] == NULL)
s += "(?,?)";
else if (capture[i+1] == NULL)
s += StringPrintf("(%d,?)",
(int)(capture[i] - btext_));
s += StringPrintf("(%td,?)",
capture[i] - btext_);
else
s += StringPrintf("(%d,%d)",
(int)(capture[i] - btext_),
(int)(capture[i+1] - btext_));
s += StringPrintf("(%td,%td)",
capture[i] - btext_,
capture[i+1] - btext_);
}
return s;
}
Expand Down Expand Up @@ -493,8 +493,7 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,

if (ExtraDebug)
fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
std::string(text).c_str(), std::string(context).c_str(), anchored,
longest);
std::string(text).c_str(), std::string(context).c_str(), anchored, longest);

// Set up search.
Threadq* runq = &q0_;
Expand Down Expand Up @@ -606,7 +605,8 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
if (ExtraDebug)
fprintf(stderr, "match (%td,%td)\n",
match_[0] - btext_, match_[1] - btext_);
match_[0] - btext_,
match_[1] - btext_);
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions re2/onepass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ bool Prog::IsOnePass() {
if (!AddQ(&workq, ip->out())) {
if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: multiple paths %d -> %d\n", *it, ip->out());
"Not OnePass: multiple paths %d -> %d", *it, ip->out());
goto fail;
}
id = ip->out();
Expand All @@ -561,7 +561,7 @@ bool Prog::IsOnePass() {
// (3) is violated
if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: multiple matches from %d\n", *it);
"Not OnePass: multiple matches from %d", *it);
goto fail;
}
matched = true;
Expand Down
6 changes: 4 additions & 2 deletions re2/testing/exhaustive_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ static void PrintResult(const RE2& re, const StringPiece& input, RE2::Anchor anc
printf("-");
else
printf("%td-%td",
m[i].begin() - input.begin(), m[i].end() - input.begin());
m[i].begin() - input.begin(),
m[i].end() - input.begin());
}
}

Expand All @@ -77,8 +78,9 @@ static void PrintResult(const RE2& re, const StringPiece& input, RE2::Anchor anc
void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
regexps_++;
std::string regexp = const_regexp;
if (!topwrapper_.empty())
if (!topwrapper_.empty()) {
regexp = StringPrintf(topwrapper_.c_str(), regexp.c_str());
}

if (GetFlag(FLAGS_show_regexps)) {
printf("\r%s", regexp.c_str());
Expand Down
27 changes: 18 additions & 9 deletions re2/testing/regexp_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@ void MemoryUsage() {
CHECK(re);
// Can't pass mc.HeapGrowth() and mc.PeakHeapGrowth() to LOG(INFO) directly,
// because LOG(INFO) might do a big allocation before they get evaluated.
fprintf(stderr, "Regexp: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "Regexp: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
mc.Reset();

Prog* prog = re->CompileToProg(0);
CHECK(prog);
CHECK(prog->IsOnePass());
CHECK(prog->CanBitState());
fprintf(stderr, "Prog: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "Prog: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
mc.Reset();

StringPiece sp[4];
CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
fprintf(stderr, "Search: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "Search: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
delete prog;
re->Decref();
}
Expand All @@ -80,28 +83,34 @@ void MemoryUsage() {
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);

PCRE re(regexp, PCRE::UTF8);
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
PCRE::FullMatch(text, re);
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
}

{
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);

PCRE* re = new PCRE(regexp, PCRE::UTF8);
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
PCRE::FullMatch(text, *re);
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
delete re;
}

{
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);

RE2 re(regexp);
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
RE2::FullMatch(text, re);
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n", mc.HeapGrowth(), mc.PeakHeapGrowth());
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
mc.HeapGrowth(), mc.PeakHeapGrowth());
}

fprintf(stderr, "sizeof: PCRE=%zd RE2=%zd Prog=%zd Inst=%zd\n",
Expand Down
3 changes: 2 additions & 1 deletion re2/testing/tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ static std::string FormatCapture(const StringPiece& text,
if (s.data() == NULL)
return "(?,?)";
return StringPrintf("(%td,%td)",
s.begin() - text.begin(), s.end() - text.begin());
s.begin() - text.begin(),
s.end() - text.begin());
}

// Returns whether text contains non-ASCII (>= 0x80) bytes.
Expand Down

0 comments on commit eecfdbf

Please sign in to comment.