Merge "Add clear method to ProtoOutputStream so it is reusable by just rewinding its internal pointer."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a27ae0fdd1
@@ -142,7 +142,7 @@ void
|
||||
PrivacyBuffer::clear()
|
||||
{
|
||||
mSize = 0;
|
||||
mProto = ProtoOutputStream();
|
||||
mProto.clear();
|
||||
}
|
||||
|
||||
size_t
|
||||
|
||||
26
cmds/statsd/AndroidTest.xml
Normal file
26
cmds/statsd/AndroidTest.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<configuration description="Config for statsd_test">
|
||||
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
|
||||
<option name="cleanup" value="true" />
|
||||
<option name="push" value="statsd_test->/data/nativetest/statsd_test" />
|
||||
</target_preparer>
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
<test class="com.android.tradefed.testtype.GTest" >
|
||||
<option name="native-test-device-path" value="/data/nativetest" />
|
||||
<option name="module-name" value="statsd_test" />
|
||||
</test>
|
||||
</configuration>
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "AnomalyTracker.h"
|
||||
#include "external/Perfetto.h"
|
||||
#include "frameworks/base/libs/incident/proto/android/os/header.pb.h"
|
||||
#include "guardrail/StatsdStats.h"
|
||||
#include "subscriber/IncidentdReporter.h"
|
||||
#include "subscriber/SubscriberReporter.h"
|
||||
|
||||
@@ -59,9 +59,7 @@ EventMetricProducer::EventMetricProducer(const ConfigKey& key, const EventMetric
|
||||
metric.links().end());
|
||||
mConditionSliced = true;
|
||||
}
|
||||
|
||||
startNewProtoOutputStreamLocked();
|
||||
|
||||
mProto = std::make_unique<ProtoOutputStream>();
|
||||
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
@@ -70,10 +68,6 @@ EventMetricProducer::~EventMetricProducer() {
|
||||
VLOG("~EventMetricProducer() called");
|
||||
}
|
||||
|
||||
void EventMetricProducer::startNewProtoOutputStreamLocked() {
|
||||
mProto = std::make_unique<ProtoOutputStream>();
|
||||
}
|
||||
|
||||
void EventMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
|
||||
}
|
||||
|
||||
@@ -113,7 +107,7 @@ void EventMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
protoOutput->write(FIELD_TYPE_MESSAGE | FIELD_ID_EVENT_METRICS,
|
||||
reinterpret_cast<char*>(buffer.get()->data()), buffer.get()->size());
|
||||
|
||||
startNewProtoOutputStreamLocked();
|
||||
mProto->clear();
|
||||
}
|
||||
|
||||
void EventMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
|
||||
@@ -40,9 +40,6 @@ public:
|
||||
|
||||
virtual ~EventMetricProducer();
|
||||
|
||||
protected:
|
||||
void startNewProtoOutputStreamLocked();
|
||||
|
||||
private:
|
||||
void onMatchedLogEventInternalLocked(
|
||||
const size_t matcherIndex, const MetricDimensionKey& eventKey,
|
||||
|
||||
@@ -64,6 +64,11 @@ public:
|
||||
size_t mOffset;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the buffer by rewinding its write pointer to avoid de/allocate buffers in heap.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/******************************** Write APIs ************************************************/
|
||||
|
||||
/**
|
||||
|
||||
@@ -123,6 +123,11 @@ public:
|
||||
EncodedBuffer::iterator data(); // Get the reader apis of the data.
|
||||
bool flush(int fd); // Flush data directly to a file descriptor.
|
||||
|
||||
/**
|
||||
* Clears the ProtoOutputStream so the buffer can be reused instead of deallocation/allocation again.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
// Please don't use the following functions to dump protos unless you are familiar with protobuf encoding.
|
||||
void writeRawVarint(uint64_t varint);
|
||||
void writeLengthDelimitedHeader(uint32_t id, size_t size);
|
||||
|
||||
@@ -106,6 +106,13 @@ EncodedBuffer::at(const Pointer& p) const
|
||||
return mBuffers[p.index()] + p.offset();
|
||||
}
|
||||
|
||||
void
|
||||
EncodedBuffer::clear()
|
||||
{
|
||||
mWp.rewind();
|
||||
mEp.rewind();
|
||||
}
|
||||
|
||||
/******************************** Write APIs ************************************************/
|
||||
size_t
|
||||
EncodedBuffer::size() const
|
||||
|
||||
@@ -36,6 +36,18 @@ ProtoOutputStream::~ProtoOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProtoOutputStream::clear()
|
||||
{
|
||||
mBuffer.clear();
|
||||
mCopyBegin = 0;
|
||||
mCompact = false;
|
||||
mDepth = 0;
|
||||
mObjectId = 0;
|
||||
mExpectedObjectToken = 0LL;
|
||||
}
|
||||
|
||||
bool
|
||||
ProtoOutputStream::write(uint64_t fieldId, double val)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user