clang-format existing code in statsd.
Added .clang-format, because there isn't an official .clang-format file for Android framework code.
before we upload changes, do:
clang-format -style=file -i [file list]
to format the files that you touched.
Test: formatting only. NO code changes.
Change-Id: I90e87f1ee6618da8ea9bc2221c609c415a4046a8
diff --git a/cmds/statsd/.clang-format b/cmds/statsd/.clang-format
new file mode 100644
index 0000000..3d64bee
--- /dev/null
+++ b/cmds/statsd/.clang-format
@@ -0,0 +1,14 @@
+BasedOnStyle: Google
+AllowShortIfStatementsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: false
+AllowShortLoopsOnASingleLine: true
+BinPackArguments: true
+BinPackParameters: true
+ColumnLimit: 100
+CommentPragmas: NOLINT:.*
+ContinuationIndentWidth: 8
+DerivePointerAlignment: false
+IndentWidth: 4
+PointerAlignment: Left
+TabWidth: 4
+AccessModifierOffset: -4
diff --git a/cmds/statsd/src/AnomalyMonitor.cpp b/cmds/statsd/src/AnomalyMonitor.cpp
index 2d3454a..92fe844 100644
--- a/cmds/statsd/src/AnomalyMonitor.cpp
+++ b/cmds/statsd/src/AnomalyMonitor.cpp
@@ -26,8 +26,7 @@
namespace statsd {
AnomalyMonitor::AnomalyMonitor(uint32_t minDiffToUpdateRegisteredAlarmTimeSec)
- : mRegisteredAlarmTimeSec(0),
- mMinUpdateTimeSec(minDiffToUpdateRegisteredAlarmTimeSec) {
+ : mRegisteredAlarmTimeSec(0), mMinUpdateTimeSec(minDiffToUpdateRegisteredAlarmTimeSec) {
}
AnomalyMonitor::~AnomalyMonitor() {
@@ -63,7 +62,7 @@
if (DEBUG) ALOGD("Adding alarm with time %u", alarm->timestampSec);
mPq.push(alarm);
if (mRegisteredAlarmTimeSec < 1 ||
- alarm->timestampSec + mMinUpdateTimeSec < mRegisteredAlarmTimeSec) {
+ alarm->timestampSec + mMinUpdateTimeSec < mRegisteredAlarmTimeSec) {
updateRegisteredAlarmTime_l(alarm->timestampSec);
}
}
@@ -100,9 +99,9 @@
}
int64_t AnomalyMonitor::secToMs(uint32_t timeSec) {
- return ((int64_t) timeSec) * 1000;
+ return ((int64_t)timeSec) * 1000;
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/AnomalyMonitor.h b/cmds/statsd/src/AnomalyMonitor.h
index e89afa8..d78be54 100644
--- a/cmds/statsd/src/AnomalyMonitor.h
+++ b/cmds/statsd/src/AnomalyMonitor.h
@@ -17,8 +17,8 @@
#ifndef ANOMALY_MONITOR_H
#define ANOMALY_MONITOR_H
-#include <indexed_priority_queue.h>
#include <android/os/IStatsCompanionService.h>
+#include <indexed_priority_queue.h>
#include <utils/RefBase.h>
#include <queue>
@@ -56,7 +56,7 @@
* Manages alarms for Anomaly Detection.
*/
class AnomalyMonitor : public RefBase {
- public:
+public:
/**
* @param minDiffToUpdateRegisteredAlarmTimeSec If the soonest alarm differs
* from the registered alarm by more than this amount, update the registered
@@ -94,7 +94,7 @@
return mRegisteredAlarmTimeSec;
}
- private:
+private:
std::mutex mLock;
/**
@@ -131,8 +131,8 @@
int64_t secToMs(uint32_t timeSec);
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif // ANOMALY_MONITOR_H
\ No newline at end of file
+#endif // ANOMALY_MONITOR_H
\ No newline at end of file
diff --git a/cmds/statsd/src/DropboxReader.cpp b/cmds/statsd/src/DropboxReader.cpp
index 307e771..27a01c8c 100644
--- a/cmds/statsd/src/DropboxReader.cpp
+++ b/cmds/statsd/src/DropboxReader.cpp
@@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <android/os/DropBoxManager.h>
#include <android-base/file.h>
+#include <android/os/DropBoxManager.h>
#include <androidfw/ZipUtils.h>
#include "DropboxReader.h"
-using android::sp;
using android::String16;
-using android::binder::Status;
-using android::base::unique_fd;
-using android::os::DropBoxManager;
using android::ZipUtils;
+using android::base::unique_fd;
+using android::binder::Status;
+using android::os::DropBoxManager;
+using android::sp;
using std::vector;
namespace android {
@@ -37,10 +37,9 @@
long timestamp = msec;
// instead of while(true), put a hard limit 1000. Dropbox won't have more than 1000 files.
- for(int i = 0; i < 1000; i++ ) {
+ for (int i = 0; i < 1000; i++) {
DropBoxManager::Entry entry;
- Status status = dropbox->getNextEntry(String16(tag.c_str()),
- timestamp, &entry);
+ Status status = dropbox->getNextEntry(String16(tag.c_str()), timestamp, &entry);
if (!status.isOk()) {
ALOGD("No more entries, or failed to read. We can't tell unfortunately.");
return android::OK;
@@ -69,15 +68,14 @@
}
bool DropboxReader::parseFromGzipFile(const unique_fd& fd, StatsLogReport& logReport) {
- FILE *file = fdopen(fd, "r");
+ FILE* file = fdopen(fd, "r");
bool result = false;
bool scanResult;
int method;
long compressedLen;
long uncompressedLen;
unsigned long crc32;
- scanResult = ZipUtils::examineGzip(file, &method, &uncompressedLen,
- &compressedLen, &crc32);
+ scanResult = ZipUtils::examineGzip(file, &method, &uncompressedLen, &compressedLen, &crc32);
if (scanResult && method == kCompressDeflated) {
vector<uint8_t> buf(uncompressedLen);
if (ZipUtils::inflateToBuffer(file, &buf[0], uncompressedLen, compressedLen)) {
@@ -107,8 +105,8 @@
}
void DropboxReader::printLog(FILE* out, const StatsLogReport& logReport) {
- fprintf(out, "start_time_msec=%lld, end_time_msec=%lld, ",
- logReport.start_report_millis(), logReport.end_report_millis());
+ fprintf(out, "start_time_msec=%lld, end_time_msec=%lld, ", logReport.start_report_millis(),
+ logReport.end_report_millis());
for (int i = 0; i < logReport.event_metrics().data_size(); i++) {
EventMetricData eventMetricData = logReport.event_metrics().data(i);
for (int j = 0; j < eventMetricData.key_value_pair_size(); j++) {
@@ -121,6 +119,6 @@
fprintf(out, "\n");
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/DropboxReader.h b/cmds/statsd/src/DropboxReader.h
index b7f8739..a5a28d9 100644
--- a/cmds/statsd/src/DropboxReader.h
+++ b/cmds/statsd/src/DropboxReader.h
@@ -40,13 +40,13 @@
static bool parseFromGzipFile(const unique_fd& fd, StatsLogReport& logReport);
static void printLog(FILE* out, const StatsLogReport& logReport);
enum {
- kCompressStored = 0, // no compression
- kCompressDeflated = 8, // standard deflate
+ kCompressStored = 0, // no compression
+ kCompressDeflated = 8, // standard deflate
};
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif //DROPBOX_READER_H
+#endif // DROPBOX_READER_H
diff --git a/cmds/statsd/src/DropboxWriter.cpp b/cmds/statsd/src/DropboxWriter.cpp
index b9d48fa..37df834 100644
--- a/cmds/statsd/src/DropboxWriter.cpp
+++ b/cmds/statsd/src/DropboxWriter.cpp
@@ -18,18 +18,17 @@
#include "DropboxWriter.h"
+using android::String16;
using android::binder::Status;
using android::os::DropBoxManager;
using android::sp;
-using android::String16;
using std::vector;
namespace android {
namespace os {
namespace statsd {
-DropboxWriter::DropboxWriter(const string& tag)
- : mTag(tag), mLogReport(), mBufferSize(0) {
+DropboxWriter::DropboxWriter(const string& tag) : mTag(tag), mLogReport(), mBufferSize(0) {
}
void DropboxWriter::addStatsLogReport(const StatsLogReport& log) {
@@ -52,16 +51,15 @@
vector<uint8_t> buffer(numBytes);
sp<DropBoxManager> dropbox = new DropBoxManager();
mLogReport.SerializeToArray(&buffer[0], numBytes);
- Status status = dropbox->addData(String16(mTag.c_str()), &buffer[0],
- numBytes, 0 /* no flag */);
+ Status status = dropbox->addData(String16(mTag.c_str()), &buffer[0], numBytes, 0 /* no flag */);
if (!status.isOk()) {
ALOGE("failed to write to dropbox");
- //TODO: What to do if flush fails??
+ // TODO: What to do if flush fails??
}
mLogReport.Clear();
mBufferSize = 0;
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/DropboxWriter.h b/cmds/statsd/src/DropboxWriter.h
index 59629fb..1fd0d75 100644
--- a/cmds/statsd/src/DropboxWriter.h
+++ b/cmds/statsd/src/DropboxWriter.h
@@ -52,21 +52,20 @@
StatsLogReport mLogReport;
/* Current *serialized* size of the logs kept in memory.
- To save computation, we will not calculate the size of the StatsLogReport every time when a new
- entry is added, which would recursively call ByteSize() on every log entry. Instead, we keep
- the sum of all individual stats log entry sizes. The size of a proto is approximately the sum
- of the size of all member protos.
+ To save computation, we will not calculate the size of the StatsLogReport every time when a
+ new entry is added, which would recursively call ByteSize() on every log entry. Instead, we
+ keep the sum of all individual stats log entry sizes. The size of a proto is approximately
+ the sum of the size of all member protos.
*/
size_t mBufferSize = 0;
/* Check if the buffer size exceeds the max buffer size when the new entry is added, and flush
the logs to dropbox if true. */
void flushIfNecessary(const StatsLogReport& log);
-
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif //DROPBOX_WRITER_H
+#endif // DROPBOX_WRITER_H
diff --git a/cmds/statsd/src/LogEntryPrinter.cpp b/cmds/statsd/src/LogEntryPrinter.cpp
index c877b05..63465b0 100644
--- a/cmds/statsd/src/LogEntryPrinter.cpp
+++ b/cmds/statsd/src/LogEntryPrinter.cpp
@@ -26,9 +26,7 @@
namespace os {
namespace statsd {
-LogEntryPrinter::LogEntryPrinter(int out)
- :m_out(out)
-{
+LogEntryPrinter::LogEntryPrinter(int out) : m_out(out) {
// Initialize the EventTagMap, which is how we know the names of the numeric event tags.
// If this fails, we can't print well, but something will print.
m_tags = android_openEventTagMap(NULL);
@@ -38,23 +36,20 @@
android_log_setPrintFormat(m_format, FORMAT_THREADTIME);
}
-LogEntryPrinter::~LogEntryPrinter()
-{
+LogEntryPrinter::~LogEntryPrinter() {
if (m_tags != NULL) {
android_closeEventTagMap(m_tags);
}
android_log_format_free(m_format);
}
-void
-LogEntryPrinter::OnLogEvent(const log_msg& msg)
-{
+void LogEntryPrinter::OnLogEvent(const log_msg& msg) {
status_t err;
AndroidLogEntry entry;
char buf[1024];
- err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1),
- &entry, m_tags, buf, sizeof(buf));
+ err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1), &entry,
+ m_tags, buf, sizeof(buf));
if (err == NO_ERROR) {
android_log_printLogLine(m_format, m_out, &entry);
} else {
@@ -63,7 +58,6 @@
}
}
-} // namespace statsd
-} // namespace os
-} // namespace android
-
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/LogEntryPrinter.h b/cmds/statsd/src/LogEntryPrinter.h
index ed720dc..4f79028 100644
--- a/cmds/statsd/src/LogEntryPrinter.h
+++ b/cmds/statsd/src/LogEntryPrinter.h
@@ -30,8 +30,7 @@
/**
* Decodes the log entry and prints it to the supplied file descriptor.
*/
-class LogEntryPrinter : public LogListener
-{
+class LogEntryPrinter : public LogListener {
public:
LogEntryPrinter(int out);
virtual ~LogEntryPrinter();
@@ -55,8 +54,8 @@
AndroidLogFormat* m_format;
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif // LOG_ENTRY_PRINTER_H
+#endif // LOG_ENTRY_PRINTER_H
diff --git a/cmds/statsd/src/LogReader.cpp b/cmds/statsd/src/LogReader.cpp
index c9164f9..c4ac337 100644
--- a/cmds/statsd/src/LogReader.cpp
+++ b/cmds/statsd/src/LogReader.cpp
@@ -31,37 +31,27 @@
namespace statsd {
#define SNOOZE_INITIAL_MS 100
-#define SNOOZE_MAX_MS (10 * 60 * 1000) // Ten minutes
-
+#define SNOOZE_MAX_MS (10 * 60 * 1000) // Ten minutes
// ================================================================================
-LogListener::LogListener()
-{
+LogListener::LogListener() {
}
-LogListener::~LogListener()
-{
+LogListener::~LogListener() {
}
-
// ================================================================================
-LogReader::LogReader()
-{
+LogReader::LogReader() {
}
-LogReader::~LogReader()
-{
+LogReader::~LogReader() {
}
-void
-LogReader::AddListener(const sp<LogListener>& listener)
-{
+void LogReader::AddListener(const sp<LogListener>& listener) {
m_listeners.push_back(listener);
}
-void
-LogReader::Run()
-{
+void LogReader::Run() {
int nextSnoozeMs = SNOOZE_INITIAL_MS;
// In an ideal world, this outer loop will only ever run one iteration, but it
@@ -100,9 +90,7 @@
}
}
-int
-LogReader::connect_and_read()
-{
+int LogReader::connect_and_read() {
int lineCount = 0;
status_t err;
logger_list* loggers;
@@ -110,8 +98,8 @@
// Prepare the logging context
loggers = android_logger_list_alloc(ANDROID_LOG_RDONLY,
- /* don't stop after N lines */ 0,
- /* no pid restriction */ 0);
+ /* don't stop after N lines */ 0,
+ /* no pid restriction */ 0);
// Open the buffer(s)
eventLogger = android_logger_open(loggers, LOG_ID_STATS);
@@ -133,7 +121,7 @@
// Call the listeners
for (vector<sp<LogListener> >::iterator it = m_listeners.begin();
- it != m_listeners.end(); it++) {
+ it != m_listeners.end(); it++) {
(*it)->OnLogEvent(msg);
}
}
@@ -145,6 +133,6 @@
return lineCount;
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/LogReader.h b/cmds/statsd/src/LogReader.h
index 4c2afe8..fc19585 100644
--- a/cmds/statsd/src/LogReader.h
+++ b/cmds/statsd/src/LogReader.h
@@ -27,10 +27,9 @@
namespace statsd {
/**
- * Callback for LogReader
+ * Callback for LogReader
*/
-class LogListener : public virtual android::RefBase
-{
+class LogListener : public virtual android::RefBase {
public:
LogListener();
virtual ~LogListener();
@@ -43,8 +42,7 @@
/**
* Class to read logs from logd.
*/
-class LogReader : public virtual android::RefBase
-{
+class LogReader : public virtual android::RefBase {
public:
/**
* Construct the LogReader with a pointer back to the StatsService
@@ -61,9 +59,9 @@
*/
void AddListener(const android::sp<LogListener>& listener);
- /**
- * Run the main LogReader loop
- */
+ /**
+ * Run the main LogReader loop
+ */
void Run();
private:
@@ -81,8 +79,8 @@
int connect_and_read();
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif // LOGREADER_H
+#endif // LOGREADER_H
diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp
index 1ae23ef..39c101c 100644
--- a/cmds/statsd/src/StatsLogProcessor.cpp
+++ b/cmds/statsd/src/StatsLogProcessor.cpp
@@ -17,8 +17,8 @@
#include <StatsLogProcessor.h>
#include <log/log_event_list.h>
-#include <utils/Errors.h>
#include <parse_util.h>
+#include <utils/Errors.h>
using namespace android;
@@ -26,8 +26,7 @@
namespace os {
namespace statsd {
-StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs")
-{
+StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs") {
// Initialize the EventTagMap, which is how we know the names of the numeric event tags.
// If this fails, we can't print well, but something will print.
m_tags = android_openEventTagMap(NULL);
@@ -37,43 +36,38 @@
android_log_setPrintFormat(m_format, FORMAT_THREADTIME);
}
-StatsLogProcessor::~StatsLogProcessor()
-{
+StatsLogProcessor::~StatsLogProcessor() {
if (m_tags != NULL) {
android_closeEventTagMap(m_tags);
}
android_log_format_free(m_format);
}
-void
-StatsLogProcessor::OnLogEvent(const log_msg& msg)
-{
+void StatsLogProcessor::OnLogEvent(const log_msg& msg) {
status_t err;
AndroidLogEntry entry;
char buf[1024];
- err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1),
- &entry, m_tags, buf, sizeof(buf));
+ err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1), &entry,
+ m_tags, buf, sizeof(buf));
// dump all statsd logs to dropbox for now.
// TODO: Add filtering, aggregation, etc.
if (err == NO_ERROR) {
StatsLogReport logReport;
logReport.set_start_report_millis(entry.tv_sec / 1000 + entry.tv_nsec / 1000 / 1000);
- EventMetricData *eventMetricData = logReport.mutable_event_metrics()->add_data();
+ EventMetricData* eventMetricData = logReport.mutable_event_metrics()->add_data();
*eventMetricData = parse(msg);
m_dropbox_writer.addStatsLogReport(logReport);
}
}
-void
-StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config)
-{
+void StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config) {
m_configs[config_source] = config;
ALOGD("Updated configuration for source %i", config_source);
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h
index a6d182c..1e525c07 100644
--- a/cmds/statsd/src/StatsLogProcessor.h
+++ b/cmds/statsd/src/StatsLogProcessor.h
@@ -24,8 +24,7 @@
namespace os {
namespace statsd {
-class StatsLogProcessor : public LogListener
-{
+class StatsLogProcessor : public LogListener {
public:
StatsLogProcessor();
virtual ~StatsLogProcessor();
@@ -54,8 +53,8 @@
std::unordered_map<int, StatsdConfig> m_configs;
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif //STATS_LOG_PROCESSOR_H
+#endif // STATS_LOG_PROCESSOR_H
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 965c9b7..a28f085 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -29,9 +29,9 @@
#include <utils/Looper.h>
#include <utils/String16.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
using namespace android;
@@ -40,17 +40,15 @@
namespace statsd {
StatsService::StatsService(const sp<Looper>& handlerLooper)
- : mAnomalyMonitor(new AnomalyMonitor(2)) // TODO: Change this based on the config
+ : mAnomalyMonitor(new AnomalyMonitor(2)) // TODO: Change this based on the config
{
ALOGD("stats service constructed");
}
-StatsService::~StatsService()
-{
+StatsService::~StatsService() {
}
-status_t
-StatsService::setProcessor(const sp<StatsLogProcessor>& main_processor) {
+status_t StatsService::setProcessor(const sp<StatsLogProcessor>& main_processor) {
m_processor = main_processor;
ALOGD("stats service set to processor %p", m_processor.get());
return NO_ERROR;
@@ -58,9 +56,8 @@
// Implement our own because the default binder implementation isn't
// properly handling SHELL_COMMAND_TRANSACTION
-status_t
-StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
+status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
+ uint32_t flags) {
status_t err;
switch (code) {
@@ -73,10 +70,9 @@
for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
args.add(String8(data.readString16()));
}
- sp<IShellCallback> shellCallback = IShellCallback::asInterface(
- data.readStrongBinder());
- sp<IResultReceiver> resultReceiver = IResultReceiver::asInterface(
- data.readStrongBinder());
+ sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder());
+ sp<IResultReceiver> resultReceiver =
+ IResultReceiver::asInterface(data.readStrongBinder());
FILE* fin = fdopen(in, "r");
FILE* fout = fdopen(out, "w");
@@ -104,15 +100,11 @@
return NO_ERROR;
}
- default: {
- return BnStatsManager::onTransact(code, data, reply, flags);
- }
+ default: { return BnStatsManager::onTransact(code, data, reply, flags); }
}
}
-status_t
-StatsService::dump(int fd, const Vector<String16>& args)
-{
+status_t StatsService::dump(int fd, const Vector<String16>& args) {
FILE* out = fdopen(fd, "w");
if (out == NULL) {
return NO_MEMORY; // the fd is already open
@@ -121,7 +113,7 @@
fprintf(out, "StatsService::dump:");
ALOGD("StatsService::dump:");
const int N = args.size();
- for (int i=0; i<N; i++) {
+ for (int i = 0; i < N; i++) {
fprintf(out, " %s", String8(args[i]).string());
ALOGD(" %s", String8(args[i]).string());
}
@@ -131,9 +123,7 @@
return NO_ERROR;
}
-status_t
-StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>& args)
-{
+status_t StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>& args) {
if (args.size() > 0) {
if (!args[0].compare(String8("print-stats-log")) && args.size() > 1) {
return doPrintStatsLog(out, args);
@@ -147,9 +137,7 @@
return NO_ERROR;
}
-status_t
-StatsService::doLoadConfig(FILE* in)
-{
+status_t StatsService::doLoadConfig(FILE* in) {
string content;
if (!android::base::ReadFdToString(fileno(in), &content)) {
return UNKNOWN_ERROR;
@@ -165,14 +153,12 @@
}
}
-Status
-StatsService::informAnomalyAlarmFired()
-{
+Status StatsService::informAnomalyAlarmFired() {
if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired was called");
if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
return Status::fromExceptionCode(Status::EX_SECURITY,
- "Only system uid can call informAnomalyAlarmFired");
+ "Only system uid can call informAnomalyAlarmFired");
}
if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired succeeded");
@@ -181,14 +167,12 @@
return Status::ok();
}
-Status
-StatsService::informPollAlarmFired()
-{
+Status StatsService::informPollAlarmFired() {
if (DEBUG) ALOGD("StatsService::informPollAlarmFired was called");
if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
return Status::fromExceptionCode(Status::EX_SECURITY,
- "Only system uid can call informPollAlarmFired");
+ "Only system uid can call informPollAlarmFired");
}
if (DEBUG) ALOGD("StatsService::informPollAlarmFired succeeded");
@@ -197,12 +181,10 @@
return Status::ok();
}
-Status
-StatsService::systemRunning()
-{
+Status StatsService::systemRunning() {
if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
return Status::fromExceptionCode(Status::EX_SECURITY,
- "Only system uid can call systemRunning");
+ "Only system uid can call systemRunning");
}
// When system_server is up and running, schedule the dropbox task to run.
@@ -213,10 +195,9 @@
return Status::ok();
}
-void
-StatsService::sayHiToStatsCompanion()
-{
- // TODO: This method needs to be private. It is temporarily public and unsecured for testing purposes.
+void StatsService::sayHiToStatsCompanion() {
+ // TODO: This method needs to be private. It is temporarily public and unsecured for testing
+ // purposes.
sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
if (statsCompanion != nullptr) {
if (DEBUG) ALOGD("Telling statsCompanion that statsd is ready");
@@ -226,8 +207,7 @@
}
}
-sp<IStatsCompanionService>
-StatsService::getStatsCompanionService() {
+sp<IStatsCompanionService> StatsService::getStatsCompanionService() {
sp<IStatsCompanionService> statsCompanion = nullptr;
// Get statscompanion service from service manager
const sp<IServiceManager> sm(defaultServiceManager());
@@ -242,9 +222,7 @@
return statsCompanion;
}
-Status
-StatsService::statsCompanionReady()
-{
+Status StatsService::statsCompanionReady() {
if (DEBUG) ALOGD("StatsService::statsCompanionReady was called");
if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
@@ -254,8 +232,9 @@
sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
if (statsCompanion == nullptr) {
- return Status::fromExceptionCode(Status::EX_NULL_POINTER,
- "statscompanion unavailable despite it contacting statsd!");
+ return Status::fromExceptionCode(
+ Status::EX_NULL_POINTER,
+ "statscompanion unavailable despite it contacting statsd!");
}
if (DEBUG) ALOGD("StatsService::statsCompanionReady linking to statsCompanion.");
IInterface::asBinder(statsCompanion)->linkToDeath(new StatsdDeathRecipient(mAnomalyMonitor));
@@ -264,14 +243,12 @@
return Status::ok();
}
-void
-StatsdDeathRecipient::binderDied(const wp<IBinder>& who) {
+void StatsdDeathRecipient::binderDied(const wp<IBinder>& who) {
ALOGW("statscompanion service died");
mAnmlyMntr->setStatsCompanionService(nullptr);
}
-status_t
-StatsService::doPrintStatsLog(FILE* out, const Vector<String8>& args) {
+status_t StatsService::doPrintStatsLog(FILE* out, const Vector<String8>& args) {
long msec = 0;
if (args.size() > 2) {
@@ -280,13 +257,14 @@
return DropboxReader::readStatsLogs(out, args[1].string(), msec);
}
-void
-StatsService::printCmdHelp(FILE* out) {
+void StatsService::printCmdHelp(FILE* out) {
fprintf(out, "Usage:\n");
fprintf(out, "\t print-stats-log [tag_required] [timestamp_nsec_optional]\n");
- fprintf(out, "\t config\t Loads a new config from command-line (must be proto in wire-encoded format).\n");
+ fprintf(out,
+ "\t config\t Loads a new config from command-line (must be proto in wire-encoded "
+ "format).\n");
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/StatsService.h b/cmds/statsd/src/StatsService.h
index 57276d2..a956cbf 100644
--- a/cmds/statsd/src/StatsService.h
+++ b/cmds/statsd/src/StatsService.h
@@ -62,12 +62,13 @@
virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor);
- // TODO: public for testing since statsd doesn't run when system starts. Change to private later.
+ // TODO: public for testing since statsd doesn't run when system starts. Change to private
+ // later.
/** Inform statsCompanion that statsd is ready. */
virtual void sayHiToStatsCompanion();
private:
- sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
+ sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
const sp<AnomalyMonitor> mAnomalyMonitor; // TODO: Move this to a more logical file/class
@@ -84,8 +85,7 @@
// --- StatsdDeathRecipient ---
class StatsdDeathRecipient : public IBinder::DeathRecipient {
public:
- StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor)
- : mAnmlyMntr(anomalyMonitor) {
+ StatsdDeathRecipient(sp<AnomalyMonitor> anomalyMonitor) : mAnmlyMntr(anomalyMonitor) {
}
virtual void binderDied(const wp<IBinder>& who);
@@ -94,8 +94,8 @@
const sp<AnomalyMonitor> mAnmlyMntr;
};
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif // STATS_SERVICE_H
+#endif // STATS_SERVICE_H
diff --git a/cmds/statsd/src/indexed_priority_queue.h b/cmds/statsd/src/indexed_priority_queue.h
index 76409c07..c749c3e 100644
--- a/cmds/statsd/src/indexed_priority_queue.h
+++ b/cmds/statsd/src/indexed_priority_queue.h
@@ -20,11 +20,11 @@
// ALOGE can be called from this file. If header loaded by another class, use their LOG_TAG instead.
#ifndef LOG_TAG
#define LOG_TAG "statsd(indexed_priority_queue)"
-#endif //LOG_TAG
+#endif // LOG_TAG
#include <cutils/log.h>
-#include <unordered_map>
#include <utils/RefBase.h>
+#include <unordered_map>
#include <vector>
using namespace android;
@@ -49,7 +49,7 @@
*/
template <class AA, class Comparator>
class indexed_priority_queue {
- public:
+public:
indexed_priority_queue();
/** Adds a into the priority queue. If already present or a==nullptr, does nothing. */
void push(sp<const AA> a);
@@ -62,11 +62,15 @@
/** Returns min element. Returns nullptr iff empty(). */
sp<const AA> top() const;
/** Returns number of elements in priority queue. */
- size_t size() const { return pq.size() - 1; } // pq is 1-indexed
+ size_t size() const {
+ return pq.size() - 1;
+ } // pq is 1-indexed
/** Returns true iff priority queue is empty. */
- bool empty() const { return size() < 1; }
+ bool empty() const {
+ return size() < 1;
+ }
- private:
+private:
/** Vector representing a min-heap (1-indexed, with nullptr at 0). */
std::vector<sp<const AA>> pq;
/** Mapping of each element in pq to its index in pq (i.e. the inverse of a=pq[i]). */
@@ -83,22 +87,22 @@
// Implementation must be done in this file due to use of template.
template <class AA, class Comparator>
-indexed_priority_queue<AA,Comparator>::indexed_priority_queue() {
+indexed_priority_queue<AA, Comparator>::indexed_priority_queue() {
init();
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::push(sp<const AA> a) {
+void indexed_priority_queue<AA, Comparator>::push(sp<const AA> a) {
if (a == nullptr) return;
if (contains(a)) return;
pq.push_back(a);
- size_t idx = size(); // index of last element since 1-indexed
+ size_t idx = size(); // index of last element since 1-indexed
indices.insert({a, idx});
- sift_up(idx); // get the pq back in order
+ sift_up(idx); // get the pq back in order
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::remove(sp<const AA> a) {
+void indexed_priority_queue<AA, Comparator>::remove(sp<const AA> a) {
if (a == nullptr) return;
if (!contains(a)) return;
size_t idx = indices[a];
@@ -106,7 +110,7 @@
ALOGE("indexed_priority_queue: Invalid index in map of indices.");
return;
}
- if (idx == size()) { // if a is the last element, i.e. at index idx == size() == (pq.size()-1)
+ if (idx == size()) { // if a is the last element, i.e. at index idx == size() == (pq.size()-1)
pq.pop_back();
indices.erase(a);
return;
@@ -124,62 +128,66 @@
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::clear() {
+void indexed_priority_queue<AA, Comparator>::clear() {
pq.clear();
indices.clear();
init();
}
template <class AA, class Comparator>
-sp<const AA> indexed_priority_queue<AA,Comparator>::top() const {
+sp<const AA> indexed_priority_queue<AA, Comparator>::top() const {
if (empty()) return nullptr;
return pq[1];
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::init() {
- pq.push_back(nullptr); // so that pq is 1-indexed.
- indices.insert({nullptr, 0}); // just to be consistent with pq.
+void indexed_priority_queue<AA, Comparator>::init() {
+ pq.push_back(nullptr); // so that pq is 1-indexed.
+ indices.insert({nullptr, 0}); // just to be consistent with pq.
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::sift_up(size_t idx) {
+void indexed_priority_queue<AA, Comparator>::sift_up(size_t idx) {
while (idx > 1) {
- size_t parent = idx/2;
- if (higher(idx, parent)) swap_indices(idx, parent);
- else break;
+ size_t parent = idx / 2;
+ if (higher(idx, parent))
+ swap_indices(idx, parent);
+ else
+ break;
idx = parent;
}
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::sift_down(size_t idx) {
- while (2*idx <= size()) {
+void indexed_priority_queue<AA, Comparator>::sift_down(size_t idx) {
+ while (2 * idx <= size()) {
size_t child = 2 * idx;
- if (child < size() && higher(child+1, child)) child++;
- if (higher(child, idx)) swap_indices(child, idx);
- else break;
+ if (child < size() && higher(child + 1, child)) child++;
+ if (higher(child, idx))
+ swap_indices(child, idx);
+ else
+ break;
idx = child;
}
}
template <class AA, class Comparator>
-bool indexed_priority_queue<AA,Comparator>::higher(size_t idx1, size_t idx2) const {
+bool indexed_priority_queue<AA, Comparator>::higher(size_t idx1, size_t idx2) const {
if (!(0u < idx1 && idx1 < pq.size() && 0u < idx2 && idx2 < pq.size())) {
ALOGE("indexed_priority_queue: Attempting to access invalid index");
- return false; // got to do something.
+ return false; // got to do something.
}
return Comparator()(pq[idx1], pq[idx2]);
}
template <class AA, class Comparator>
-bool indexed_priority_queue<AA,Comparator>::contains(sp<const AA> a) const {
- if (a == nullptr) return false; // publicly, we pretend that nullptr is not actually in pq.
+bool indexed_priority_queue<AA, Comparator>::contains(sp<const AA> a) const {
+ if (a == nullptr) return false; // publicly, we pretend that nullptr is not actually in pq.
return indices.count(a) > 0;
}
template <class AA, class Comparator>
-void indexed_priority_queue<AA,Comparator>::swap_indices(size_t i, size_t j) {
+void indexed_priority_queue<AA, Comparator>::swap_indices(size_t i, size_t j) {
if (!(0u < i && i < pq.size() && 0u < j && j < pq.size())) {
ALOGE("indexed_priority_queue: Attempting to swap invalid index");
return;
@@ -192,8 +200,8 @@
indices[val_j] = i;
}
-} // namespace statsd
-} // namespace os
-} // namespace android
+} // namespace statsd
+} // namespace os
+} // namespace android
-#endif //STATSD_INDEXED_PRIORITY_QUEUE_H
+#endif // STATSD_INDEXED_PRIORITY_QUEUE_H
diff --git a/cmds/statsd/src/main.cpp b/cmds/statsd/src/main.cpp
index c1dad4f..b303321 100644
--- a/cmds/statsd/src/main.cpp
+++ b/cmds/statsd/src/main.cpp
@@ -18,8 +18,8 @@
#include "LogEntryPrinter.h"
#include "LogReader.h"
-#include "StatsService.h"
#include "StatsLogProcessor.h"
+#include "StatsService.h"
#include <binder/IInterface.h>
#include <binder/IPCThreadState.h>
@@ -31,8 +31,8 @@
#include <utils/StrongPointer.h>
#include <stdio.h>
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
using namespace android;
@@ -49,9 +49,7 @@
/**
* Thread func for where the log reader runs.
*/
-static void*
-log_reader_thread_func(void* cookie)
-{
+static void* log_reader_thread_func(void* cookie) {
log_reader_thread_data* data = static_cast<log_reader_thread_data*>(cookie);
sp<LogReader> reader = new LogReader();
@@ -75,9 +73,7 @@
/**
* Creates and starts the thread to own the LogReader.
*/
-static status_t
-start_log_reader_thread(const sp<StatsService>& service)
-{
+static status_t start_log_reader_thread(const sp<StatsService>& service) {
status_t err;
pthread_attr_t attr;
pthread_t thread;
@@ -108,9 +104,7 @@
}
// ================================================================================
-int
-main(int /*argc*/, char** /*argv*/)
-{
+int main(int /*argc*/, char** /*argv*/) {
status_t err;
// Set up the looper
@@ -118,7 +112,7 @@
// Set up the binder
sp<ProcessState> ps(ProcessState::self());
- ps->setThreadPoolMaxThreadCount(1); // everything is oneway, let it queue and save ram
+ ps->setThreadPoolMaxThreadCount(1); // everything is oneway, let it queue and save ram
ps->startThreadPool();
ps->giveThreadPoolName();
IPCThreadState::self()->disableBackgroundScheduling(true);
diff --git a/cmds/statsd/src/parse_util.cpp b/cmds/statsd/src/parse_util.cpp
index ffce884..b68f135 100644
--- a/cmds/statsd/src/parse_util.cpp
+++ b/cmds/statsd/src/parse_util.cpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include <parse_util.h>
#include <log/log_event_list.h>
+#include <parse_util.h>
using android::os::statsd::EVENT_TIMESTAMP;
using android::os::statsd::EventMetricData;
@@ -25,22 +25,20 @@
using android::os::statsd::TagId;
using android::os::statsd::TagId_IsValid;
-EventMetricData parse(log_msg msg)
-{
+EventMetricData parse(log_msg msg) {
// dump all statsd logs to dropbox for now.
// TODO: Add filtering, aggregation, etc.
EventMetricData eventMetricData;
// set timestamp of the event.
- KeyValuePair *keyValuePair = eventMetricData.add_key_value_pair();
+ KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
keyValuePair->set_key(EVENT_TIMESTAMP);
keyValuePair->set_value_int(msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec);
// start iterating k,v pairs.
- android_log_context context = create_android_log_parser(const_cast<log_msg*>(&msg)->msg()
- + sizeof(uint32_t),
- const_cast<log_msg*>(&msg)->len()
- - sizeof(uint32_t));
+ android_log_context context =
+ create_android_log_parser(const_cast<log_msg*>(&msg)->msg() + sizeof(uint32_t),
+ const_cast<log_msg*>(&msg)->len() - sizeof(uint32_t));
android_log_list_element elem;
if (context) {
@@ -64,7 +62,7 @@
key = elem.data.int32;
} else if (KeyId_IsValid(key)) {
int32_t val = elem.data.int32;
- KeyValuePair *keyValuePair = eventMetricData.add_key_value_pair();
+ KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
keyValuePair->set_key(static_cast<KeyId>(key));
keyValuePair->set_value_int(val);
} else {
@@ -74,7 +72,7 @@
case EVENT_TYPE_FLOAT:
if (index % 2 == 0 && KeyId_IsValid(key)) {
float val = elem.data.float32;
- KeyValuePair *keyValuePair = eventMetricData.add_key_value_pair();
+ KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
keyValuePair->set_key(static_cast<KeyId>(key));
keyValuePair->set_value_float(val);
}
@@ -83,7 +81,7 @@
case EVENT_TYPE_STRING:
if (index % 2 == 0 && KeyId_IsValid(key)) {
char* val = elem.data.string;
- KeyValuePair *keyValuePair = eventMetricData.add_key_value_pair();
+ KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
keyValuePair->set_key(static_cast<KeyId>(key));
keyValuePair->set_value_str(val);
}
@@ -92,7 +90,7 @@
case EVENT_TYPE_LONG:
if (index % 2 == 0 && KeyId_IsValid(key)) {
int64_t val = elem.data.int64;
- KeyValuePair *keyValuePair = eventMetricData.add_key_value_pair();
+ KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
keyValuePair->set_key(static_cast<KeyId>(key));
keyValuePair->set_value_int(val);
}
diff --git a/cmds/statsd/src/parse_util.h b/cmds/statsd/src/parse_util.h
index 8750f82..e9f4c27 100644
--- a/cmds/statsd/src/parse_util.h
+++ b/cmds/statsd/src/parse_util.h
@@ -16,8 +16,8 @@
#ifndef PARSE_UTIL_H
#define PARSE_UTIL_H
-#include "LogReader.h"
#include "DropboxWriter.h"
+#include "LogReader.h"
#include <log/logprint.h>
@@ -25,4 +25,4 @@
EventMetricData parse(const log_msg msg);
-#endif // PARSE_UTIL_H
+#endif // PARSE_UTIL_H
diff --git a/cmds/statsd/tests/LogReader_test.cpp b/cmds/statsd/tests/LogReader_test.cpp
index ca538b0..2002143 100644
--- a/cmds/statsd/tests/LogReader_test.cpp
+++ b/cmds/statsd/tests/LogReader_test.cpp
@@ -21,4 +21,3 @@
TEST(LogReaderTest, TestNothingAtAll) {
printf("yay!");
}
-
diff --git a/cmds/statsd/tests/indexed_priority_queue_test.cpp b/cmds/statsd/tests/indexed_priority_queue_test.cpp
index 1aad089..e4d4d25 100644
--- a/cmds/statsd/tests/indexed_priority_queue_test.cpp
+++ b/cmds/statsd/tests/indexed_priority_queue_test.cpp
@@ -133,7 +133,6 @@
EXPECT_TRUE(ipq.contains(aa4_b));
}
-
TEST(indexed_priority_queue, remove_nonexistant) {
indexed_priority_queue<AATest, AATest::Smaller> ipq;
sp<const AATest> aa4 = new AATest{4};