Skip to content

Commit

Permalink
cloudtest
Browse files Browse the repository at this point in the history
  • Loading branch information
yekm committed Jun 12, 2023
1 parent 6220196 commit bb6c65f
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
run: ctest -V -C ${{env.BUILD_TYPE}}

16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ find_package(glfw3)

add_subdirectory(colormap)

add_executable(cloudlife)
target_sources(cloudlife PUBLIC
main.cpp
add_library(clouds OBJECT
artfactory.cpp
settings.cpp
imgui_elements.cpp
Expand All @@ -57,5 +55,17 @@ target_sources(cloudlife PUBLIC
vermiculate.cpp
discrete.cpp
thornbird.cpp)

target_link_libraries(clouds IMGUI glfw GL colormap)

add_executable(cloudlife main.cpp $<TARGET_OBJECTS:clouds>)
add_executable(cloudtest test.cpp $<TARGET_OBJECTS:clouds>)
target_link_libraries(cloudlife IMGUI glfw GL colormap)
target_link_libraries(cloudtest IMGUI glfw GL colormap)
set_target_properties(cloudlife PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set_target_properties(cloudtest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

include(CTest)

add_test(NAME CloudTest1 COMMAND cloudtest)
add_test(NAME CloudTest2 COMMAND cloudtest -f 32 -i 8)
7 changes: 7 additions & 0 deletions artfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ std::unique_ptr<Art> ArtFactory::get_art() {
return std::unique_ptr<Art>(create(vc.get_value()));
}

void ArtFactory::cycle_art() {
int i = vc.get_index() + 1;
if (i >= art_items.size())
i = 0;
vc.set_index(i);
}

bool ArtFactory::render_gui() {
return vc.RenderGui();
}
1 change: 1 addition & 0 deletions artfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ArtFactory : public Factory<Art> {
public:
ArtFactory();
std::unique_ptr<Art> get_art();
void cycle_art();
bool render_gui();
private:
VectorCombo::combo_container_t art_items;
Expand Down
15 changes: 12 additions & 3 deletions imgui_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsign
#include <sys/resource.h>
#include "timer.h"

void cpu_load_text()
char * cpu_load_text()
{
static int c = 0;
static double up = 0, sp = 0;
static common::Timer old_t;
static struct rusage old_usage;
static double outt = 0, ostt = 0;
static double ru_maxrss = 0;
static char text[1024*4];

if (c % 120 == 0) {
common::Timer t;
Expand All @@ -177,6 +178,14 @@ void cpu_load_text()
}
c++;

ImGui::Text("Usr + Sys = %.2f + %.2f = %.2f", up, sp, up+sp);
ImGui::Text("maxrss %.2f MB", ru_maxrss);
snprintf(text, sizeof(text),
"Usr + Sys = %.2f + %.2f = %.2f. maxrss %.2f MB",
up, sp, up+sp, ru_maxrss);

return text;
}

void cpu_load_gui()
{
ImGui::Text(cpu_load_text());
}
4 changes: 2 additions & 2 deletions imgui_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ bool ScrollableSliderFloat(const char* label, float* v, float v_min, float v_max
bool ScrollableSliderInt(const char* label, int* v, int v_min, int v_max, const char* format, float scrollFactor);
bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsigned v_max, const char* format, float scrollFactor);

void cpu_load_text();

char *cpu_load_text();
void cpu_load_gui();
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char *argv[])
1000.0f / ImGui::GetIO().Framerate,
ImGui::GetIO().Framerate);

cpu_load_text();
cpu_load_gui();

ImGui::End();

Expand Down
107 changes: 107 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <cstdint>
#include <memory>

#include <unistd.h> // getopt
#include <error.h>

#include "imgui.h"
#include "imgui_elements.h"

#include <stdio.h>

#include "timer.h"

#include "artfactory.h"

std::unique_ptr<Art> art;

static int sw = 1024, sh = 1024;

typedef uint32_t pixel_t;
pixel_t *image_data = NULL;
std::vector<pixel_t> image_data_vector;
#define texture_size (art->tex_w * art->tex_h * sizeof(pixel_t))

void make_pbos() {
image_data_vector.resize(texture_size);
image_data = image_data_vector.data();
}


int main(int argc, char *argv[])
{
int opt;
int frames = 128, iterations = 2, reporting = 1;

while ((opt = getopt(argc, argv, "f:i:r:")) != -1) {
switch (opt) {
case 'f':
frames = atoi(optarg);
break;
case 'i':
iterations = atoi(optarg);
break;
case 'r':
reporting = atoi(optarg);
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-f frames=128] [-i iterations=2] [-r reporting=1]\n",
argv[0]);
exit(EXIT_FAILURE);
}
}

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;

ImGui::StyleColorsDark();

ArtFactory af;
art = af.get_art();

std::string first_art(art->name());

do {
sw = sh = 1024;
for (int i=0; i<iterations; i++)
{
printf("%s %dx%d\n", art->name(), sw, sh);
art->resized(sw, sh);
art->frame_number = 0;
make_pbos();

float fps = 0;
common::Timer old_t;

while (art->frame_number < frames)
{
art->draw(image_data);

++art->frame_number;
if (art->clear_every != 0 && art->frame_number % art->clear_every == 0)
art->clear();

if (art->frame_number % reporting == 0) {
common::Timer t;
double dt = (t - old_t).seconds();
double fps = art->frame_number / dt;

printf("%s frame:%d fps:%.2f \r",
cpu_load_text(), art->frame_number, fps);
fflush(stdout);
}
}
sw += 321;
sh += 123;
printf("\n");
}

af.cycle_art();
art = af.get_art();
} while (first_art != art->name());

ImGui::DestroyContext();

return 0;
}

0 comments on commit bb6c65f

Please sign in to comment.