Statsd namespace is defined and used
Statsd code now lives in android::os::statsd namespace. Existing files
are largely modified to follow this convention.
Exception: parse_util, since it seems a bit different.
Test: code compiles and existing statsd_tests still pass
Change-Id: Idf92a071b9ed172d01eb3087a4fa3609d67a038c
diff --git a/cmds/statsd/src/AnomalyMonitor.cpp b/cmds/statsd/src/AnomalyMonitor.cpp
index 8fd5249..2d3454a 100644
--- a/cmds/statsd/src/AnomalyMonitor.cpp
+++ b/cmds/statsd/src/AnomalyMonitor.cpp
@@ -17,11 +17,13 @@
#define LOG_TAG "AnomalyMonitor"
#define DEBUG true
-#include <AnomalyMonitor.h>
+#include "AnomalyMonitor.h"
#include <cutils/log.h>
-using namespace android::os::statsd;
+namespace android {
+namespace os {
+namespace statsd {
AnomalyMonitor::AnomalyMonitor(uint32_t minDiffToUpdateRegisteredAlarmTimeSec)
: mRegisteredAlarmTimeSec(0),
@@ -100,3 +102,7 @@
int64_t AnomalyMonitor::secToMs(uint32_t timeSec) {
return ((int64_t) timeSec) * 1000;
}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/AnomalyMonitor.h b/cmds/statsd/src/AnomalyMonitor.h
index 3ee5354..e89afa8 100644
--- a/cmds/statsd/src/AnomalyMonitor.h
+++ b/cmds/statsd/src/AnomalyMonitor.h
@@ -25,7 +25,8 @@
#include <vector>
using namespace android;
-using namespace android::os;
+
+using android::os::IStatsCompanionService;
namespace android {
namespace os {
diff --git a/cmds/statsd/src/DropboxReader.cpp b/cmds/statsd/src/DropboxReader.cpp
index cda2f43..307e771 100644
--- a/cmds/statsd/src/DropboxReader.cpp
+++ b/cmds/statsd/src/DropboxReader.cpp
@@ -23,11 +23,14 @@
using android::String16;
using android::binder::Status;
using android::base::unique_fd;
-using android::os::statsd::EventMetricData;
using android::os::DropBoxManager;
using android::ZipUtils;
using std::vector;
+namespace android {
+namespace os {
+namespace statsd {
+
status_t DropboxReader::readStatsLogs(FILE* out, const string& tag, long msec) {
sp<DropBoxManager> dropbox = new DropBoxManager();
StatsLogReport logReport;
@@ -117,3 +120,7 @@
}
fprintf(out, "\n");
}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/DropboxReader.h b/cmds/statsd/src/DropboxReader.h
index f7d5a82..b7f8739 100644
--- a/cmds/statsd/src/DropboxReader.h
+++ b/cmds/statsd/src/DropboxReader.h
@@ -23,10 +23,13 @@
#include <stdio.h>
using android::base::unique_fd;
-using android::os::statsd::StatsLogReport;
using android::status_t;
using std::string;
+namespace android {
+namespace os {
+namespace statsd {
+
class DropboxReader {
public:
// msec is the start timestamp.
@@ -42,4 +45,8 @@
};
};
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif //DROPBOX_READER_H
diff --git a/cmds/statsd/src/DropboxWriter.cpp b/cmds/statsd/src/DropboxWriter.cpp
index 01a9eac..b9d48fa 100644
--- a/cmds/statsd/src/DropboxWriter.cpp
+++ b/cmds/statsd/src/DropboxWriter.cpp
@@ -18,12 +18,16 @@
#include "DropboxWriter.h"
-using android::os::DropBoxManager;
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) {
}
@@ -57,3 +61,7 @@
mLogReport.Clear();
mBufferSize = 0;
}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/DropboxWriter.h b/cmds/statsd/src/DropboxWriter.h
index 31b3f27..59629fb 100644
--- a/cmds/statsd/src/DropboxWriter.h
+++ b/cmds/statsd/src/DropboxWriter.h
@@ -20,7 +20,10 @@
#include <frameworks/base/cmds/statsd/src/stats_log.pb.h>
using std::string;
-using android::os::statsd::StatsLogReport;
+
+namespace android {
+namespace os {
+namespace statsd {
class DropboxWriter {
public:
@@ -62,4 +65,8 @@
};
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif //DROPBOX_WRITER_H
diff --git a/cmds/statsd/src/LogEntryPrinter.cpp b/cmds/statsd/src/LogEntryPrinter.cpp
index ba07308..c877b05 100644
--- a/cmds/statsd/src/LogEntryPrinter.cpp
+++ b/cmds/statsd/src/LogEntryPrinter.cpp
@@ -22,6 +22,10 @@
using namespace android;
+namespace android {
+namespace os {
+namespace statsd {
+
LogEntryPrinter::LogEntryPrinter(int out)
:m_out(out)
{
@@ -59,3 +63,7 @@
}
}
+} // namespace statsd
+} // namespace os
+} // namespace android
+
diff --git a/cmds/statsd/src/LogEntryPrinter.h b/cmds/statsd/src/LogEntryPrinter.h
index 61ffddc..ed720dc 100644
--- a/cmds/statsd/src/LogEntryPrinter.h
+++ b/cmds/statsd/src/LogEntryPrinter.h
@@ -23,6 +23,10 @@
#include <stdio.h>
+namespace android {
+namespace os {
+namespace statsd {
+
/**
* Decodes the log entry and prints it to the supplied file descriptor.
*/
@@ -51,4 +55,8 @@
AndroidLogFormat* m_format;
};
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif // LOG_ENTRY_PRINTER_H
diff --git a/cmds/statsd/src/LogReader.cpp b/cmds/statsd/src/LogReader.cpp
index 2a9e500..c9164f9 100644
--- a/cmds/statsd/src/LogReader.cpp
+++ b/cmds/statsd/src/LogReader.cpp
@@ -26,6 +26,10 @@
using namespace android;
using namespace std;
+namespace android {
+namespace os {
+namespace statsd {
+
#define SNOOZE_INITIAL_MS 100
#define SNOOZE_MAX_MS (10 * 60 * 1000) // Ten minutes
@@ -141,3 +145,6 @@
return lineCount;
}
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/LogReader.h b/cmds/statsd/src/LogReader.h
index 08a17a3..4c2afe8 100644
--- a/cmds/statsd/src/LogReader.h
+++ b/cmds/statsd/src/LogReader.h
@@ -18,11 +18,14 @@
#define LOGREADER_H
#include <log/log_read.h>
-
#include <utils/RefBase.h>
#include <vector>
+namespace android {
+namespace os {
+namespace statsd {
+
/**
* Callback for LogReader
*/
@@ -78,4 +81,8 @@
int connect_and_read();
};
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif // LOGREADER_H
diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp
index c2fffd8..1ae23ef 100644
--- a/cmds/statsd/src/StatsLogProcessor.cpp
+++ b/cmds/statsd/src/StatsLogProcessor.cpp
@@ -21,8 +21,10 @@
#include <parse_util.h>
using namespace android;
-using android::os::statsd::EventMetricData;
-using android::os::statsd::StatsLogReport;
+
+namespace android {
+namespace os {
+namespace statsd {
StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs")
{
@@ -71,3 +73,7 @@
m_configs[config_source] = config;
ALOGD("Updated configuration for source %i", config_source);
}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h
index 5df8424..a6d182c 100644
--- a/cmds/statsd/src/StatsLogProcessor.h
+++ b/cmds/statsd/src/StatsLogProcessor.h
@@ -20,7 +20,9 @@
#include <unordered_map>
-using android::os::statsd::StatsdConfig;
+namespace android {
+namespace os {
+namespace statsd {
class StatsLogProcessor : public LogListener
{
@@ -51,4 +53,9 @@
*/
std::unordered_map<int, StatsdConfig> m_configs;
};
+
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif //STATS_LOG_PROCESSOR_H
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 976fc26..965c9b7 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -34,9 +34,11 @@
#include <stdlib.h>
using namespace android;
-using android::os::statsd::StatsdConfig;
-// ================================================================================
+namespace android {
+namespace os {
+namespace statsd {
+
StatsService::StatsService(const sp<Looper>& handlerLooper)
: mAnomalyMonitor(new AnomalyMonitor(2)) // TODO: Change this based on the config
{
@@ -211,23 +213,6 @@
return Status::ok();
}
-status_t
-StatsService::doPrintStatsLog(FILE* out, const Vector<String8>& args) {
- long msec = 0;
-
- if (args.size() > 2) {
- msec = strtol(args[2].string(), NULL, 10);
- }
- return DropboxReader::readStatsLogs(out, args[1].string(), msec);
-}
-
-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");
-}
-
void
StatsService::sayHiToStatsCompanion()
{
@@ -241,6 +226,22 @@
}
}
+sp<IStatsCompanionService>
+StatsService::getStatsCompanionService() {
+ sp<IStatsCompanionService> statsCompanion = nullptr;
+ // Get statscompanion service from service manager
+ const sp<IServiceManager> sm(defaultServiceManager());
+ if (sm != nullptr) {
+ const String16 name("statscompanion");
+ statsCompanion = interface_cast<IStatsCompanionService>(sm->checkService(name));
+ if (statsCompanion == nullptr) {
+ ALOGW("statscompanion service unavailable!");
+ return nullptr;
+ }
+ }
+ return statsCompanion;
+}
+
Status
StatsService::statsCompanionReady()
{
@@ -263,24 +264,29 @@
return Status::ok();
}
-sp<IStatsCompanionService>
-StatsService::getStatsCompanionService() {
- sp<IStatsCompanionService> statsCompanion = nullptr;
- // Get statscompanion service from service manager
- const sp<IServiceManager> sm(defaultServiceManager());
- if (sm != nullptr) {
- const String16 name("statscompanion");
- statsCompanion = interface_cast<IStatsCompanionService>(sm->checkService(name));
- if (statsCompanion == nullptr) {
- ALOGW("statscompanion service unavailable!");
- return nullptr;
- }
- }
- return statsCompanion;
-}
-
void
StatsdDeathRecipient::binderDied(const wp<IBinder>& who) {
ALOGW("statscompanion service died");
mAnmlyMntr->setStatsCompanionService(nullptr);
-}
\ No newline at end of file
+}
+
+status_t
+StatsService::doPrintStatsLog(FILE* out, const Vector<String8>& args) {
+ long msec = 0;
+
+ if (args.size() > 2) {
+ msec = strtol(args[2].string(), NULL, 10);
+ }
+ return DropboxReader::readStatsLogs(out, args[1].string(), msec);
+}
+
+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");
+}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/StatsService.h b/cmds/statsd/src/StatsService.h
index 467c2bd..57276d2 100644
--- a/cmds/statsd/src/StatsService.h
+++ b/cmds/statsd/src/StatsService.h
@@ -34,12 +34,12 @@
using namespace android::base;
using namespace android::binder;
using namespace android::os;
-using namespace android::os::statsd;
using namespace std;
-using android::os::statsd::StatsdConfig;
+namespace android {
+namespace os {
+namespace statsd {
-// ================================================================================
class StatsService : public BnStatsManager {
public:
StatsService(const sp<Looper>& handlerLooper);
@@ -69,15 +69,14 @@
private:
sp<StatsLogProcessor> m_processor; // Reference to the processor for updating configs.
+ const sp<AnomalyMonitor> mAnomalyMonitor; // TODO: Move this to a more logical file/class
+
status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);
void printCmdHelp(FILE* out);
status_t doLoadConfig(FILE* in);
- const sp<AnomalyMonitor> mAnomalyMonitor; // TODO: Move this to a more logical file/class
-
- private:
/** Fetches the StatsCompanionService. */
sp<IStatsCompanionService> getStatsCompanionService();
};
@@ -95,4 +94,8 @@
const sp<AnomalyMonitor> mAnmlyMntr;
};
+} // namespace statsd
+} // namespace os
+} // namespace android
+
#endif // STATS_SERVICE_H
diff --git a/cmds/statsd/src/main.cpp b/cmds/statsd/src/main.cpp
index 161b630..c1dad4f 100644
--- a/cmds/statsd/src/main.cpp
+++ b/cmds/statsd/src/main.cpp
@@ -36,6 +36,7 @@
#include <unistd.h>
using namespace android;
+using namespace android::os::statsd;
// ================================================================================
/**