--- /dev/null
+/*
+ * SWAP Trace Parser
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Alexander Aksenov <a.aksenov@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - Samsung RnD Institute Russia
+ *
+ */
+
+
+
+#include <boost/algorithm/string.hpp>
+#include <data_writer.h>
+#include "writer_csv.h"
+
+
+static bool first_element = true;
+
+static void prepare_output(std::ostream &ios)
+{
+ if (!first_element)
+ ios << ",";
+ else
+ first_element = false;
+}
+
+static inline void start_output()
+{
+ first_element = true;
+}
+
+static inline void finish_output()
+{
+ first_element = false;
+}
+
+
+
+template<typename T>
+static void data_out(const std::string &name, const T val, std::ostream &ios)
+{
+ prepare_output(ios);
+
+ ios << val;
+}
+
+template<typename T>
+static void data_hex_out(const std::string &name, const T val,
+ std::ostream &ios)
+{
+ prepare_output(ios);
+
+ ios << "0x" << std::hex << val << std::dec;
+}
+
+template<typename T>
+static void args_out(const std::string &mod, const T val, std::ostream &ios)
+{
+ prepare_output(ios);
+
+ ios << "\"" << mod << "\"," << val;
+}
+
+template<typename T>
+static void args_vector_out(const std::string &mod, const std::vector<T> &val,
+ const uint64_t p, std::ostream &ios)
+{
+ prepare_output(ios);
+
+ ios << "\"" << mod << "\"," << val.size() << ",0x" << std::hex << p
+ << std::dec;
+
+ for (auto const &item : val)
+ ios << "," << item;
+}
+
+
+
+
+
+void DataWriterCSV::start_msg()
+{
+ start_output();
+}
+
+void DataWriterCSV::finish_msg()
+{
+ ios_ << std::endl;
+}
+
+void DataWriterCSV::output_val(const std::string &name, const uint8_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const uint32_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const uint64_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const float val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const double val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const std::string &val)
+{
+ prepare_output(ios_);
+
+ ios_ << "\"";
+
+ if ((val.find("\n") == std::string::npos) && (val.find("\r") == std::string::npos)) {
+ ios_ << val;
+ } else {
+ std::string new_val(val);
+
+ boost::replace_all(new_val, "\n", "\\n");
+ boost::replace_all(new_val, "\r", "\\r");
+ ios_ << new_val;
+ }
+
+ ios_ << "\"";
+}
+
+void DataWriterCSV::output_val(const std::string &name, const char val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_val(const std::string &name, const int val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_hex(const std::string &name, const uint32_t val)
+{
+ data_hex_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_hex(const std::string &name, const uint64_t val)
+{
+ data_hex_out(name, val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const bool val)
+{
+ args_out("b", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const uint8_t val)
+{
+ args_out("c", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const uint32_t val)
+{
+ args_out("d", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const uint64_t val)
+{
+ args_out("x", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const float val)
+{
+ args_out("f", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const double val)
+{
+ args_out("w", val, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name, const std::string &val)
+{
+ prepare_output(ios_);
+
+ ios_ << "\"s\", \"";
+
+ if ((val.find("\n") == std::string::npos) && (val.find("\r") == std::string::npos)) {
+ ios_ << val;
+ } else {
+ std::string new_val(val);
+
+ boost::replace_all(new_val, "\n", "\\n");
+ boost::replace_all(new_val, "\r", "\\r");
+ ios_ << new_val;
+ }
+
+ ios_ << "\"";
+}
+
+void DataWriterCSV::output_args(const std::string &name,
+ const std::vector<float> &val, uint64_t p)
+{
+ args_vector_out("F", val, p, ios_);
+}
+
+void DataWriterCSV::output_args(const std::string &name,
+ const std::vector<uint32_t> &val, uint64_t p)
+{
+ args_vector_out("D", val, p, ios_);
+}
+
+void DataWriterCSV::output_time(const std::string &name, const uint64_t val)
+{
+ prepare_output(ios_);
+
+ ios_ << val;
+}
+
+void DataWriterCSV::output_args_hex(const std::string &name, const uint64_t val)
+{
+ prepare_output(ios_);
+
+ ios_ << "0x" << std::hex << val << std::dec;
+}
+
+void DataWriterCSV::output_buf(const std::vector<char> &buf)
+{
+ // TODO No place with implemnetation
+}
--- /dev/null
+/*
+ * SWAP Trace Parser
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Alexander Aksenov <a.aksenov@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - Samsung RnD Institute Russia
+ *
+ */
+
+
+
+#ifndef __WRITER_CSV_H__
+#define __WRITER_CSV_H__
+
+
+#include <data_writer.h>
+
+
+class DataWriterCSV: public DataWriter
+{
+public:
+ using DataWriter::DataWriter;
+
+ void start_file(const uint32_t version) {}
+ void finish_file() {}
+
+ void start_msg();
+ void finish_msg();
+
+ void output_val(const std::string &name, const uint8_t val);
+ void output_val(const std::string &name, const uint32_t val);
+ void output_val(const std::string &name, const uint64_t val);
+ void output_val(const std::string &name, const float val);
+ void output_val(const std::string &name, const double val);
+ void output_val(const std::string &name, const std::string &val);
+ void output_val(const std::string &name, const char val);
+ void output_val(const std::string &name, const int val);
+
+ void output_hex(const std::string &name, const uint32_t val);
+ void output_hex(const std::string &name, const uint64_t val);
+
+ void output_args(const std::string &name, const bool val);
+ void output_args(const std::string &name, const uint8_t val);
+ void output_args(const std::string &name, const uint32_t val);
+ void output_args(const std::string &name, const uint64_t val);
+ void output_args(const std::string &name, const float val);
+ void output_args(const std::string &name, const double val);
+ void output_args(const std::string &name, const std::string &val);
+ void output_args(const std::string &name) {}
+ void output_args(const std::string &name, const std::vector<float> &val, uint64_t p);
+ void output_args(const std::string &name, const std::vector<uint32_t> &val, uint64_t p);
+ void output_args_hex(const std::string &name, const uint64_t val);
+
+ void output_time(const std::string &name, const uint64_t val);
+ void output_buf(const std::vector<char> &buf);
+ void start_array(const std::string &name) {}
+ void finish_array() {}
+ void start_object(const std::string &name) {}
+ void finish_object() {}
+};
+
+#endif /* __WRITER_CSV_H__ */