citrun

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

commit 06da48ae5728c29d29c7fb53aa0f5c865d44d284
parent 020c65ace92d58a9898bc70fd1130f5ba6972459
Author: Kyle Milz <kyle@0x30.net>
Date:   Thu, 15 Dec 2016 21:27:48 -0700

src: let each process file have its own gl buffer

Diffstat:
Msrc/Jamfile | 8++++----
Msrc/gl_main.cc | 84++++++++++++++++++++++++-------------------------------------------------------
Msrc/gl_view.cc | 9++-------
Msrc/gl_view.h | 4++--
Msrc/process_file.cc | 60++++++++++++++++++++++++++++++++----------------------------
Msrc/process_file.h | 11++++++-----
6 files changed, 71 insertions(+), 105 deletions(-)

diff --git a/src/Jamfile b/src/Jamfile @@ -1,11 +1,10 @@ SubDir TOP src ; # -# libcitrun.a and utils.a +# libcitrun.a # ObjectCcFlags rt.c : -fPIC -ansi ; Library libcitrun : rt.c ; -Library utils : process_file.cc process_dir.cc ; # # citrun-wrap, citrun-check @@ -21,13 +20,14 @@ ReplaceTokens citrun-wrap ; # LINKLIBS on citrun-term += -lcurses ; # XXX: Not the main focus right now. -# LinkLibraries citrun-term : utils ; # Main citrun-term : term_main.cc ; # # citrun-gl & citrun-gltest # GL_SRCS = + process_file.cc + process_dir.cc gl_view.cc demo-atlas.cc gl_buffer.cc @@ -46,7 +46,7 @@ ObjectC++Flags gl_main.cc gl_testmain.cc $(GL_SRCS) : `pkg-config $(PKG_CONFIG_LIBS) --cflags` ; LINKLIBS on citrun-gl citrun-gltest += -lm `pkg-config $(PKG_CONFIG_LIBS) --libs` ; -LinkLibraries citrun-gl citrun-gltest : gl_common libglyphy utils ; +LinkLibraries citrun-gl citrun-gltest : gl_common libglyphy ; LINKLIBS on citrun-gltest += -lOSMesa ; diff --git a/src/gl_main.cc b/src/gl_main.cc @@ -2,7 +2,6 @@ #include <GL/glew.h> #include <err.h> #include <iostream> -#include <sstream> #include <vector> #include "gl_buffer.h" @@ -13,14 +12,8 @@ #include <GLFW/glfw3.h> -demo_glstate_t *st; - -std::vector<ProcessFile> drawables; -ProcessDir m_pdir; View *static_vu; -demo_buffer_t *buffer; - void reshape_func(int width, int height) { @@ -52,55 +45,8 @@ motion_func(int x, int y) } void -add_new_process(std::string const &file_name, demo_font_t *font) -{ - drawables.push_back(ProcessFile(file_name)); - ProcessFile *pfile = &drawables.back(); - - demo_buffer_clear(buffer); - - std::stringstream ss; - ss << "program name:\t" << pfile->progname() << std::endl; - ss << "trnsltn units:\t" << pfile->m_tus.size() << std::endl; - ss << "process id:\t" << pfile->getpid() << std::endl; - ss << "parent pid:\t" << pfile->getppid() << std::endl; - ss << "process group:\t" << pfile->getpgrp() << std::endl; - - glyphy_point_t cur_pos = { 0, 0 }; - demo_buffer_move_to(buffer, &cur_pos); - - demo_buffer_add_text(buffer, ss.str().c_str(), font, 2); - - demo_buffer_current_point(buffer, &cur_pos); - - cur_pos.x = 0; - for (auto &t : pfile->m_tus) { - demo_buffer_add_text(buffer, t.comp_file_path().c_str(), font, 1); - } -} - -void next_frame(View *vu, demo_font_t *font) { - for (std::string &file_name : m_pdir.scan()) - add_new_process(file_name, font); - - for (auto &rp : drawables) { - // rp.read_executions(); - - //glyphy_point_t tmp; - for (auto &t : rp.m_tus) { - //size_t bytes_total = t.num_lines * sizeof(uint64_t); - - for (unsigned int i = 0; i < t.num_lines(); i++) { - //if (t.exec_counts[i] == 0) - // continue; - - // demo_buffer_add_text(buffer, ">>", font, 1); - } - } - std::cout << "tick" << std::endl; - } } static void @@ -144,10 +90,13 @@ main(int argc, char *argv[]) if (!glewIsSupported("GL_VERSION_2_0")) errx(1, "No support for OpenGL 2.0 found"); - st = demo_glstate_create(); - buffer = demo_buffer_create(); + ProcessDir m_pdir; + std::vector<ProcessFile> drawables; - static_vu = new View(st, buffer); + demo_glstate_t *st = demo_glstate_create(); + demo_buffer_t *buffer = demo_buffer_create(); + + static_vu = new View(st); demo_font_t *font = demo_font_create(demo_glstate_get_atlas(st)); @@ -159,8 +108,25 @@ main(int argc, char *argv[]) while (!glfwWindowShouldClose(window)) { - next_frame(static_vu, font); - static_vu->display(); + for (std::string &file_name : m_pdir.scan()) + drawables.push_back(ProcessFile(file_name, font)); + + glyphy_extents_t extents; + for (auto &i : drawables) { + glyphy_extents_t t = i.get_extents(); + extents.max_x = std::max(extents.max_x, t.max_x); + extents.max_y = std::max(extents.max_y, t.max_y); + extents.min_x = std::min(extents.min_x, t.min_x); + extents.min_y = std::min(extents.min_y, t.min_y); + } + + // Set up view transforms + static_vu->display(extents); + + demo_buffer_draw (buffer); + + for (auto &i : drawables) + i.display(); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/src/gl_view.cc b/src/gl_view.cc @@ -29,10 +29,9 @@ extern "C" { void start_animation(); -View::View(demo_glstate_t *st, demo_buffer_t *buf) : +View::View(demo_glstate_t *st) : refcount(1), st(st), - buffer(buf), fullscreen(false) { TRACE(); @@ -471,7 +470,7 @@ View::advance_frame(long dtime) } void -View::display() +View::display(glyphy_extents_t const &extents) { long new_time = current_time (); advance_frame(new_time - last_frame_time); @@ -490,8 +489,6 @@ View::display() apply_transform(mat); // Buffer best-fit - glyphy_extents_t extents; - demo_buffer_extents (buffer, NULL, &extents); double content_scale = .9 * std::min (width / (extents.max_x - extents.min_x), height / (extents.max_y - extents.min_y)); m4Scale (mat, content_scale, content_scale, 1); @@ -504,8 +501,6 @@ View::display() glClearColor (1, 1, 1, 1); glClear (GL_COLOR_BUFFER_BIT); - - demo_buffer_draw (buffer); } void diff --git a/src/gl_view.h b/src/gl_view.h @@ -8,7 +8,7 @@ class View { public: - View(demo_glstate_t *, demo_buffer_t *); + View(demo_glstate_t *); ~View(); void reset(); @@ -18,7 +18,7 @@ public: void mouse_func(int button, int state, int x, int y); void motion_func(int x, int y); void print_help(); - void display(); + void display(glyphy_extents_t const &); void setup(); /* Animation */ diff --git a/src/process_file.cc b/src/process_file.cc @@ -23,7 +23,7 @@ #include <fcntl.h> // O_RDONLY #include <fstream> #include <iostream> -#include <stdlib.h> // getenv +#include <sstream> #include <unistd.h> // getpagesize #include "process_file.h" @@ -108,11 +108,12 @@ TranslationUnit::save_executions() // Take a filesystem path and memory map its contents. Map at least a header // structure on top of it. // -ProcessFile::ProcessFile(std::string const &path) : +ProcessFile::ProcessFile(std::string const &path, demo_font_t *font) : m_path(path), m_fd(0), m_tus_with_execs(0), - m_program_loc(0) + m_program_loc(0), + m_gl_buffer(demo_buffer_create()) { struct stat sb; void *mem, *end; @@ -123,8 +124,9 @@ ProcessFile::ProcessFile(std::string const &path) : if (fstat(m_fd, &sb) < 0) err(1, "fstat"); - if (sb.st_size > 1024 * 1024 * 1024) - errx(1, "shared memory too large: %lli", sb.st_size); + // Explicitly check 0 here otherwise mmap barfs. + if (sb.st_size == 0 || sb.st_size > 1024 * 1024 * 1024) + errx(1, "invalid file size %lli", sb.st_size); m_size = sb.st_size; @@ -148,6 +150,23 @@ ProcessFile::ProcessFile(std::string const &path) : for (auto &t : m_tus) m_program_loc += t.num_lines(); + + std::stringstream ss; + ss << "Program Name:" << m_header->progname << std::endl; + ss << "Translation Units:" << m_tus.size() << std::endl; + ss << "Lines of Code:" << m_program_loc << std::endl; + ss << "Process Id:" << m_header->pids[0] << std::endl; + ss << "Parent Process Id:" << m_header->pids[1] << std::endl; + ss << "Process Group:" << m_header->pids[2] << std::endl; + + glyphy_point_t cur_pos = { 0, 0 }; + demo_buffer_move_to(m_gl_buffer, &cur_pos); + demo_buffer_add_text(m_gl_buffer, ss.str().c_str(), font, 2); + + demo_buffer_current_point(m_gl_buffer, &cur_pos); + cur_pos.x = 0; + for (auto &t : m_tus) + demo_buffer_add_text(m_gl_buffer, t.comp_file_path().c_str(), font, 1); } // @@ -170,32 +189,17 @@ ProcessFile::find_tu(std::string const &srcname) const return NULL; } -// -// Return program the runtime is/was running within. -// -std::string -ProcessFile::progname() const -{ - return std::string(m_header->progname); -} - -// -// Return the pid, ppid, pgrp the runtime is/was running within. -// -int -ProcessFile::getpid() const +void +ProcessFile::display() const { - return m_header->pids[0]; + demo_buffer_draw (m_gl_buffer); } -int -ProcessFile::getppid() const +glyphy_extents_t +ProcessFile::get_extents() const { - return m_header->pids[1]; -} + glyphy_extents_t extents; + demo_buffer_extents(m_gl_buffer, NULL, &extents); -int -ProcessFile::getpgrp() const -{ - return m_header->pids[2]; + return extents; } diff --git a/src/process_file.h b/src/process_file.h @@ -1,6 +1,8 @@ #include <string> #include <vector> +#include "gl_buffer.h" + // // Owns a few pages of shared memory that are created by a running instrumented @@ -34,16 +36,15 @@ class ProcessFile size_t m_size; int m_tus_with_execs; unsigned int m_program_loc; + demo_buffer_t *m_gl_buffer; public: - ProcessFile(std::string const &); + ProcessFile(std::string const &, demo_font_t *); const TranslationUnit *find_tu(std::string const &) const; bool is_alive() const; - std::string progname() const; - int getpid() const; - int getppid() const; - int getpgrp() const; + void display() const; + glyphy_extents_t get_extents() const; std::vector<TranslationUnit> m_tus; };