Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35ef4f20 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add EventMetricProducer"

parents 8b714a1b 5110bedd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ statsd_common_src := \
    src/matchers/SimpleLogMatchingTracker.cpp \
    src/metrics/CountAnomalyTracker.cpp \
    src/metrics/MetricProducer.cpp \
    src/metrics/EventMetricProducer.cpp \
    src/metrics/CountMetricProducer.cpp \
    src/metrics/DurationMetricProducer.cpp \
    src/metrics/MetricsManager.cpp \
@@ -65,7 +66,8 @@ statsd_common_shared_libraries := \
    libselinux \
    libutils \
    libservices \
    libandroidfw
    libandroidfw \
    libprotoutil

# =========
# statsd
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

#define DEBUG true  // STOPSHIP if true
#define DEBUG false  // STOPSHIP if true
#include "Log.h"

#include "SimpleConditionTracker.h"
+7 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ static StatsdConfig build_fake_config() {

    int WAKE_LOCK_TAG_ID = 11;
    int WAKE_LOCK_UID_KEY_ID = 1;
    int WAKE_LOCK_STATE_KEY = 2;
    int WAKE_LOCK_STATE_KEY = 3;
    int WAKE_LOCK_ACQUIRE_VALUE = 1;
    int WAKE_LOCK_RELEASE_VALUE = 0;

@@ -167,7 +167,7 @@ static StatsdConfig build_fake_config() {
    keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY);
    metric->set_condition("SCREEN_IS_OFF");

    // Count wake lock, slice by uid, while SCREEN_IS_OFF and app in background
    // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background
    metric = config.add_count_metric();
    metric->set_metric_id(4);
    metric->set_what("APP_GET_WL");
@@ -195,6 +195,11 @@ static StatsdConfig build_fake_config() {
    link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
    link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);

    // Add an EventMetric to log process state change events.
    EventMetric* eventMetric = config.add_event_metric();
    eventMetric->set_metric_id(6);
    eventMetric->set_what("SCREEN_TURNED_ON");

    // Event matchers............
    LogEntryMatcher* eventMatcher = config.add_log_entry_matcher();
    eventMatcher->set_name("SCREEN_TURNED_ON");
+9 −13
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "logd/LogEvent.h"

#include <sstream>
#include "stats_util.h"

namespace android {
namespace os {
@@ -24,6 +25,7 @@ namespace statsd {

using std::ostringstream;
using std::string;
using android::util::ProtoOutputStream;

// We need to keep a copy of the android_log_event_list owned by this instance so that the char*
// for strings is not cleared before we can read them.
@@ -203,30 +205,24 @@ string LogEvent::ToString() const {
    return result.str();
}

void LogEvent::ToProto(EventMetricData* out) const {
    // TODO: Implement this when we have the ProtoOutputStream version.

    // set timestamp of the event.
    out->set_timestamp_nanos(mTimestampNs);

    // uint64_t token = proto->StartObject(EventMetricData.FIELD);
void LogEvent::ToProto(ProtoOutputStream& proto) const {
    long long atomToken = proto.start(TYPE_MESSAGE + mTagId);
    const size_t N = mElements.size();
    for (size_t i=0; i<N; i++) {
        const int key = i + 1;

        const android_log_list_element& elem = mElements[i];
        if (elem.type == EVENT_TYPE_INT) {
            // proto->Write(key, elem.data.int32);
            proto.write(TYPE_INT32 + key, elem.data.int32);
        } else if (elem.type == EVENT_TYPE_LONG) {
            // proto->Write(key, elem.data.int64);
            proto.write(TYPE_INT64 + key, (long long)elem.data.int64);
        } else if (elem.type == EVENT_TYPE_FLOAT) {
            // proto->Write(key, elem.data.float32);
            proto.write(TYPE_FLOAT + key, elem.data.float32);
        } else if (elem.type == EVENT_TYPE_STRING) {
            // proto->Write(key, elem.data.string);
            proto.write(TYPE_STRING + key, elem.data.string);
        }
    }

    //proto->EndObject(token);
    proto.end(atomToken);
}

}  // namespace statsd
+4 −4
Original line number Diff line number Diff line
@@ -18,9 +18,10 @@

#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"

#include <utils/Errors.h>
#include <android/util/ProtoOutputStream.h>
#include <log/log_event_list.h>
#include <log/log_read.h>
#include <utils/Errors.h>

#include <memory>
#include <string>
@@ -80,10 +81,9 @@ public:
    string ToString() const;

    /**
     * Write this object as an EventMetricData proto object.
     * TODO: Use the streaming output generator to do this instead of this proto lite object?
     * Write this object to a ProtoOutputStream.
     */
    void ToProto(EventMetricData* out) const;
    void ToProto(android::util::ProtoOutputStream& out) const;

    /*
     * Get a KeyValuePair proto object.
Loading