Trace Parser: add API map list support 57/160157/6
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 14 Nov 2017 16:24:30 +0000 (19:24 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Thu, 16 Nov 2017 17:09:10 +0000 (20:09 +0300)
Just specify it with -a

Change-Id: I1a6754ebdafc4c7ea05d81782b517d82b5336c40
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
src/cli/trace_parser/exe/main.cpp
src/cli/trace_parser/exe/session_data.cpp
src/cli/trace_parser/exe/session_data.h
src/cli/trace_parser/include/parser.h
src/cli/trace_parser/lib/parser.cpp
src/cli/trace_parser/lib/protocol.h
src/cli/trace_parser/lib/protocol30.cpp

index 09dd6d0..e331e55 100644 (file)
@@ -66,7 +66,7 @@ static void parse_loop(const Parser &parser, std::iostream &ios)
 static Parser get_parser(const SessionData &sd, std::iostream &out)
 {
     auto dw = get_data_writer(sd.get_type(), out);
-    ParserOptions opt(sd.get_version(), sd.get_cpu_num(), sd.get_devs_num(), dw);
+    ParserOptions opt(sd.get_version(), sd.get_cpu_num(), sd.get_devs_num(), dw, sd.get_api_map());
 
     return Parser(opt);
 }
index f9aa829..9c65371 100644 (file)
@@ -56,6 +56,7 @@ po::variables_map SessionData::parse_cmdline(int argc, char **argv)
             ("help,h", "Print help message")
             ("input,i", po::value<std::string>(), "Input trace file")
             ("session,s", po::value<std::string>(), "Trace's session data")
+            ("api_map,a", po::value<std::string>(), "API map list from target")
             ("output,o", po::value<std::string>(), "Output file")
             ("cpu_num,c", po::value<int>()->default_value(4), "Target CPUs number")
             ("devs_num,e", po::value<int>()->default_value(5), "Target energy devices number")
@@ -169,9 +170,39 @@ void SessionData::fill_data(const po::variables_map &vm)
         fill_by_cmdline(vm);
 }
 
+void SessionData::read_api_map(const std::string &api_path)
+{
+    std::ifstream file(api_path);
+
+    if (file.is_open()) {
+        std::string line;
+        int id;
+
+        while (std::getline(file, line)) {
+            std::string::size_type n;
+
+            if (file.eof()) {
+                if (!line.empty())
+                    std::cerr << "API file <" << api_path << "> ends with non-empty line!" << std::endl;
+                break;
+            }
+
+            n = line.find(' ');
+            id = std::stoi(line.substr(0, n));
+            // Remove also space between id and API name
+            line.erase(0, n + 1);
+
+            api_list_.insert(std::make_pair(id, line));
+        }
+    }
+}
+
 SessionData::SessionData(int argc, char **argv)
 {
     po::variables_map vm = parse_cmdline(argc, argv);
 
     fill_data(vm);
+
+    if (vm.count("api_map"))
+        read_api_map(vm["api_map"].as<std::string>());
 }
index f8347c1..2bb5e4e 100644 (file)
@@ -38,10 +38,11 @@ class SessionData
 public:
     SessionData(int argc, char **argv);
 
-    std::string get_type() const { return type_; }
-    std::string get_version() const { return ver_; }
-    std::string get_input() const { return input_; }
-    std::string get_output() const { return output_; }
+    const std::string &get_type() const { return type_; }
+    const std::string &get_version() const { return ver_; }
+    const std::string &get_input() const { return input_; }
+    const std::string &get_output() const { return output_; }
+    const std::map<int, std::string> &get_api_map() const { return api_list_; }
     int get_cpu_num() const { return cpu_num_; }
     int get_devs_num() const { return devs_num_; }
 
@@ -50,6 +51,7 @@ private:
     std::string ver_;
     std::string input_;
     std::string output_;
+    std::map<int, std::string> api_list_;
     int cpu_num_;
     int devs_num_;
 
@@ -57,6 +59,7 @@ private:
     void fill_data(const boost::program_options::variables_map &vm);
     void fill_by_file(const boost::program_options::variables_map &vm);
     void fill_by_cmdline(const boost::program_options::variables_map &vm);
+    void read_api_map(const std::string &api_path);
 };
 
 #endif /* __SESSION_DATA_H__ */
index 8479f57..ecbf5f2 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <memory>
 #include <string>
+#include <map>
 #include <data_writer.h>
 
 
@@ -62,13 +63,15 @@ struct ParserOptions
     const int cpu_num;
     const int devs_num;
     std::shared_ptr<DataWriter> writer;
+    std::map<int, std::string> &api_map;
 
     ParserOptions(const std::string &version, const int cpu_num, const int devs_num,
-                  std::shared_ptr<DataWriter> writer) :
+                  std::shared_ptr<DataWriter> writer, std::map<int, std::string> api_map) :
         version(version),
         cpu_num(cpu_num),
         devs_num(devs_num),
-        writer(writer)
+        writer(writer),
+        api_map(api_map)
     {}
 };
 
index d27cbe0..0753e43 100644 (file)
@@ -46,15 +46,16 @@ Parser::Parser(const ParserOptions &init_data)
     const int cpu_num = init_data.cpu_num;
     const int devs_num = init_data.devs_num;
     std::shared_ptr<DataWriter> dw = init_data.writer;
+    std::map<int, std::string> &api_map = init_data.api_map;
 
     if (!init_data.version.compare(v30))
-        protocol_ = std::make_unique<Protocol30>(dw, cpu_num, devs_num);
+        protocol_ = std::make_unique<Protocol30>(dw, cpu_num, devs_num, api_map);
     else if (!init_data.version.compare(v40))
-        protocol_ = std::make_unique<Protocol40>(dw, cpu_num, devs_num);
+        protocol_ = std::make_unique<Protocol40>(dw, cpu_num, devs_num, api_map);
     else if (!init_data.version.compare(v41))
-        protocol_ = std::make_unique<Protocol41>(dw, cpu_num, devs_num);
+        protocol_ = std::make_unique<Protocol41>(dw, cpu_num, devs_num, api_map);
     else if (!init_data.version.compare(v42))
-        protocol_ = std::make_unique<Protocol42>(dw, cpu_num, devs_num);
+        protocol_ = std::make_unique<Protocol42>(dw, cpu_num, devs_num, api_map);
     else
         throw std::logic_error((boost::format("Wrong protocol version <%1%>. \
                                                Suppotred versions are <%2%>, \
index 83116ea..e1b5ea0 100644 (file)
 class Protocol
 {
 public:
-    Protocol(std::shared_ptr<DataWriter> writer, const int cpu_num, const int devs_num) :
+    Protocol(std::shared_ptr<DataWriter> writer, const int cpu_num, const int devs_num,
+             const std::map<int, std::string> &api_map) :
         writer_(writer),
         cpu_num_(cpu_num),
-        devs_num_(devs_num)
+        devs_num_(devs_num),
+        api_map_(api_map)
     {}
 
+    const std::string &get_api_name(int id) const
+    {
+        static const std::string empty = "";
+        auto it = api_map_.find(id);
+
+        if (it != api_map_.end())
+            return it->second;
+        else
+            return empty;
+    }
+
+    bool is_api_names_available() const
+    {
+        return !api_map_.empty();
+    }
+
     virtual void start_file() const { writer_->start_file(get_version()); }
     virtual void finish_file() const { writer_->finish_file(); }
     virtual uint32_t get_version() const { return 0; }
@@ -58,6 +76,7 @@ protected:
     std::shared_ptr<DataWriter> writer_;
     const int cpu_num_;
     const int devs_num_;
+    const std::map<int, std::string> api_map_;
 };
 
 #endif /* __PROTOCOL_H__ */
index 50438b1..91ac092 100644 (file)
@@ -505,7 +505,10 @@ void Protocol30::parse_probe_common(Buffer &buf) const
     uint64_t pc_addr, addr;
     struct lmap_info info;
 
-    writer_->output_val("api_id", buf.get_val<uint32_t>());
+    uint32_t api_id = buf.get_val<uint32_t>();
+    writer_->output_val("api_id", api_id);
+    if (is_api_names_available())
+        writer_->output_val("api_id_name", get_api_name(api_id));
 
     pid = buf.get_val<uint32_t>();
     writer_->output_val("pid", pid);