citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 9afb38d0780aabf2d0c3faf756d31871fa46626e
parent 1150eab6cc2ae925440246477474ad2a67d7818d
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Mon, 21 Mar 2016 23:47:01 -0600

viewer: sync with recent runtime changes

Diffstat:
Mviewer/runtime_client.cc | 58++++++++++++++++++++++++++++++++++++++--------------------
Mviewer/runtime_client.h | 19++++++++++++-------
2 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/viewer/runtime_client.cc b/viewer/runtime_client.cc @@ -14,31 +14,44 @@ RuntimeClient::RuntimeClient(af_unix *sock, demo_buffer_t *buf, demo_font_t *f) buffer(buf), font(f) { - assert(socket->read_all(num_tus) == 8); + uint64_t num_tus; + socket->read_all(num_tus); + translation_units.resize(num_tus); - for (int i = 0; i < num_tus; i++) { - uint64_t file_name_sz; - assert(socket->read_all(file_name_sz) == 8); + assert(sizeof(pid_t) == 4); + socket->read_all((uint8_t *)&process_id, 4); + socket->read_all((uint8_t *)&parent_process_id, 4); + socket->read_all((uint8_t *)&process_group, 4); - file_name.resize(file_name_sz); - assert(socket->read_all((uint8_t *)&file_name[0], file_name_sz) == file_name_sz); + std::stringstream ss; + ss << "Translation Units: " << num_tus << std::endl; + ss << "Process ID: " << process_id << std::endl; + ss << "Parent Process ID: " << parent_process_id << std::endl; + ss << "Process Group: " << process_group << std::endl; - read_file(); + glyphy_point_t top_left = { 0, 0 }; + demo_buffer_move_to(buffer, &top_left); + demo_buffer_add_text(buffer, ss.str().c_str(), font, 1); - assert(socket->read_all(num_lines) == 8); - execution_counts.resize(num_lines); - } + for (auto &current_unit : translation_units) { + top_left.y = 4; - glyphy_point_t top_left = { 0, 0 }; - for (auto &line : source_file_contents) { - demo_buffer_move_to(buffer, &top_left); - demo_buffer_add_text(buffer, line.c_str(), font, 1); - ++top_left.y; + uint64_t file_name_sz; + socket->read_all(file_name_sz); + + current_unit.file_name.resize(file_name_sz); + socket->read_all((uint8_t *)&current_unit.file_name[0], file_name_sz); + + read_file(current_unit.file_name, top_left); + top_left.x += 40; + + socket->read_all(current_unit.num_lines); + current_unit.execution_counts.resize(current_unit.num_lines); } } void -RuntimeClient::read_file() +RuntimeClient::read_file(std::string file_name, glyphy_point_t top_left) { std::string line; std::ifstream file_stream(file_name); @@ -46,8 +59,11 @@ RuntimeClient::read_file() if (file_stream.is_open() == 0) errx(1, "ifstream.open()"); - while (std::getline(file_stream, line)) - source_file_contents.push_back(line); + while (std::getline(file_stream, line)) { + demo_buffer_move_to(buffer, &top_left); + demo_buffer_add_text(buffer, line.c_str(), font, 1); + ++top_left.y; + } file_stream.close(); } @@ -60,8 +76,10 @@ RuntimeClient::draw() void RuntimeClient::idle() { - size_t bytes_total = num_lines * sizeof(uint64_t); - assert(socket->read_all((uint8_t *)&execution_counts[0], bytes_total) == bytes_total); + for (auto &trans_unit : translation_units) { + size_t bytes_total = trans_unit.num_lines * sizeof(uint64_t); + assert(socket->read_all((uint8_t *)&trans_unit.execution_counts[0], bytes_total) == bytes_total); + } // Send response back uint8_t msg_type = 1; diff --git a/viewer/runtime_client.h b/viewer/runtime_client.h @@ -10,6 +10,12 @@ #include "demo-buffer.h" #include "demo-font.h" +struct TranslationUnit { + std::string file_name; + uint64_t num_lines; + std::vector<uint64_t> execution_counts; +}; + class RuntimeClient : public drawable { public: RuntimeClient(af_unix *, demo_buffer_t *, demo_font_t *); @@ -17,18 +23,17 @@ public: void draw(); void idle(); private: - void read_file(); + void read_file(std::string, glyphy_point_t); + + pid_t process_id; + pid_t parent_process_id; + pid_t process_group; af_unix *socket; demo_buffer_t *buffer; demo_font_t *font; - uint64_t num_tus; - std::string file_name; - uint64_t num_lines; - - std::vector<std::string> source_file_contents; - std::vector<uint64_t> execution_counts; + std::vector<TranslationUnit> translation_units; }; #endif