Fix incidentd skip collecting timedout of a section.
By moving the section stats collection before any return statements,
it won't missing stats collection.
Bug: 77962855
Test: atest incidentd_test
Change-Id: I0900556428c51636e24df48a407eb916ccff795c
diff --git a/cmds/incidentd/src/Section.cpp b/cmds/incidentd/src/Section.cpp
index 45d6281..5604973 100644
--- a/cmds/incidentd/src/Section.cpp
+++ b/cmds/incidentd/src/Section.cpp
@@ -70,6 +70,13 @@
return WriteFully(fd, buf, p - buf) ? NO_ERROR : -errno;
}
+static void write_section_stats(IncidentMetadata::SectionStats* stats, const FdBuffer& buffer) {
+ stats->set_dump_size_bytes(buffer.data().size());
+ stats->set_dump_duration_ms(buffer.durationMs());
+ stats->set_timed_out(buffer.timedOut());
+ stats->set_is_truncated(buffer.truncated());
+}
+
// Reads data from FdBuffer and writes it to the requests file descriptor.
static status_t write_report_requests(const int id, const FdBuffer& buffer,
ReportRequestSet* requests) {
@@ -77,12 +84,6 @@
EncodedBuffer::iterator data = buffer.data();
PrivacyBuffer privacyBuffer(get_privacy_of_section(id), data);
int writeable = 0;
- IncidentMetadata::SectionStats* stats = requests->sectionStats(id);
-
- stats->set_dump_size_bytes(data.size());
- stats->set_dump_duration_ms(buffer.durationMs());
- stats->set_timed_out(buffer.timedOut());
- stats->set_is_truncated(buffer.truncated());
// The streaming ones, group requests by spec in order to save unnecessary strip operations
map<PrivacySpec, vector<sp<ReportRequest>>> requestsBySpec;
@@ -140,7 +141,8 @@
writeable++;
VLOG("Section %d flushed %zu bytes to dropbox %d with spec %d", id, privacyBuffer.size(),
requests->mainFd(), spec.dest);
- stats->set_report_size_bytes(privacyBuffer.size());
+ // Reports bytes of the section uploaded via dropbox after filtering.
+ requests->sectionStats(id)->set_report_size_bytes(privacyBuffer.size());
}
DONE:
@@ -270,7 +272,7 @@
status_t readStatus = buffer.readProcessedDataInStream(fd.get(), std::move(p2cPipe.writeFd()),
std::move(c2pPipe.readFd()),
this->timeoutMs, mIsSysfs);
-
+ write_section_stats(requests->sectionStats(this->id), buffer);
if (readStatus != NO_ERROR || buffer.timedOut()) {
ALOGW("FileSection '%s' failed to read data from incident helper: %s, timedout: %s",
this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false");
@@ -363,7 +365,7 @@
status_t readStatus = buffer.readProcessedDataInStream(
fd.get(), std::move(p2cPipe.writeFd()), std::move(c2pPipe.readFd()), this->timeoutMs,
isSysfs(mFilenames[index]));
-
+ write_section_stats(requests->sectionStats(this->id), buffer);
if (readStatus != NO_ERROR || buffer.timedOut()) {
ALOGW("GZipSection '%s' failed to read data from gzip: %s, timedout: %s",
this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false");
@@ -499,7 +501,7 @@
}
}
}
-
+ write_section_stats(requests->sectionStats(this->id), buffer);
if (timedOut || buffer.timedOut()) {
ALOGW("WorkerThreadSection '%s' timed out", this->name.string());
return NO_ERROR;
@@ -580,6 +582,7 @@
cmdPipe.writeFd().reset();
status_t readStatus = buffer.read(ihPipe.readFd().get(), this->timeoutMs);
+ write_section_stats(requests->sectionStats(this->id), buffer);
if (readStatus != NO_ERROR || buffer.timedOut()) {
ALOGW("CommandSection '%s' failed to read data from incident helper: %s, timedout: %s",
this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false");
@@ -927,4 +930,4 @@
} // namespace incidentd
} // namespace os
-} // namespace android
\ No newline at end of file
+} // namespace android