Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1698)

Unified Diff: counter.cc

Issue 2736008: Measure and report time between user-space process crashes. (Closed) Base URL: ssh://git@chromiumos-git/metrics.git
Patch Set: No need to start the back off again on crashes. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « counter.h ('k') | counter_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: counter.cc
diff --git a/counter.cc b/counter.cc
index 34fcf711628ac0520add8e35178391ea2858cf7e..58dbae45786e8e5f73581ea3c24ea064cc2c980c 100644
--- a/counter.cc
+++ b/counter.cc
@@ -58,11 +58,16 @@ void TaggedCounter::Flush() {
}
void TaggedCounter::UpdateInternal(int tag, int count, bool flush) {
- // If there's no new data and the last record in the aggregation
- // file is with the same tag, there's nothing to do.
- if (!flush && count <= 0 &&
- record_state_ == kRecordValid && record_.tag() == tag)
- return;
+ if (flush) {
+ // Flushing but record is null, so nothing to do.
+ if (record_state_ == kRecordNull)
+ return;
+ } else {
+ // If there's no new data and the last record in the aggregation
+ // file is with the same tag, there's nothing to do.
+ if (count <= 0 && record_state_ == kRecordValid && record_.tag() == tag)
+ return;
+ }
DLOG(INFO) << "tag: " << tag << " count: " << count << " flush: " << flush;
DCHECK(filename_);
@@ -78,7 +83,7 @@ void TaggedCounter::UpdateInternal(int tag, int count, bool flush) {
ReadRecord(fd);
ReportRecord(tag, flush);
- UpdateRecord(tag, count);
+ UpdateRecord(tag, count, flush);
WriteRecord(fd);
HANDLE_EINTR(close(fd));
@@ -89,7 +94,7 @@ void TaggedCounter::ReadRecord(int fd) {
return;
if (HANDLE_EINTR(read(fd, &record_, sizeof(record_))) == sizeof(record_)) {
- if (record_.count() > 0) {
+ if (record_.count() >= 0) {
record_state_ = kRecordValid;
return;
}
@@ -106,7 +111,7 @@ void TaggedCounter::ReadRecord(int fd) {
void TaggedCounter::ReportRecord(int tag, bool flush) {
// If no valid record, there's nothing to report.
if (record_state_ != kRecordValid) {
- DCHECK(record_state_ == kRecordNull);
+ DCHECK_EQ(record_state_, kRecordNull);
return;
}
@@ -121,9 +126,11 @@ void TaggedCounter::ReportRecord(int tag, bool flush) {
record_state_ = kRecordNullDirty;
}
-void TaggedCounter::UpdateRecord(int tag, int count) {
- if (count <= 0)
+void TaggedCounter::UpdateRecord(int tag, int count, bool flush) {
+ if (flush) {
+ DCHECK(record_state_ == kRecordNull || record_state_ == kRecordNullDirty);
return;
+ }
switch (record_state_) {
case kRecordNull:
@@ -137,8 +144,10 @@ void TaggedCounter::UpdateRecord(int tag, int count) {
// If there's an existing record for the current tag,
// accumulates the counts.
DCHECK_EQ(record_.tag(), tag);
- record_.Add(count);
- record_state_ = kRecordValidDirty;
+ if (count > 0) {
+ record_.Add(count);
+ record_state_ = kRecordValidDirty;
+ }
break;
default:
« no previous file with comments | « counter.h ('k') | counter_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698