Remove stream.proto and cpp-streaming-proto generates field name to id

mapping by default

Test: atest incident_helper_test
Change-Id: Iab04973ea78b942e44503fcd6ae60808caf3b9e0
This commit is contained in:
Yi Jin
2017-12-18 15:55:19 -08:00
parent 39b4499d94
commit f68e747e05
10 changed files with 7 additions and 118 deletions

View File

@@ -693,7 +693,6 @@ cc_library {
srcs: [
"core/proto/**/*.proto",
"libs/incident/**/*.proto",
"tools/streaming_proto/stream.proto",
],
target: {

View File

@@ -999,7 +999,6 @@ LOCAL_PROTOC_FLAGS := \
-Iexternal/protobuf/src
LOCAL_SOURCE_FILES_ALL_GENERATED := true
LOCAL_SRC_FILES := \
tools/streaming_proto/stream.proto \
cmds/am/proto/instrumentation_data.proto \
$(call all-proto-files-under, core/proto) \
$(call all-proto-files-under, libs/incident/proto) \

View File

@@ -18,8 +18,6 @@ syntax = "proto2";
option java_multiple_files = true;
option java_outer_classname = "CpuInfoProto";
import "frameworks/base/tools/streaming_proto/stream.proto";
package android.os;
/**
@@ -31,8 +29,6 @@ package android.os;
message CpuInfo {
message TaskStats {
option (stream_proto.stream_msg).enable_fields_mapping = true;
optional int32 total = 1; // total number of cpu tasks
optional int32 running = 2; // number of running tasks
optional int32 sleeping = 3; // number of sleeping tasks
@@ -42,8 +38,6 @@ message CpuInfo {
optional TaskStats task_stats = 1;
message MemStats { // unit in kB
option (stream_proto.stream_msg).enable_fields_mapping = true;
optional int32 total = 1;
optional int32 used = 2;
optional int32 free = 3;
@@ -54,8 +48,6 @@ message CpuInfo {
optional MemStats swap = 3;
message CpuUsage { // unit is percentage %
option (stream_proto.stream_msg).enable_fields_mapping = true;
optional int32 cpu = 1; // 400% cpu indicates 4 cores
optional int32 user = 2;
optional int32 nice = 3;
@@ -70,8 +62,6 @@ message CpuInfo {
// Next Tag: 13
message Task {
option (stream_proto.stream_msg).enable_fields_mapping = true;
optional int32 pid = 1;
optional int32 tid = 2;
optional string user = 3;
@@ -80,8 +70,6 @@ message CpuInfo {
optional float cpu = 6; // precentage of cpu usage of the task
enum Status {
option (stream_proto.stream_enum).enable_enums_mapping = true;
STATUS_UNKNOWN = 0;
STATUS_D = 1; // uninterruptible sleep
STATUS_R = 2; // running
@@ -95,8 +83,6 @@ message CpuInfo {
// How Android memory manager will treat the task
enum Policy {
option (stream_proto.stream_enum).enable_enums_mapping = true;
POLICY_UNKNOWN = 0;
POLICY_fg = 1; // foreground, the name is lower case for parsing the value
POLICY_bg = 2; // background, the name is lower case for parsing the value

View File

@@ -18,8 +18,6 @@ syntax = "proto2";
option java_multiple_files = true;
option java_outer_classname = "WakeupSourcesProto";
import "frameworks/base/tools/streaming_proto/stream.proto";
package android.os;
message KernelWakeSources {
@@ -29,8 +27,6 @@ message KernelWakeSources {
// Next Tag: 11
message WakeupSourceProto {
option (stream_proto.stream_msg).enable_fields_mapping = true;
// Name of the event which triggers application processor
optional string name = 1;

View File

@@ -18,8 +18,6 @@ syntax = "proto2";
option java_multiple_files = true;
option java_outer_classname = "PageTypeInfoProto";
import "frameworks/base/tools/streaming_proto/stream.proto";
package android.os;
/*
@@ -63,7 +61,6 @@ message MigrateTypeProto {
// Next tag: 9
message BlockProto {
option (stream_proto.stream_msg).enable_fields_mapping = true;
optional int32 node = 1;

View File

@@ -19,7 +19,6 @@ option java_multiple_files = true;
option java_outer_classname = "ProcrankProto";
import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/tools/streaming_proto/stream.proto";
package android.os;
@@ -36,7 +35,6 @@ message Procrank {
// Next Tag: 11
message ProcessProto {
option (stream_proto.stream_msg).enable_fields_mapping = true;
option (android.msg_privacy).dest = DEST_AUTOMATIC;
// ID of the process

View File

@@ -19,14 +19,12 @@ syntax = "proto2";
option java_multiple_files = true;
import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/tools/streaming_proto/stream.proto";
package android.os;
// Android Platform Exported System Properties
// TODO: This is not the completed list, new properties need to be whitelisted.
message SystemPropertiesProto {
option (stream_proto.stream_msg).enable_fields_mapping_recursively = true;
// Properties that are not specified below would be appended here.
// These values stay on device only.

View File

@@ -32,26 +32,6 @@ cc_defaults {
shared_libs: ["libprotoc"],
}
cc_library {
name: "streamingflags",
host_supported: true,
proto: {
export_proto_headers: true,
include_dirs: ["external/protobuf/src"],
},
target: {
host: {
proto: {
type: "full",
},
srcs: [
"stream.proto",
],
},
},
}
cc_binary_host {
name: "protoc-gen-javastream",
srcs: [
@@ -68,5 +48,4 @@ cc_binary_host {
],
defaults: ["protoc-gen-stream-defaults"],
static_libs: ["streamingflags"],
}

View File

@@ -2,8 +2,6 @@
#include "stream_proto_utils.h"
#include "string_utils.h"
#include <frameworks/base/tools/streaming_proto/stream.pb.h>
#include <iomanip>
#include <iostream>
#include <sstream>
@@ -12,18 +10,14 @@ using namespace android::stream_proto;
using namespace google::protobuf::io;
using namespace std;
const bool GENERATE_MAPPING = true;
static string
make_filename(const FileDescriptorProto& file_descriptor)
{
return file_descriptor.name() + ".h";
}
static inline bool
should_generate_enums_mapping(const EnumDescriptorProto& enu)
{
return enu.options().GetExtension(stream_enum).enable_enums_mapping();
}
static void
write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& indent)
{
@@ -36,7 +30,7 @@ write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& ind
<< " = " << value.number() << ";" << endl;
}
if (should_generate_enums_mapping(enu)) {
if (GENERATE_MAPPING) {
string name = make_constant_name(enu.name());
string prefix = name + "_";
text << indent << "const int _ENUM_" << name << "_COUNT = " << N << ";" << endl;
@@ -79,23 +73,11 @@ write_field(stringstream& text, const FieldDescriptorProto& field, const string&
text << endl;
}
static inline bool
should_generate_fields_mapping(const DescriptorProto& message)
{
return message.options().GetExtension(stream_msg).enable_fields_mapping();
}
static inline bool
should_generate_fields_mapping_recursively(const DescriptorProto& message) {
return message.options().GetExtension(stream_msg).enable_fields_mapping_recursively();
}
static void
write_message(stringstream& text, const DescriptorProto& message, const string& indent, bool genMapping)
write_message(stringstream& text, const DescriptorProto& message, const string& indent)
{
int N;
const string indented = indent + INDENT;
genMapping |= should_generate_fields_mapping_recursively(message);
text << indent << "// message " << message.name() << endl;
text << indent << "namespace " << message.name() << " {" << endl;
@@ -109,7 +91,7 @@ write_message(stringstream& text, const DescriptorProto& message, const string&
// Nested classes
N = message.nested_type_size();
for (int i=0; i<N; i++) {
write_message(text, message.nested_type(i), indented, genMapping);
write_message(text, message.nested_type(i), indented);
}
// Fields
@@ -118,7 +100,7 @@ write_message(stringstream& text, const DescriptorProto& message, const string&
write_field(text, message.field(i), indented);
}
if (genMapping | should_generate_fields_mapping(message)) {
if (GENERATE_MAPPING) {
N = message.field_size();
text << indented << "const int _FIELD_COUNT = " << N << ";" << endl;
text << indented << "const char* _FIELD_NAMES[" << N << "] = {" << endl;
@@ -167,7 +149,7 @@ write_header_file(CodeGeneratorResponse* response, const FileDescriptorProto& fi
N = file_descriptor.message_type_size();
for (size_t i=0; i<N; i++) {
write_message(text, file_descriptor.message_type(i), "", false);
write_message(text, file_descriptor.message_type(i), "");
}
for (vector<string>::iterator it = namespaces.begin(); it != namespaces.end(); it++) {

View File

@@ -1,45 +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.
*/
syntax = "proto2";
import "google/protobuf/descriptor.proto";
package android.stream_proto;
// This option tells streaming proto plugin to compile .proto files with extra features.
message MessageOptions {
// creates a mapping of field names of the message to its field ids
optional bool enable_fields_mapping = 1;
// creates mapping between field names to its field ids and recursively for its submessages.
optional bool enable_fields_mapping_recursively = 2;
}
extend google.protobuf.MessageOptions {
// Flags used by streaming proto plugins
optional MessageOptions stream_msg = 126856794;
}
message EnumOptions {
// creates a mapping of enum names to its values, strip its prefix enum type for each value
optional bool enable_enums_mapping = 1;
}
extend google.protobuf.EnumOptions {
// Flags used by streaming proto plugins
optional EnumOptions stream_enum = 126856794;
}