Merge "Delete StatsLogEventWrapper"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c7e7661b7f
@@ -14,7 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
// TODO(b/145815909): move StatsDimensionsValue.aidl and StatsLogEventWrapper.aidl here
|
||||
// TODO(b/145815909): move StatsDimensionsValue.aidl here
|
||||
filegroup {
|
||||
name: "statsd_aidl",
|
||||
srcs: [
|
||||
|
||||
4
cmds/statsd/src/external/Perfetto.h
vendored
4
cmds/statsd/src/external/Perfetto.h
vendored
@@ -16,10 +16,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <android/os/StatsLogEventWrapper.h>
|
||||
|
||||
using android::os::StatsLogEventWrapper;
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
@@ -71,70 +71,6 @@ LogEvent::LogEvent(const LogEvent& event) {
|
||||
mValues = event.mValues;
|
||||
}
|
||||
|
||||
LogEvent::LogEvent(const StatsLogEventWrapper& statsLogEventWrapper, int workChainIndex) {
|
||||
mTagId = statsLogEventWrapper.getTagId();
|
||||
mLogdTimestampNs = statsLogEventWrapper.getWallClockTimeNs();
|
||||
mElapsedTimestampNs = statsLogEventWrapper.getElapsedRealTimeNs();
|
||||
mLogUid = 0;
|
||||
int workChainPosOffset = 0;
|
||||
if (workChainIndex != -1) {
|
||||
const WorkChain& wc = statsLogEventWrapper.getWorkChains()[workChainIndex];
|
||||
// chains are at field 1, level 2
|
||||
int depth = 2;
|
||||
for (int i = 0; i < (int)wc.uids.size(); i++) {
|
||||
int pos[] = {1, i + 1, 1};
|
||||
mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(wc.uids[i])));
|
||||
pos[2]++;
|
||||
mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(wc.tags[i])));
|
||||
mValues.back().mField.decorateLastPos(2);
|
||||
}
|
||||
mValues.back().mField.decorateLastPos(1);
|
||||
workChainPosOffset = 1;
|
||||
}
|
||||
for (int i = 0; i < (int)statsLogEventWrapper.getElements().size(); i++) {
|
||||
Field field(statsLogEventWrapper.getTagId(), getSimpleField(i + 1 + workChainPosOffset));
|
||||
switch (statsLogEventWrapper.getElements()[i].type) {
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::INT:
|
||||
mValues.push_back(
|
||||
FieldValue(field, Value(statsLogEventWrapper.getElements()[i].int_value)));
|
||||
break;
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::LONG:
|
||||
mValues.push_back(
|
||||
FieldValue(field, Value(statsLogEventWrapper.getElements()[i].long_value)));
|
||||
break;
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::FLOAT:
|
||||
mValues.push_back(FieldValue(
|
||||
field, Value(statsLogEventWrapper.getElements()[i].float_value)));
|
||||
break;
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::DOUBLE:
|
||||
mValues.push_back(FieldValue(
|
||||
field, Value(statsLogEventWrapper.getElements()[i].double_value)));
|
||||
break;
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::STRING:
|
||||
mValues.push_back(
|
||||
FieldValue(field, Value(statsLogEventWrapper.getElements()[i].str_value)));
|
||||
break;
|
||||
case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::STORAGE:
|
||||
mValues.push_back(FieldValue(
|
||||
field, Value(statsLogEventWrapper.getElements()[i].storage_value)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogEvent::createLogEvents(const StatsLogEventWrapper& statsLogEventWrapper,
|
||||
std::vector<std::shared_ptr<LogEvent>>& logEvents) {
|
||||
if (statsLogEventWrapper.getWorkChains().size() == 0) {
|
||||
logEvents.push_back(std::make_shared<LogEvent>(statsLogEventWrapper, -1));
|
||||
} else {
|
||||
for (size_t i = 0; i < statsLogEventWrapper.getWorkChains().size(); i++) {
|
||||
logEvents.push_back(std::make_shared<LogEvent>(statsLogEventWrapper, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) {
|
||||
mLogdTimestampNs = wallClockTimestampNs;
|
||||
mElapsedTimestampNs = elapsedTimestampNs;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "FieldValue.h"
|
||||
|
||||
#include <android/frameworks/stats/1.0/types.h>
|
||||
#include <android/os/StatsLogEventWrapper.h>
|
||||
#include <android/util/ProtoOutputStream.h>
|
||||
#include <log/log_read.h>
|
||||
#include <private/android_logger.h>
|
||||
@@ -79,17 +78,6 @@ public:
|
||||
*/
|
||||
explicit LogEvent(uint8_t* msg, uint32_t len, uint32_t uid, bool useNewSchema);
|
||||
|
||||
/**
|
||||
* Creates LogEvent from StatsLogEventWrapper.
|
||||
*/
|
||||
static void createLogEvents(const StatsLogEventWrapper& statsLogEventWrapper,
|
||||
std::vector<std::shared_ptr<LogEvent>>& logEvents);
|
||||
|
||||
/**
|
||||
* Construct one LogEvent from a StatsLogEventWrapper with the i-th work chain. -1 if no chain.
|
||||
*/
|
||||
explicit LogEvent(const StatsLogEventWrapper& statsLogEventWrapper, int workChainIndex);
|
||||
|
||||
/**
|
||||
* Constructs a LogEvent with synthetic data for testing. Must call init() before reading.
|
||||
*/
|
||||
|
||||
@@ -665,168 +665,6 @@ TEST(LogEventTest, TestKeyValuePairsEvent) {
|
||||
EXPECT_EQ(1.1f, item16.mValue.float_value);
|
||||
}
|
||||
|
||||
TEST(LogEventTest, TestStatsLogEventWrapperNoChain) {
|
||||
Parcel parcel;
|
||||
// tag id
|
||||
parcel.writeInt32(1);
|
||||
// elapsed realtime
|
||||
parcel.writeInt64(1111L);
|
||||
// wallclock time
|
||||
parcel.writeInt64(2222L);
|
||||
// no chain
|
||||
parcel.writeInt32(0);
|
||||
// 2 data
|
||||
parcel.writeInt32(2);
|
||||
// int 6
|
||||
parcel.writeInt32(1);
|
||||
parcel.writeInt32(6);
|
||||
// long 10
|
||||
parcel.writeInt32(2);
|
||||
parcel.writeInt64(10);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
StatsLogEventWrapper statsLogEventWrapper;
|
||||
EXPECT_EQ(NO_ERROR, statsLogEventWrapper.readFromParcel(&parcel));
|
||||
EXPECT_EQ(1, statsLogEventWrapper.getTagId());
|
||||
EXPECT_EQ(1111L, statsLogEventWrapper.getElapsedRealTimeNs());
|
||||
EXPECT_EQ(2222L, statsLogEventWrapper.getWallClockTimeNs());
|
||||
EXPECT_EQ(0, statsLogEventWrapper.getWorkChains().size());
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getElements().size());
|
||||
EXPECT_EQ(6, statsLogEventWrapper.getElements()[0].int_value);
|
||||
EXPECT_EQ(10L, statsLogEventWrapper.getElements()[1].long_value);
|
||||
LogEvent event(statsLogEventWrapper, -1);
|
||||
EXPECT_EQ(1, event.GetTagId());
|
||||
EXPECT_EQ(1111L, event.GetElapsedTimestampNs());
|
||||
EXPECT_EQ(2222L, event.GetLogdTimestampNs());
|
||||
EXPECT_EQ(2, event.size());
|
||||
EXPECT_EQ(6, event.getValues()[0].mValue.int_value);
|
||||
EXPECT_EQ(10, event.getValues()[1].mValue.long_value);
|
||||
}
|
||||
|
||||
TEST(LogEventTest, TestStatsLogEventWrapperWithChain) {
|
||||
Parcel parcel;
|
||||
// tag id
|
||||
parcel.writeInt32(1);
|
||||
// elapsed realtime
|
||||
parcel.writeInt64(1111L);
|
||||
// wallclock time
|
||||
parcel.writeInt64(2222L);
|
||||
// 3 chains
|
||||
parcel.writeInt32(3);
|
||||
// chain1, 2 nodes (1, "tag1") (2, "tag2")
|
||||
parcel.writeInt32(2);
|
||||
parcel.writeInt32(1);
|
||||
parcel.writeString16(String16("tag1"));
|
||||
parcel.writeInt32(2);
|
||||
parcel.writeString16(String16("tag2"));
|
||||
// chain2, 1 node (3, "tag3")
|
||||
parcel.writeInt32(1);
|
||||
parcel.writeInt32(3);
|
||||
parcel.writeString16(String16("tag3"));
|
||||
// chain3, 2 nodes (4, "") (5, "")
|
||||
parcel.writeInt32(2);
|
||||
parcel.writeInt32(4);
|
||||
parcel.writeString16(String16(""));
|
||||
parcel.writeInt32(5);
|
||||
parcel.writeString16(String16(""));
|
||||
// 2 data
|
||||
parcel.writeInt32(2);
|
||||
// int 6
|
||||
parcel.writeInt32(1);
|
||||
parcel.writeInt32(6);
|
||||
// long 10
|
||||
parcel.writeInt32(2);
|
||||
parcel.writeInt64(10);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
StatsLogEventWrapper statsLogEventWrapper;
|
||||
EXPECT_EQ(NO_ERROR, statsLogEventWrapper.readFromParcel(&parcel));
|
||||
EXPECT_EQ(1, statsLogEventWrapper.getTagId());
|
||||
EXPECT_EQ(1111L, statsLogEventWrapper.getElapsedRealTimeNs());
|
||||
EXPECT_EQ(2222L, statsLogEventWrapper.getWallClockTimeNs());
|
||||
EXPECT_EQ(3, statsLogEventWrapper.getWorkChains().size());
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getWorkChains()[0].uids.size());
|
||||
EXPECT_EQ(1, statsLogEventWrapper.getWorkChains()[0].uids[0]);
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getWorkChains()[0].uids[1]);
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getWorkChains()[0].tags.size());
|
||||
EXPECT_EQ("tag1", statsLogEventWrapper.getWorkChains()[0].tags[0]);
|
||||
EXPECT_EQ("tag2", statsLogEventWrapper.getWorkChains()[0].tags[1]);
|
||||
EXPECT_EQ(1, statsLogEventWrapper.getWorkChains()[1].uids.size());
|
||||
EXPECT_EQ(3, statsLogEventWrapper.getWorkChains()[1].uids[0]);
|
||||
EXPECT_EQ(1, statsLogEventWrapper.getWorkChains()[1].tags.size());
|
||||
EXPECT_EQ("tag3", statsLogEventWrapper.getWorkChains()[1].tags[0]);
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getElements().size());
|
||||
EXPECT_EQ(6, statsLogEventWrapper.getElements()[0].int_value);
|
||||
EXPECT_EQ(10L, statsLogEventWrapper.getElements()[1].long_value);
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getWorkChains()[2].uids.size());
|
||||
EXPECT_EQ(4, statsLogEventWrapper.getWorkChains()[2].uids[0]);
|
||||
EXPECT_EQ(5, statsLogEventWrapper.getWorkChains()[2].uids[1]);
|
||||
EXPECT_EQ(2, statsLogEventWrapper.getWorkChains()[2].tags.size());
|
||||
EXPECT_EQ("", statsLogEventWrapper.getWorkChains()[2].tags[0]);
|
||||
EXPECT_EQ("", statsLogEventWrapper.getWorkChains()[2].tags[1]);
|
||||
|
||||
LogEvent event(statsLogEventWrapper, -1);
|
||||
EXPECT_EQ(1, event.GetTagId());
|
||||
EXPECT_EQ(1111L, event.GetElapsedTimestampNs());
|
||||
EXPECT_EQ(2222L, event.GetLogdTimestampNs());
|
||||
EXPECT_EQ(2, event.size());
|
||||
EXPECT_EQ(6, event.getValues()[0].mValue.int_value);
|
||||
EXPECT_EQ(10, event.getValues()[1].mValue.long_value);
|
||||
|
||||
LogEvent event1(statsLogEventWrapper, 0);
|
||||
|
||||
EXPECT_EQ(1, event1.GetTagId());
|
||||
EXPECT_EQ(1111L, event1.GetElapsedTimestampNs());
|
||||
EXPECT_EQ(2222L, event1.GetLogdTimestampNs());
|
||||
EXPECT_EQ(6, event1.size());
|
||||
EXPECT_EQ(1, event1.getValues()[0].mValue.int_value);
|
||||
EXPECT_EQ(0x2010101, event1.getValues()[0].mField.getField());
|
||||
EXPECT_EQ("tag1", event1.getValues()[1].mValue.str_value);
|
||||
EXPECT_EQ(0x2010182, event1.getValues()[1].mField.getField());
|
||||
EXPECT_EQ(2, event1.getValues()[2].mValue.int_value);
|
||||
EXPECT_EQ(0x2010201, event1.getValues()[2].mField.getField());
|
||||
EXPECT_EQ("tag2", event1.getValues()[3].mValue.str_value);
|
||||
EXPECT_EQ(0x2018282, event1.getValues()[3].mField.getField());
|
||||
EXPECT_EQ(6, event1.getValues()[4].mValue.int_value);
|
||||
EXPECT_EQ(0x20000, event1.getValues()[4].mField.getField());
|
||||
EXPECT_EQ(10, event1.getValues()[5].mValue.long_value);
|
||||
EXPECT_EQ(0x30000, event1.getValues()[5].mField.getField());
|
||||
|
||||
LogEvent event2(statsLogEventWrapper, 1);
|
||||
|
||||
EXPECT_EQ(1, event2.GetTagId());
|
||||
EXPECT_EQ(1111L, event2.GetElapsedTimestampNs());
|
||||
EXPECT_EQ(2222L, event2.GetLogdTimestampNs());
|
||||
EXPECT_EQ(4, event2.size());
|
||||
EXPECT_EQ(3, event2.getValues()[0].mValue.int_value);
|
||||
EXPECT_EQ(0x2010101, event2.getValues()[0].mField.getField());
|
||||
EXPECT_EQ("tag3", event2.getValues()[1].mValue.str_value);
|
||||
EXPECT_EQ(0x2018182, event2.getValues()[1].mField.getField());
|
||||
EXPECT_EQ(6, event2.getValues()[2].mValue.int_value);
|
||||
EXPECT_EQ(0x20000, event2.getValues()[2].mField.getField());
|
||||
EXPECT_EQ(10, event2.getValues()[3].mValue.long_value);
|
||||
EXPECT_EQ(0x30000, event2.getValues()[3].mField.getField());
|
||||
|
||||
LogEvent event3(statsLogEventWrapper, 2);
|
||||
|
||||
EXPECT_EQ(1, event3.GetTagId());
|
||||
EXPECT_EQ(1111L, event3.GetElapsedTimestampNs());
|
||||
EXPECT_EQ(2222L, event3.GetLogdTimestampNs());
|
||||
EXPECT_EQ(6, event3.size());
|
||||
EXPECT_EQ(4, event3.getValues()[0].mValue.int_value);
|
||||
EXPECT_EQ(0x2010101, event3.getValues()[0].mField.getField());
|
||||
EXPECT_EQ("", event3.getValues()[1].mValue.str_value);
|
||||
EXPECT_EQ(0x2010182, event3.getValues()[1].mField.getField());
|
||||
EXPECT_EQ(5, event3.getValues()[2].mValue.int_value);
|
||||
EXPECT_EQ(0x2010201, event3.getValues()[2].mField.getField());
|
||||
EXPECT_EQ("", event3.getValues()[3].mValue.str_value);
|
||||
EXPECT_EQ(0x2018282, event3.getValues()[3].mField.getField());
|
||||
EXPECT_EQ(6, event3.getValues()[4].mValue.int_value);
|
||||
EXPECT_EQ(0x20000, event3.getValues()[4].mField.getField());
|
||||
EXPECT_EQ(10, event3.getValues()[5].mValue.long_value);
|
||||
EXPECT_EQ(0x30000, event3.getValues()[5].mField.getField());
|
||||
}
|
||||
|
||||
TEST(LogEventTest, TestBinaryFieldAtom) {
|
||||
Atom launcherAtom;
|
||||
auto launcher_event = launcherAtom.mutable_launcher_event();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
/** @hide */
|
||||
parcelable StatsLogEventWrapper cpp_header "android/os/StatsLogEventWrapper.h";
|
||||
@@ -1,267 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package android.os;
|
||||
|
||||
import android.util.Slog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper class for sending data from Android OS to StatsD.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class StatsLogEventWrapper implements Parcelable {
|
||||
static final boolean DEBUG = false;
|
||||
static final String TAG = "StatsLogEventWrapper";
|
||||
|
||||
// Keep in sync with FieldValue.h enums
|
||||
private static final int EVENT_TYPE_UNKNOWN = 0;
|
||||
private static final int EVENT_TYPE_INT = 1; /* int32_t */
|
||||
private static final int EVENT_TYPE_LONG = 2; /* int64_t */
|
||||
private static final int EVENT_TYPE_FLOAT = 3;
|
||||
private static final int EVENT_TYPE_DOUBLE = 4;
|
||||
private static final int EVENT_TYPE_STRING = 5;
|
||||
private static final int EVENT_TYPE_STORAGE = 6;
|
||||
|
||||
List<Integer> mTypes = new ArrayList<>();
|
||||
List<Object> mValues = new ArrayList<>();
|
||||
int mTag;
|
||||
long mElapsedTimeNs;
|
||||
long mWallClockTimeNs;
|
||||
WorkSource mWorkSource = null;
|
||||
|
||||
public StatsLogEventWrapper(int tag, long elapsedTimeNs, long wallClockTimeNs) {
|
||||
this.mTag = tag;
|
||||
this.mElapsedTimeNs = elapsedTimeNs;
|
||||
this.mWallClockTimeNs = wallClockTimeNs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate for Parcel.
|
||||
*/
|
||||
public static final @android.annotation.NonNull Parcelable.Creator<StatsLogEventWrapper> CREATOR = new
|
||||
Parcelable.Creator<StatsLogEventWrapper>() {
|
||||
public StatsLogEventWrapper createFromParcel(Parcel in) {
|
||||
return new StatsLogEventWrapper(in);
|
||||
}
|
||||
|
||||
public StatsLogEventWrapper[] newArray(int size) {
|
||||
return new StatsLogEventWrapper[size];
|
||||
}
|
||||
};
|
||||
|
||||
private StatsLogEventWrapper(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set work source if any.
|
||||
*/
|
||||
public void setWorkSource(WorkSource ws) {
|
||||
if (ws.getWorkChains() == null || ws.getWorkChains().size() == 0) {
|
||||
Slog.w(TAG, "Empty worksource!");
|
||||
return;
|
||||
}
|
||||
mWorkSource = ws;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a int value.
|
||||
*/
|
||||
public void writeInt(int val) {
|
||||
mTypes.add(EVENT_TYPE_INT);
|
||||
mValues.add(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a long value.
|
||||
*/
|
||||
public void writeLong(long val) {
|
||||
mTypes.add(EVENT_TYPE_LONG);
|
||||
mValues.add(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string value.
|
||||
*/
|
||||
public void writeString(String val) {
|
||||
mTypes.add(EVENT_TYPE_STRING);
|
||||
// use empty string for null
|
||||
mValues.add(val == null ? "" : val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a float value.
|
||||
*/
|
||||
public void writeFloat(float val) {
|
||||
mTypes.add(EVENT_TYPE_FLOAT);
|
||||
mValues.add(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a storage value.
|
||||
*/
|
||||
public void writeStorage(byte[] val) {
|
||||
mTypes.add(EVENT_TYPE_STORAGE);
|
||||
mValues.add(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a boolean value.
|
||||
*/
|
||||
public void writeBoolean(boolean val) {
|
||||
mTypes.add(EVENT_TYPE_INT);
|
||||
mValues.add(val ? 1 : 0);
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG,
|
||||
"Writing " + mTag + " " + mElapsedTimeNs + " " + mWallClockTimeNs + " and "
|
||||
+ mTypes.size() + " elements.");
|
||||
}
|
||||
out.writeInt(mTag);
|
||||
out.writeLong(mElapsedTimeNs);
|
||||
out.writeLong(mWallClockTimeNs);
|
||||
if (mWorkSource != null) {
|
||||
List<WorkSource.WorkChain> workChains = mWorkSource.getWorkChains();
|
||||
// number of chains
|
||||
out.writeInt(workChains.size());
|
||||
for (int i = 0; i < workChains.size(); i++) {
|
||||
android.os.WorkSource.WorkChain wc = workChains.get(i);
|
||||
if (wc.getSize() == 0) {
|
||||
Slog.w(TAG, "Empty work chain.");
|
||||
out.writeInt(0);
|
||||
continue;
|
||||
}
|
||||
if (wc.getUids().length != wc.getTags().length
|
||||
|| wc.getUids().length != wc.getSize()) {
|
||||
Slog.w(TAG, "Malformated work chain.");
|
||||
out.writeInt(0);
|
||||
continue;
|
||||
}
|
||||
// number of nodes
|
||||
out.writeInt(wc.getSize());
|
||||
for (int j = 0; j < wc.getSize(); j++) {
|
||||
out.writeInt(wc.getUids()[j]);
|
||||
out.writeString(wc.getTags()[j] == null ? "" : wc.getTags()[j]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no chains
|
||||
out.writeInt(0);
|
||||
}
|
||||
out.writeInt(mTypes.size());
|
||||
for (int i = 0; i < mTypes.size(); i++) {
|
||||
out.writeInt(mTypes.get(i));
|
||||
switch (mTypes.get(i)) {
|
||||
case EVENT_TYPE_INT:
|
||||
out.writeInt((int) mValues.get(i));
|
||||
break;
|
||||
case EVENT_TYPE_LONG:
|
||||
out.writeLong((long) mValues.get(i));
|
||||
break;
|
||||
case EVENT_TYPE_FLOAT:
|
||||
out.writeFloat((float) mValues.get(i));
|
||||
break;
|
||||
case EVENT_TYPE_DOUBLE:
|
||||
out.writeDouble((double) mValues.get(i));
|
||||
break;
|
||||
case EVENT_TYPE_STRING:
|
||||
out.writeString((String) mValues.get(i));
|
||||
break;
|
||||
case EVENT_TYPE_STORAGE:
|
||||
out.writeByteArray((byte[]) mValues.get(i));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from parcel and appropriately fills member fields.
|
||||
*/
|
||||
public void readFromParcel(Parcel in) {
|
||||
mTypes = new ArrayList<>();
|
||||
mValues = new ArrayList<>();
|
||||
mWorkSource = null;
|
||||
|
||||
mTag = in.readInt();
|
||||
mElapsedTimeNs = in.readLong();
|
||||
mWallClockTimeNs = in.readLong();
|
||||
|
||||
// Clear any data.
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Reading " + mTag + " " + mElapsedTimeNs + " " + mWallClockTimeNs);
|
||||
}
|
||||
// Set up worksource if present.
|
||||
int numWorkChains = in.readInt();
|
||||
if (numWorkChains > 0) {
|
||||
mWorkSource = new WorkSource();
|
||||
for (int i = 0; i < numWorkChains; i++) {
|
||||
android.os.WorkSource.WorkChain workChain = mWorkSource.createWorkChain();
|
||||
int workChainSize = in.readInt();
|
||||
for (int j = 0; j < workChainSize; j++) {
|
||||
int uid = in.readInt();
|
||||
String tag = in.readString();
|
||||
workChain.addNode(uid, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do the rest of the types.
|
||||
int numTypes = in.readInt();
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Reading " + numTypes + " elements");
|
||||
}
|
||||
for (int i = 0; i < numTypes; i++) {
|
||||
int type = in.readInt();
|
||||
mTypes.add(type);
|
||||
switch (type) {
|
||||
case EVENT_TYPE_INT:
|
||||
mValues.add(in.readInt());
|
||||
break;
|
||||
case EVENT_TYPE_LONG:
|
||||
mValues.add(in.readLong());
|
||||
break;
|
||||
case EVENT_TYPE_FLOAT:
|
||||
mValues.add(in.readFloat());
|
||||
break;
|
||||
case EVENT_TYPE_DOUBLE:
|
||||
mValues.add(in.readDouble());
|
||||
break;
|
||||
case EVENT_TYPE_STRING:
|
||||
mValues.add(in.readString());
|
||||
break;
|
||||
case EVENT_TYPE_STORAGE:
|
||||
mValues.add(in.createByteArray());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate for Parcel.
|
||||
*/
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ cc_library_shared {
|
||||
"src/content/ComponentName.cpp",
|
||||
"src/os/DropBoxManager.cpp",
|
||||
"src/os/StatsDimensionsValue.cpp",
|
||||
"src/os/StatsLogEventWrapper.cpp",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef STATS_LOG_EVENT_WRAPPER_H
|
||||
#define STATS_LOG_EVENT_WRAPPER_H
|
||||
|
||||
#include <binder/Parcel.h>
|
||||
#include <binder/Parcelable.h>
|
||||
#include <binder/Status.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <vector>
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
|
||||
/**
|
||||
* A wrapper for a union type to contain multiple types of values.
|
||||
*
|
||||
*/
|
||||
struct StatsLogValue {
|
||||
// Keep in sync with FieldValue.h
|
||||
enum STATS_LOG_VALUE_TYPE {
|
||||
UNKNOWN = 0,
|
||||
INT = 1,
|
||||
LONG = 2,
|
||||
FLOAT = 3,
|
||||
DOUBLE = 4,
|
||||
STRING = 5,
|
||||
STORAGE = 6
|
||||
};
|
||||
|
||||
StatsLogValue() : type(UNKNOWN) {}
|
||||
|
||||
StatsLogValue(int32_t v) {
|
||||
int_value = v;
|
||||
type = INT;
|
||||
}
|
||||
|
||||
StatsLogValue(int64_t v) {
|
||||
long_value = v;
|
||||
type = LONG;
|
||||
}
|
||||
|
||||
StatsLogValue(float v) {
|
||||
float_value = v;
|
||||
type = FLOAT;
|
||||
}
|
||||
|
||||
StatsLogValue(double v) {
|
||||
double_value = v;
|
||||
type = DOUBLE;
|
||||
}
|
||||
|
||||
StatsLogValue(const std::string& v) {
|
||||
str_value = v;
|
||||
type = STRING;
|
||||
}
|
||||
|
||||
void setType(STATS_LOG_VALUE_TYPE t) { type = t; }
|
||||
|
||||
union {
|
||||
int32_t int_value;
|
||||
int64_t long_value;
|
||||
float float_value;
|
||||
double double_value;
|
||||
};
|
||||
std::string str_value;
|
||||
std::vector<uint8_t> storage_value;
|
||||
|
||||
STATS_LOG_VALUE_TYPE type;
|
||||
};
|
||||
|
||||
struct WorkChain {
|
||||
std::vector<int32_t> uids;
|
||||
std::vector<std::string> tags;
|
||||
};
|
||||
|
||||
// Represents a parcelable object. Only used to send data from Android OS to statsd.
|
||||
class StatsLogEventWrapper : public android::Parcelable {
|
||||
public:
|
||||
StatsLogEventWrapper();
|
||||
|
||||
StatsLogEventWrapper(StatsLogEventWrapper&& in) = default;
|
||||
|
||||
android::status_t writeToParcel(android::Parcel* out) const;
|
||||
|
||||
android::status_t readFromParcel(const android::Parcel* in);
|
||||
|
||||
int getTagId() const { return mTagId; }
|
||||
|
||||
int64_t getElapsedRealTimeNs() const { return mElapsedRealTimeNs; }
|
||||
|
||||
int64_t getWallClockTimeNs() const { return mWallClockTimeNs; }
|
||||
|
||||
const std::vector<StatsLogValue>& getElements() const { return mElements; }
|
||||
|
||||
const std::vector<WorkChain>& getWorkChains() const { return mWorkChains; }
|
||||
|
||||
private:
|
||||
int mTagId;
|
||||
|
||||
int64_t mElapsedRealTimeNs;
|
||||
|
||||
int64_t mWallClockTimeNs;
|
||||
|
||||
std::vector<StatsLogValue> mElements;
|
||||
|
||||
std::vector<WorkChain> mWorkChains;
|
||||
};
|
||||
} // Namespace os
|
||||
} // Namespace android
|
||||
|
||||
|
||||
#endif // STATS_LOG_EVENT_WRAPPER_H
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <android/os/StatsLogEventWrapper.h>
|
||||
|
||||
#include <binder/Parcel.h>
|
||||
#include <binder/Parcelable.h>
|
||||
#include <binder/Status.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <vector>
|
||||
|
||||
using android::Parcel;
|
||||
using android::Parcelable;
|
||||
using android::status_t;
|
||||
using std::vector;
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
|
||||
StatsLogEventWrapper::StatsLogEventWrapper(){};
|
||||
|
||||
status_t StatsLogEventWrapper::writeToParcel(Parcel* out) const {
|
||||
// Implement me if desired. We don't currently use this.
|
||||
ALOGE(
|
||||
"Cannot do c++ StatsLogEventWrapper.writeToParcel(); it is not "
|
||||
"implemented.");
|
||||
(void)out; // To prevent compile error of unused parameter 'in'
|
||||
return UNKNOWN_ERROR;
|
||||
};
|
||||
|
||||
status_t StatsLogEventWrapper::readFromParcel(const Parcel* in) {
|
||||
status_t res = OK;
|
||||
if (in == NULL) {
|
||||
ALOGE("statsd received parcel argument was NULL.");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
if ((res = in->readInt32(&mTagId)) != OK) {
|
||||
ALOGE("statsd could not read tagId from parcel");
|
||||
return res;
|
||||
}
|
||||
if ((res = in->readInt64(&mElapsedRealTimeNs)) != OK) {
|
||||
ALOGE("statsd could not read elapsed real time from parcel");
|
||||
return res;
|
||||
}
|
||||
if ((res = in->readInt64(&mWallClockTimeNs)) != OK) {
|
||||
ALOGE("statsd could not read wall clock time from parcel");
|
||||
return res;
|
||||
}
|
||||
int numWorkChain = 0;
|
||||
if ((res = in->readInt32(&numWorkChain)) != OK) {
|
||||
ALOGE("statsd could not read number of work chains from parcel");
|
||||
return res;
|
||||
}
|
||||
if (numWorkChain > 0) {
|
||||
for (int i = 0; i < numWorkChain; i++) {
|
||||
int numNodes = 0;
|
||||
if ((res = in->readInt32(&numNodes)) != OK) {
|
||||
ALOGE(
|
||||
"statsd could not read number of nodes in work chain from parcel");
|
||||
return res;
|
||||
}
|
||||
if (numNodes == 0) {
|
||||
ALOGE("empty work chain");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
WorkChain wc;
|
||||
for (int j = 0; j < numNodes; j++) {
|
||||
wc.uids.push_back(in->readInt32());
|
||||
wc.tags.push_back(std::string(String8(in->readString16()).string()));
|
||||
}
|
||||
mWorkChains.push_back(wc);
|
||||
}
|
||||
}
|
||||
int dataSize = 0;
|
||||
if ((res = in->readInt32(&dataSize)) != OK) {
|
||||
ALOGE("statsd could not read data size from parcel");
|
||||
return res;
|
||||
}
|
||||
if (mTagId <= 0 || mElapsedRealTimeNs <= 0 || mWallClockTimeNs <= 0 ||
|
||||
dataSize <= 0) {
|
||||
ALOGE("statsd received invalid parcel");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < dataSize; i++) {
|
||||
int type = in->readInt32();
|
||||
switch (type) {
|
||||
case StatsLogValue::INT:
|
||||
mElements.push_back(StatsLogValue(in->readInt32()));
|
||||
break;
|
||||
case StatsLogValue::LONG:
|
||||
mElements.push_back(StatsLogValue(in->readInt64()));
|
||||
break;
|
||||
case StatsLogValue::STRING:
|
||||
mElements.push_back(
|
||||
StatsLogValue(std::string(String8(in->readString16()).string())));
|
||||
break;
|
||||
case StatsLogValue::FLOAT:
|
||||
mElements.push_back(StatsLogValue(in->readFloat()));
|
||||
break;
|
||||
case StatsLogValue::STORAGE:
|
||||
mElements.push_back(StatsLogValue());
|
||||
mElements.back().setType(StatsLogValue::STORAGE);
|
||||
in->readByteVector(&(mElements.back().storage_value));
|
||||
break;
|
||||
default:
|
||||
ALOGE("unrecognized data type: %d", type);
|
||||
return BAD_TYPE;
|
||||
}
|
||||
}
|
||||
return NO_ERROR;
|
||||
};
|
||||
|
||||
} // Namespace os
|
||||
} // Namespace android
|
||||
Reference in New Issue
Block a user