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);
}
("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")
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>());
}
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_; }
std::string ver_;
std::string input_;
std::string output_;
+ std::map<int, std::string> api_list_;
int cpu_num_;
int devs_num_;
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__ */
#include <memory>
#include <string>
+#include <map>
#include <data_writer.h>
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)
{}
};
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%>, \
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; }
std::shared_ptr<DataWriter> writer_;
const int cpu_num_;
const int devs_num_;
+ const std::map<int, std::string> api_map_;
};
#endif /* __PROTOCOL_H__ */
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);