1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "uploadthread.h" 20 #include "prong.h" 21 #include "histogram.h" 22 23 #include "pb_encode.h" 24 25 #include "nano/tuningfork.pb.h" 26 #include "nano/tuningfork_clearcut_log.pb.h" 27 28 namespace tuningfork { 29 30 typedef logs_proto_tuningfork_TuningForkLogEvent TuningForkLogEvent; 31 typedef logs_proto_tuningfork_TuningForkHistogram ClearcutHistogram; 32 typedef logs_proto_tuningfork_DeviceInfo DeviceInfo; 33 34 class ClearcutSerializer { 35 public: 36 static void SerializeEvent(const ProngCache& t, 37 const ProtobufSerialization& fidelity_params, 38 const ExtraUploadInfo& device_info, 39 ProtobufSerialization& evt_ser); 40 // Fill in the event histograms 41 static void FillHistograms(const ProngCache& pc, TuningForkLogEvent &evt); 42 // Fill in the annotation, etc, then the histogram 43 static void Fill(const Prong& p, ClearcutHistogram& h); 44 // Fill in the histogram data 45 static void Fill(const Histogram& h, ClearcutHistogram& ch); 46 // Fill in the device info 47 static void Fill(const ExtraUploadInfo& p, DeviceInfo& di); 48 // Fill in the other experiment, session and apk info 49 static void FillExtras(const ExtraUploadInfo& p, TuningForkLogEvent& evt); 50 51 // Callbacks needed by nanopb 52 static bool writeCountArray(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); 53 static bool writeAnnotation(pb_ostream_t* stream, const pb_field_t *field, void *const *arg); 54 static bool writeHistograms(pb_ostream_t* stream, const pb_field_t *field, void *const *arg); 55 static bool writeFidelityParams(pb_ostream_t* stream, const pb_field_t *field, void *const *arg); 56 static bool writeString(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); 57 static bool writeDeviceInfo(pb_ostream_t* stream, const pb_field_t *field, void *const *arg); 58 static bool writeCpuFreqs(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); 59 60 }; 61 62 } //namespace tuningfork 63