summaryrefslogtreecommitdiff
path: root/cmds
diff options
context:
space:
mode:
Diffstat (limited to 'cmds')
-rw-r--r--cmds/bootanimation/BootAnimation.cpp42
-rw-r--r--cmds/screencap/screencap.cpp47
-rw-r--r--cmds/statsd/src/atom_field_options.proto12
-rw-r--r--cmds/statsd/src/atoms.proto28
-rw-r--r--cmds/statsd/src/external/StatsPullerManager.cpp5
-rw-r--r--cmds/statsd/src/logd/LogEvent.cpp14
-rw-r--r--cmds/statsd/src/logd/LogEvent.h6
-rw-r--r--cmds/statsd/src/stats_log_util.cpp40
-rw-r--r--cmds/statsd/tests/LogEvent_test.cpp99
-rw-r--r--cmds/statsd/tools/statsd-testdrive/src/com/android/statsd/testdrive/TestDrive.java24
10 files changed, 220 insertions, 97 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index e915cc811676..5dcb392b002d 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -114,7 +114,7 @@ BootAnimation::BootAnimation(sp<Callbacks> callbacks)
void BootAnimation::onFirstRef() {
status_t err = mSession->linkToComposerDeath(this);
- ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
+ SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
if (err == NO_ERROR) {
run("BootAnimation", PRIORITY_DISPLAY);
}
@@ -128,7 +128,7 @@ sp<SurfaceComposerClient> BootAnimation::session() const {
void BootAnimation::binderDied(const wp<IBinder>&)
{
// woah, surfaceflinger died!
- ALOGD("SurfaceFlinger died, exiting...");
+ SLOGD("SurfaceFlinger died, exiting...");
// calling requestExit() is not enough here because the Surface code
// might be blocked on a condition variable that will never be updated.
@@ -360,7 +360,7 @@ bool BootAnimation::threadLoop()
bool BootAnimation::android()
{
- ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
+ SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
elapsedRealtime());
initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
@@ -508,14 +508,14 @@ static bool parseColor(const char str[7], float color[3]) {
static bool readFile(ZipFileRO* zip, const char* name, String8& outString)
{
ZipEntryRO entry = zip->findEntryByName(name);
- ALOGE_IF(!entry, "couldn't find %s", name);
+ SLOGE_IF(!entry, "couldn't find %s", name);
if (!entry) {
return false;
}
FileMap* entryMap = zip->createEntryFileMap(entry);
zip->releaseEntry(entry);
- ALOGE_IF(!entryMap, "entryMap is null");
+ SLOGE_IF(!entryMap, "entryMap is null");
if (!entryMap) {
return false;
}
@@ -616,7 +616,7 @@ void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos)
size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo);
if (length != TIME_LENGTH - 1) {
- ALOGE("Couldn't format time; abandoning boot animation clock");
+ SLOGE("Couldn't format time; abandoning boot animation clock");
mClockEnabled = false;
return;
}
@@ -654,13 +654,13 @@ bool BootAnimation::parseAnimationDesc(Animation& animation)
char pathType;
if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
- // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps);
+ // SLOGD("> w=%d, h=%d, fps=%d", width, height, fps);
animation.width = width;
animation.height = height;
animation.fps = fps;
} else if (sscanf(l, " %c %d %d %s #%6s %16s %16s",
&pathType, &count, &pause, path, color, clockPos1, clockPos2) >= 4) {
- //ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s",
+ //SLOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s",
// pathType, count, pause, path, color, clockPos1, clockPos2);
Animation::Part part;
part.playUntilComplete = pathType == 'c';
@@ -670,7 +670,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation)
part.audioData = NULL;
part.animation = NULL;
if (!parseColor(color, part.backgroundColor)) {
- ALOGE("> invalid color '#%s'", color);
+ SLOGE("> invalid color '#%s'", color);
part.backgroundColor[0] = 0.0f;
part.backgroundColor[1] = 0.0f;
part.backgroundColor[2] = 0.0f;
@@ -679,7 +679,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation)
animation.parts.add(part);
}
else if (strcmp(l, "$SYSTEM") == 0) {
- // ALOGD("> SYSTEM");
+ // SLOGD("> SYSTEM");
Animation::Part part;
part.playUntilComplete = false;
part.count = 1;
@@ -710,7 +710,7 @@ bool BootAnimation::preloadZip(Animation& animation)
while ((entry = zip->nextEntry(cookie)) != NULL) {
const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
- ALOGE("Error fetching entry file name");
+ SLOGE("Error fetching entry file name");
continue;
}
@@ -754,7 +754,7 @@ bool BootAnimation::preloadZip(Animation& animation)
}
}
} else {
- ALOGE("bootanimation.zip is compressed; must be only stored");
+ SLOGE("bootanimation.zip is compressed; must be only stored");
}
}
}
@@ -782,7 +782,7 @@ bool BootAnimation::preloadZip(Animation& animation)
frame.trimX = x;
frame.trimY = y;
} else {
- ALOGE("Error parsing trim.txt, line: %s", lineStr);
+ SLOGE("Error parsing trim.txt, line: %s", lineStr);
break;
}
}
@@ -876,7 +876,7 @@ bool BootAnimation::playAnimation(const Animation& animation)
const int animationX = (mWidth - animation.width) / 2;
const int animationY = (mHeight - animation.height) / 2;
- ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
+ SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
elapsedRealtime());
for (size_t i=0 ; i<pcount ; i++) {
const Animation::Part& part(animation.parts[i]);
@@ -949,7 +949,7 @@ bool BootAnimation::playAnimation(const Animation& animation)
nsecs_t now = systemTime();
nsecs_t delay = frameDuration - (now - lastFrame);
- //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
+ //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
lastFrame = now;
if (delay > 0) {
@@ -1048,13 +1048,13 @@ void BootAnimation::releaseAnimation(Animation* animation) const
BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn)
{
if (mLoadedFiles.indexOf(fn) >= 0) {
- ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
+ SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
fn.string());
return NULL;
}
ZipFileRO *zip = ZipFileRO::open(fn);
if (zip == NULL) {
- ALOGE("Failed to open animation zip \"%s\": %s",
+ SLOGE("Failed to open animation zip \"%s\": %s",
fn.string(), strerror(errno));
return NULL;
}
@@ -1143,7 +1143,7 @@ bool BootAnimation::TimeCheckThread::doThreadLoop() {
if (pollResult == 0) {
return true;
} else if (pollResult < 0) {
- ALOGE("Could not poll inotify events");
+ SLOGE("Could not poll inotify events");
return false;
}
@@ -1152,7 +1152,7 @@ bool BootAnimation::TimeCheckThread::doThreadLoop() {
if (length == 0) {
return true;
} else if (length < 0) {
- ALOGE("Could not read inotify events");
+ SLOGE("Could not read inotify events");
return false;
}
@@ -1183,7 +1183,7 @@ void BootAnimation::TimeCheckThread::addTimeDirWatch() {
status_t BootAnimation::TimeCheckThread::readyToRun() {
mInotifyFd = inotify_init();
if (mInotifyFd < 0) {
- ALOGE("Could not initialize inotify fd");
+ SLOGE("Could not initialize inotify fd");
return NO_INIT;
}
@@ -1191,7 +1191,7 @@ status_t BootAnimation::TimeCheckThread::readyToRun() {
if (mSystemWd < 0) {
close(mInotifyFd);
mInotifyFd = -1;
- ALOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH);
+ SLOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH);
return NO_INIT;
}
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index d334f96d47fb..8fa298060d60 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -31,6 +31,7 @@
#include <gui/ISurfaceComposer.h>
#include <ui/DisplayInfo.h>
+#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>
#include <system/graphics.h>
@@ -74,12 +75,12 @@ static SkColorType flinger2skia(PixelFormat f)
}
}
-static sk_sp<SkColorSpace> dataSpaceToColorSpace(android_dataspace d)
+static sk_sp<SkColorSpace> dataSpaceToColorSpace(ui::Dataspace d)
{
switch (d) {
- case HAL_DATASPACE_V0_SRGB:
+ case ui::Dataspace::V0_SRGB:
return SkColorSpace::MakeSRGB();
- case HAL_DATASPACE_DISPLAY_P3:
+ case ui::Dataspace::DISPLAY_P3:
return SkColorSpace::MakeRGB(
SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
default:
@@ -87,12 +88,26 @@ static sk_sp<SkColorSpace> dataSpaceToColorSpace(android_dataspace d)
}
}
-static uint32_t dataSpaceToInt(android_dataspace d)
+static ui::Dataspace pickBestDataspace(ui::ColorMode colorMode)
+{
+ switch (colorMode) {
+ case ui::ColorMode::SRGB:
+ return ui::Dataspace::V0_SRGB;
+ case ui::ColorMode::DISPLAY_P3:
+ case ui::ColorMode::BT2100_PQ:
+ case ui::ColorMode::BT2100_HLG:
+ return ui::Dataspace::DISPLAY_P3;
+ default:
+ return ui::Dataspace::V0_SRGB;
+ }
+}
+
+static uint32_t dataSpaceToInt(ui::Dataspace d)
{
switch (d) {
- case HAL_DATASPACE_V0_SRGB:
+ case ui::Dataspace::V0_SRGB:
return COLORSPACE_SRGB;
- case HAL_DATASPACE_DISPLAY_P3:
+ case ui::Dataspace::DISPLAY_P3:
return COLORSPACE_DISPLAY_P3;
default:
return COLORSPACE_UNKNOWN;
@@ -161,7 +176,6 @@ int main(int argc, char** argv)
void* base = NULL;
uint32_t w, s, h, f;
- android_dataspace d;
size_t size = 0;
// Maps orientations from DisplayInfo to ISurfaceComposer
@@ -197,8 +211,15 @@ int main(int argc, char** argv)
uint32_t captureOrientation = ORIENTATION_MAP[displayOrientation];
sp<GraphicBuffer> outBuffer;
- status_t result = ScreenshotClient::capture(display, Rect(), 0 /* reqWidth */,
- 0 /* reqHeight */, false, captureOrientation, &outBuffer);
+ ui::Dataspace reqDataspace =
+ pickBestDataspace(SurfaceComposerClient::getActiveColorMode(display));
+
+ // Due to the fact that we hard code the way we write pixels into screenshot,
+ // we hard code RGBA_8888 here.
+ ui::PixelFormat reqPixelFormat = ui::PixelFormat::RGBA_8888;
+ status_t result = ScreenshotClient::capture(display, reqDataspace, reqPixelFormat, Rect(),
+ 0 /* reqWidth */, 0 /* reqHeight */, false,
+ captureOrientation, &outBuffer);
if (result != NO_ERROR) {
close(fd);
return 1;
@@ -222,12 +243,12 @@ int main(int argc, char** argv)
h = outBuffer->getHeight();
s = outBuffer->getStride();
f = outBuffer->getPixelFormat();
- d = HAL_DATASPACE_UNKNOWN;
size = s * h * bytesPerPixel(f);
if (png) {
const SkImageInfo info =
- SkImageInfo::Make(w, h, flinger2skia(f), kPremul_SkAlphaType, dataSpaceToColorSpace(d));
+ SkImageInfo::Make(w, h, flinger2skia(f), kPremul_SkAlphaType,
+ dataSpaceToColorSpace(reqDataspace));
SkPixmap pixmap(info, base, s * bytesPerPixel(f));
struct FDWStream final : public SkWStream {
size_t fBytesWritten = 0;
@@ -244,7 +265,7 @@ int main(int argc, char** argv)
notifyMediaScanner(fn);
}
} else {
- uint32_t c = dataSpaceToInt(d);
+ uint32_t c = dataSpaceToInt(reqDataspace);
write(fd, &w, 4);
write(fd, &h, 4);
write(fd, &f, 4);
@@ -261,4 +282,4 @@ int main(int argc, char** argv)
}
return 0;
-} \ No newline at end of file
+}
diff --git a/cmds/statsd/src/atom_field_options.proto b/cmds/statsd/src/atom_field_options.proto
index 453bf7e126cd..e33bd8c97a07 100644
--- a/cmds/statsd/src/atom_field_options.proto
+++ b/cmds/statsd/src/atom_field_options.proto
@@ -64,10 +64,22 @@ message StateAtomFieldOption {
optional StateField option = 1 [default = STATE_FIELD_UNSET];
}
+// Used to generate StatsLog.write APIs.
+enum LogMode {
+ MODE_UNSET = 0;
+ // Log fields as their actual types e.g., all primary data types.
+ // Or fields that are hardcoded in stats_log_api_gen tool e.g., AttributionNode
+ MODE_AUTOMATIC = 1;
+ // Log fields in their proto binary format. These fields will not be parsed in statsd
+ MODE_BYTES = 2;
+}
+
extend google.protobuf.FieldOptions {
// Flags to decorate an atom that presents a state change.
optional StateAtomFieldOption state_field_option = 50000;
// Flags to decorate the uid fields in an atom.
optional bool is_uid = 50001 [default = false];
+
+ optional LogMode log_mode = 50002 [default = MODE_AUTOMATIC];
} \ No newline at end of file
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 37ad32044e45..2f69ac18af7c 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -22,6 +22,7 @@ option java_outer_classname = "AtomsProto";
import "frameworks/base/cmds/statsd/src/atom_field_options.proto";
import "frameworks/base/core/proto/android/app/enums.proto";
+import "frameworks/base/core/proto/android/app/launcher/launcher.proto";
import "frameworks/base/core/proto/android/app/settings_enums.proto";
import "frameworks/base/core/proto/android/app/job/enums.proto";
import "frameworks/base/core/proto/android/bluetooth/enums.proto";
@@ -67,7 +68,7 @@ message Atom {
ExcessiveCpuUsageReported excessive_cpu_usage_reported = 16;
CachedKillReported cached_kill_reported = 17;
ProcessMemoryStatReported process_memory_stat_reported = 18;
- // 19 is available
+ LauncherUIChanged launcher_event = 19;
BatterySaverModeStateChanged battery_saver_mode_state_changed = 20;
DeviceIdleModeStateChanged device_idle_mode_state_changed = 21;
DeviceIdlingModeStateChanged device_idling_mode_state_changed = 22;
@@ -186,6 +187,7 @@ message Atom {
DiskIo disk_io = 10032;
PowerProfile power_profile = 10033;
ProcStats proc_stats_pkg_proc = 10034;
+ ProcessCpuTime process_cpu_time = 10035;
NativeProcessMemoryState native_process_memory_state = 10036;
}
@@ -1438,6 +1440,14 @@ message PhoneStateChanged {
optional State state = 1;
}
+message LauncherUIChanged {
+ optional android.app.launcher.LauncherAction action = 1;
+ optional android.app.launcher.LauncherState src_state = 2;
+ optional android.app.launcher.LauncherState dst_state = 3;
+ optional android.app.launcher.LauncherExtension extension = 4 [(log_mode) = MODE_BYTES];
+ optional bool is_swipe_up_enabled = 5;
+}
+
/**
* Logs when Settings UI has changed.
*
@@ -3092,3 +3102,19 @@ message UserRestrictionChanged {
// Whether the restriction is enabled or disabled.
optional bool enabled = 2;
}
+
+/**
+ * Pulls process user time and system time. Puller takes a snapshot of all pids
+ * in the system and returns cpu stats for those that are working at the time.
+ * Dead pids will be dropped. Kernel processes are excluded.
+ * Min cool-down is 5 sec.
+ */
+message ProcessCpuTime {
+ optional int32 uid = 1 [(is_uid) = true];
+
+ optional string process_name = 2;
+ // Process cpu time in user space, cumulative from boot/process start
+ optional int64 user_time_millis = 3;
+ // Process cpu time in system space, cumulative from boot/process start
+ optional int64 system_time_millis = 4;
+} \ No newline at end of file
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index 1a9ba8a8de17..ba626f86f913 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -229,6 +229,11 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
// PowerProfile constants for power model calculations.
{android::util::POWER_PROFILE,
{{}, {}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::POWER_PROFILE)}},
+ // Process cpu stats. Min cool-down is 5 sec, inline with what AcitivityManagerService uses.
+ {android::util::PROCESS_CPU_TIME,
+ {{} /* additive fields */, {} /* non additive fields */,
+ 5 * NS_PER_SEC /* min cool-down in seconds*/,
+ new StatsCompanionServicePuller(android::util::PROCESS_CPU_TIME)}},
};
StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index 4bbcfd593366..febb9229bc95 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -267,10 +267,12 @@ LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
}
}
-LogEvent::LogEvent(int32_t tagId, int64_t timestampNs) {
+LogEvent::LogEvent(int32_t tagId, int64_t timestampNs) : LogEvent(tagId, timestampNs, 0) {}
+
+LogEvent::LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid) {
mLogdTimestampNs = timestampNs;
mTagId = tagId;
- mLogUid = 0;
+ mLogUid = uid;
mContext = create_android_logger(1937006964); // the event tag shared by all stats logs
if (mContext) {
android_log_write_int64(mContext, timestampNs);
@@ -344,7 +346,8 @@ bool LogEvent::write(float value) {
return false;
}
-bool LogEvent::writeKeyValuePairs(const std::map<int32_t, int32_t>& int_map,
+bool LogEvent::writeKeyValuePairs(int32_t uid,
+ const std::map<int32_t, int32_t>& int_map,
const std::map<int32_t, int64_t>& long_map,
const std::map<int32_t, std::string>& string_map,
const std::map<int32_t, float>& float_map) {
@@ -352,6 +355,7 @@ bool LogEvent::writeKeyValuePairs(const std::map<int32_t, int32_t>& int_map,
if (android_log_write_list_begin(mContext) < 0) {
return false;
}
+ write(uid);
for (const auto& itr : int_map) {
if (android_log_write_list_begin(mContext) < 0) {
return false;
@@ -561,6 +565,10 @@ void LogEvent::init(android_log_context context) {
}
i++;
} while ((elem.type != EVENT_TYPE_UNKNOWN) && !elem.complete);
+ if (isKeyValuePairAtom && mValues.size() > 0) {
+ mValues[0] = FieldValue(Field(android::util::KEY_VALUE_PAIRS_ATOM, getSimpleField(1)),
+ Value((int32_t)mLogUid));
+ }
}
int64_t LogEvent::GetLong(size_t key, status_t* err) const {
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h
index c7e2a8c5ca21..3d5b2abc7e3a 100644
--- a/cmds/statsd/src/logd/LogEvent.h
+++ b/cmds/statsd/src/logd/LogEvent.h
@@ -75,6 +75,9 @@ public:
// For testing. The timestamp is used as both elapsed real time and logd timestamp.
explicit LogEvent(int32_t tagId, int64_t timestampNs);
+ // For testing. The timestamp is used as both elapsed real time and logd timestamp.
+ explicit LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid);
+
/**
* Constructs a KeyValuePairsAtom LogEvent from value maps.
*/
@@ -147,7 +150,8 @@ public:
bool write(float value);
bool write(const std::vector<AttributionNodeInternal>& nodes);
bool write(const AttributionNodeInternal& node);
- bool writeKeyValuePairs(const std::map<int32_t, int32_t>& int_map,
+ bool writeKeyValuePairs(int32_t uid,
+ const std::map<int32_t, int32_t>& int_map,
const std::map<int32_t, int64_t>& long_map,
const std::map<int32_t, std::string>& string_map,
const std::map<int32_t, float>& float_map);
diff --git a/cmds/statsd/src/stats_log_util.cpp b/cmds/statsd/src/stats_log_util.cpp
index 805e5833c1eb..2498d9f32d06 100644
--- a/cmds/statsd/src/stats_log_util.cpp
+++ b/cmds/statsd/src/stats_log_util.cpp
@@ -25,15 +25,16 @@
#include <utils/Log.h>
#include <utils/SystemClock.h>
+using android::util::AtomsInfo;
using android::util::FIELD_COUNT_REPEATED;
using android::util::FIELD_TYPE_BOOL;
+using android::util::FIELD_TYPE_FIXED64;
using android::util::FIELD_TYPE_FLOAT;
using android::util::FIELD_TYPE_INT32;
using android::util::FIELD_TYPE_INT64;
-using android::util::FIELD_TYPE_UINT64;
-using android::util::FIELD_TYPE_FIXED64;
using android::util::FIELD_TYPE_MESSAGE;
using android::util::FIELD_TYPE_STRING;
+using android::util::FIELD_TYPE_UINT64;
using android::util::ProtoOutputStream;
namespace android {
@@ -294,8 +295,9 @@ void writeDimensionPathToProto(const std::vector<Matcher>& fieldMatchers,
// }
//
//
-void writeFieldValueTreeToStreamHelper(const std::vector<FieldValue>& dims, size_t* index,
- int depth, int prefix, ProtoOutputStream* protoOutput) {
+void writeFieldValueTreeToStreamHelper(int tagId, const std::vector<FieldValue>& dims,
+ size_t* index, int depth, int prefix,
+ ProtoOutputStream* protoOutput) {
size_t count = dims.size();
while (*index < count) {
const auto& dim = dims[*index];
@@ -319,9 +321,31 @@ void writeFieldValueTreeToStreamHelper(const std::vector<FieldValue>& dims, size
case FLOAT:
protoOutput->write(FIELD_TYPE_FLOAT | fieldNum, dim.mValue.float_value);
break;
- case STRING:
- protoOutput->write(FIELD_TYPE_STRING | fieldNum, dim.mValue.str_value);
+ case STRING: {
+ bool isBytesField = false;
+ // Bytes field is logged via string format in log_msg format. So here we check
+ // if this string field is a byte field.
+ std::map<int, std::vector<int>>::const_iterator itr;
+ if (depth == 0 && (itr = AtomsInfo::kBytesFieldAtoms.find(tagId)) !=
+ AtomsInfo::kBytesFieldAtoms.end()) {
+ const std::vector<int>& bytesFields = itr->second;
+ for (int bytesField : bytesFields) {
+ if (bytesField == fieldNum) {
+ // This is a bytes field
+ isBytesField = true;
+ break;
+ }
+ }
+ }
+ if (isBytesField) {
+ protoOutput->write(FIELD_TYPE_MESSAGE | fieldNum,
+ (const char*)dim.mValue.str_value.c_str(),
+ dim.mValue.str_value.length());
+ } else {
+ protoOutput->write(FIELD_TYPE_STRING | fieldNum, dim.mValue.str_value);
+ }
break;
+ }
case STORAGE:
protoOutput->write(FIELD_TYPE_MESSAGE | fieldNum,
(const char*)dim.mValue.storage_value.data(),
@@ -342,7 +366,7 @@ void writeFieldValueTreeToStreamHelper(const std::vector<FieldValue>& dims, size
}
// Directly jump to the leaf value because the repeated position field is implied
// by the position of the sub msg in the parent field.
- writeFieldValueTreeToStreamHelper(dims, index, valueDepth,
+ writeFieldValueTreeToStreamHelper(tagId, dims, index, valueDepth,
dim.mField.getPrefix(valueDepth), protoOutput);
if (msg_token != 0) {
protoOutput->end(msg_token);
@@ -359,7 +383,7 @@ void writeFieldValueTreeToStream(int tagId, const std::vector<FieldValue>& value
uint64_t atomToken = protoOutput->start(FIELD_TYPE_MESSAGE | tagId);
size_t index = 0;
- writeFieldValueTreeToStreamHelper(values, &index, 0, 0, protoOutput);
+ writeFieldValueTreeToStreamHelper(tagId, values, &index, 0, 0, protoOutput);
protoOutput->end(atomToken);
}
diff --git a/cmds/statsd/tests/LogEvent_test.cpp b/cmds/statsd/tests/LogEvent_test.cpp
index ced65f292d49..f59ac1a737e2 100644
--- a/cmds/statsd/tests/LogEvent_test.cpp
+++ b/cmds/statsd/tests/LogEvent_test.cpp
@@ -90,7 +90,7 @@ TEST(LogEventTest, TestLogParsing) {
}
TEST(LogEventTest, TestKeyValuePairsAtomParsing) {
- LogEvent event1(83, 2000);
+ LogEvent event1(83, 2000, 1000);
std::map<int32_t, int32_t> int_map;
std::map<int32_t, int64_t> long_map;
std::map<int32_t, std::string> string_map;
@@ -108,7 +108,8 @@ TEST(LogEventTest, TestKeyValuePairsAtomParsing) {
float_map[111] = 2.2f;
float_map[222] = 1.1f;
- EXPECT_TRUE(event1.writeKeyValuePairs(int_map,
+ EXPECT_TRUE(event1.writeKeyValuePairs(0, // Logging side logs 0 uid.
+ int_map,
long_map,
string_map,
float_map));
@@ -116,87 +117,92 @@ TEST(LogEventTest, TestKeyValuePairsAtomParsing) {
EXPECT_EQ(83, event1.GetTagId());
const auto& items = event1.getValues();
- EXPECT_EQ((size_t)16, items.size());
+ EXPECT_EQ((size_t)17, items.size());
const FieldValue& item0 = event1.getValues()[0];
- EXPECT_EQ(0x2010101, item0.mField.getField());
+ EXPECT_EQ(0x10000, item0.mField.getField());
EXPECT_EQ(Type::INT, item0.mValue.getType());
- EXPECT_EQ(11, item0.mValue.int_value);
+ EXPECT_EQ(1000, item0.mValue.int_value);
const FieldValue& item1 = event1.getValues()[1];
- EXPECT_EQ(0x2010182, item1.mField.getField());
+ EXPECT_EQ(0x2010201, item1.mField.getField());
EXPECT_EQ(Type::INT, item1.mValue.getType());
- EXPECT_EQ(123, item1.mValue.int_value);
+ EXPECT_EQ(11, item1.mValue.int_value);
const FieldValue& item2 = event1.getValues()[2];
- EXPECT_EQ(0x2010201, item2.mField.getField());
+ EXPECT_EQ(0x2010282, item2.mField.getField());
EXPECT_EQ(Type::INT, item2.mValue.getType());
- EXPECT_EQ(22, item2.mValue.int_value);
+ EXPECT_EQ(123, item2.mValue.int_value);
const FieldValue& item3 = event1.getValues()[3];
- EXPECT_EQ(0x2010282, item3.mField.getField());
+ EXPECT_EQ(0x2010301, item3.mField.getField());
EXPECT_EQ(Type::INT, item3.mValue.getType());
- EXPECT_EQ(345, item3.mValue.int_value);
+ EXPECT_EQ(22, item3.mValue.int_value);
const FieldValue& item4 = event1.getValues()[4];
- EXPECT_EQ(0x2010301, item4.mField.getField());
+ EXPECT_EQ(0x2010382, item4.mField.getField());
EXPECT_EQ(Type::INT, item4.mValue.getType());
- EXPECT_EQ(33, item4.mValue.int_value);
+ EXPECT_EQ(345, item4.mValue.int_value);
const FieldValue& item5 = event1.getValues()[5];
- EXPECT_EQ(0x2010382, item5.mField.getField());
- EXPECT_EQ(Type::LONG, item5.mValue.getType());
- EXPECT_EQ(678L, item5.mValue.int_value);
+ EXPECT_EQ(0x2010401, item5.mField.getField());
+ EXPECT_EQ(Type::INT, item5.mValue.getType());
+ EXPECT_EQ(33, item5.mValue.int_value);
const FieldValue& item6 = event1.getValues()[6];
- EXPECT_EQ(0x2010401, item6.mField.getField());
- EXPECT_EQ(Type::INT, item6.mValue.getType());
- EXPECT_EQ(44, item6.mValue.int_value);
+ EXPECT_EQ(0x2010482, item6.mField.getField());
+ EXPECT_EQ(Type::LONG, item6.mValue.getType());
+ EXPECT_EQ(678L, item6.mValue.int_value);
const FieldValue& item7 = event1.getValues()[7];
- EXPECT_EQ(0x2010482, item7.mField.getField());
- EXPECT_EQ(Type::LONG, item7.mValue.getType());
- EXPECT_EQ(890L, item7.mValue.int_value);
+ EXPECT_EQ(0x2010501, item7.mField.getField());
+ EXPECT_EQ(Type::INT, item7.mValue.getType());
+ EXPECT_EQ(44, item7.mValue.int_value);
const FieldValue& item8 = event1.getValues()[8];
- EXPECT_EQ(0x2010501, item8.mField.getField());
- EXPECT_EQ(Type::INT, item8.mValue.getType());
- EXPECT_EQ(1, item8.mValue.int_value);
+ EXPECT_EQ(0x2010582, item8.mField.getField());
+ EXPECT_EQ(Type::LONG, item8.mValue.getType());
+ EXPECT_EQ(890L, item8.mValue.int_value);
const FieldValue& item9 = event1.getValues()[9];
- EXPECT_EQ(0x2010583, item9.mField.getField());
- EXPECT_EQ(Type::STRING, item9.mValue.getType());
- EXPECT_EQ("test2", item9.mValue.str_value);
+ EXPECT_EQ(0x2010601, item9.mField.getField());
+ EXPECT_EQ(Type::INT, item9.mValue.getType());
+ EXPECT_EQ(1, item9.mValue.int_value);
const FieldValue& item10 = event1.getValues()[10];
- EXPECT_EQ(0x2010601, item10.mField.getField());
- EXPECT_EQ(Type::INT, item10.mValue.getType());
- EXPECT_EQ(2, item10.mValue.int_value);
+ EXPECT_EQ(0x2010683, item10.mField.getField());
+ EXPECT_EQ(Type::STRING, item10.mValue.getType());
+ EXPECT_EQ("test2", item10.mValue.str_value);
const FieldValue& item11 = event1.getValues()[11];
- EXPECT_EQ(0x2010683, item11.mField.getField());
- EXPECT_EQ(Type::STRING, item11.mValue.getType());
- EXPECT_EQ("test1", item11.mValue.str_value);
+ EXPECT_EQ(0x2010701, item11.mField.getField());
+ EXPECT_EQ(Type::INT, item11.mValue.getType());
+ EXPECT_EQ(2, item11.mValue.int_value);
const FieldValue& item12 = event1.getValues()[12];
- EXPECT_EQ(0x2010701, item12.mField.getField());
- EXPECT_EQ(Type::INT, item12.mValue.getType());
- EXPECT_EQ(111, item12.mValue.int_value);
+ EXPECT_EQ(0x2010783, item12.mField.getField());
+ EXPECT_EQ(Type::STRING, item12.mValue.getType());
+ EXPECT_EQ("test1", item12.mValue.str_value);
const FieldValue& item13 = event1.getValues()[13];
- EXPECT_EQ(0x2010784, item13.mField.getField());
- EXPECT_EQ(Type::FLOAT, item13.mValue.getType());
- EXPECT_EQ(2.2f, item13.mValue.float_value);
+ EXPECT_EQ(0x2010801, item13.mField.getField());
+ EXPECT_EQ(Type::INT, item13.mValue.getType());
+ EXPECT_EQ(111, item13.mValue.int_value);
const FieldValue& item14 = event1.getValues()[14];
- EXPECT_EQ(0x2018801, item14.mField.getField());
- EXPECT_EQ(Type::INT, item14.mValue.getType());
- EXPECT_EQ(222, item14.mValue.int_value);
+ EXPECT_EQ(0x2010884, item14.mField.getField());
+ EXPECT_EQ(Type::FLOAT, item14.mValue.getType());
+ EXPECT_EQ(2.2f, item14.mValue.float_value);
const FieldValue& item15 = event1.getValues()[15];
- EXPECT_EQ(0x2018884, item15.mField.getField());
- EXPECT_EQ(Type::FLOAT, item15.mValue.getType());
- EXPECT_EQ(1.1f, item15.mValue.float_value);
+ EXPECT_EQ(0x2018901, item15.mField.getField());
+ EXPECT_EQ(Type::INT, item15.mValue.getType());
+ EXPECT_EQ(222, item15.mValue.int_value);
+
+ const FieldValue& item16 = event1.getValues()[16];
+ EXPECT_EQ(0x2018984, item16.mField.getField());
+ EXPECT_EQ(Type::FLOAT, item16.mValue.getType());
+ EXPECT_EQ(1.1f, item16.mValue.float_value);
}
TEST(LogEventTest, TestLogParsing2) {
@@ -292,6 +298,7 @@ TEST(LogEventTest, TestKeyValuePairsEvent) {
EXPECT_EQ(83, event1.GetTagId());
EXPECT_EQ((int64_t)2000, event1.GetLogdTimestampNs());
EXPECT_EQ((int64_t)2001, event1.GetElapsedTimestampNs());
+ EXPECT_EQ((int64_t)10001, event1.GetUid());
const auto& items = event1.getValues();
EXPECT_EQ((size_t)17, items.size());
diff --git a/cmds/statsd/tools/statsd-testdrive/src/com/android/statsd/testdrive/TestDrive.java b/cmds/statsd/tools/statsd-testdrive/src/com/android/statsd/testdrive/TestDrive.java
index ae3e5a1b1dfa..cc4e386bfdf0 100644
--- a/cmds/statsd/tools/statsd-testdrive/src/com/android/statsd/testdrive/TestDrive.java
+++ b/cmds/statsd/tools/statsd-testdrive/src/com/android/statsd/testdrive/TestDrive.java
@@ -31,7 +31,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
import java.util.logging.Level;
+import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class TestDrive {
@@ -68,6 +71,12 @@ public class TestDrive {
mIsPushedAtom = atomId < PULL_ATOM_START;
TestDrive testDrive = new TestDrive();
+ TestDriveFormatter formatter = new TestDriveFormatter();
+ ConsoleHandler handler = new ConsoleHandler();
+ handler.setFormatter(formatter);
+ logger.addHandler(handler);
+ logger.setUseParentHandlers(false);
+
try {
StatsdConfig config = testDrive.createConfig(atomId);
if (config == null) {
@@ -79,7 +88,8 @@ public class TestDrive {
logger.info(config.toString());
if (mIsPushedAtom) {
logger.info(
- "Now please play with the device to trigger the event. All events should be dumped after 1 min ...");
+ "Now please play with the device to trigger the event. All events should "
+ + "be dumped after 1 min ...");
Thread.sleep(60_000);
} else {
// wait for 2 min
@@ -140,7 +150,7 @@ public class TestDrive {
// Check result
if (process.waitFor() == 0) {
- logger.info("Success!");
+ logger.fine("Success!");
} else {
// Abnormal termination: Log command parameters and output and throw ExecutionException
logger.log(Level.SEVERE, out.toString());
@@ -235,8 +245,8 @@ public class TestDrive {
ConfigMetricsReport report = reportList.getReports(reportList.getReportsCount() - 1);
// Really should be only one metric.
if (report.getMetricsCount() != 1) {
- logger.log(Level.SEVERE, "Only one report metric expected, got "
- + report.getMetricsCount());
+ logger.log(Level.SEVERE,
+ "Only one report metric expected, got " + report.getMetricsCount());
return;
}
@@ -283,4 +293,10 @@ public class TestDrive {
+ "allowed_log_source: \"AID_BLUETOOTH\"\n"
+ "\n"
+ "hash_strings_in_metric_report: false";
+
+ public static class TestDriveFormatter extends Formatter {
+ public String format(LogRecord record) {
+ return record.getMessage() + "\n";
+ }
+ }
}