Quellcode durchsuchen

Allow playground file to be profiled

Ole vor 9 Jahren
Ursprung
Commit
9030274aa6
3 geänderte Dateien mit 27 neuen und 1 gelöschten Zeilen
  1. 3 0
      .gitignore
  2. 6 1
      Makefile
  3. 18 0
      examples/playground.cpp

+ 3 - 0
.gitignore

@@ -4,3 +4,6 @@ docs/html/
 
 *.d
 *.o
+
+cpuprofile.pdf
+cpuprofile.prof

+ 6 - 1
Makefile

@@ -69,9 +69,14 @@ examples: $(EXAMPLE_OBJS)
 $(EXAMPLE_DIR)/%.out: $(EXAMPLE_DIR)/%.cpp Makefile
 	$(CXX) $(USECXXFLAGS) $(USELDFLAGS) -MMD -MF$(<:%.cpp=%.d) -MT$@ -o$@ $< $(USELDLIBS)
 
+$(PLAYGROUND_OBJ): $(EXAMPLE_DIR)/$(PLAYGROUND_SRC) Makefile
+	$(CXX) $(USECXXFLAGS) $(USELDFLAGS) -MMD -MF$(<:%.cpp=%.d) -MT$@ -o$@ $< $(USELDLIBS) -lprofiler
+
 # Playground
 playground: $(PLAYGROUND_OBJ)
-	./$(PLAYGROUND_OBJ)
+	CPUPROFILE=./cpuprofile.prof ./$(PLAYGROUND_OBJ)
+	pprof --pdf ./$(PLAYGROUND_OBJ) ./cpuprofile.prof > cpuprofile.pdf
+	xdg-open cpuprofile.pdf
 
 # Phony
 .PHONY: all clean docs test examples playground

+ 18 - 0
examples/playground.cpp

@@ -1,5 +1,23 @@
 #include <luwra.hpp>
 
+#include <string>
+#include <iostream>
+
+using namespace luwra;
+
 int main() {
+	StateWrapper state;
+
+	state["t1"] = FieldVector {};
+
+	for (int i = 0; i < 50000000; i++) {
+		state["t1"]["value"] = i;
+		int j = state["t1"]["value"];
+
+		if (j != i) {
+			return 1;
+		}
+	}
+
 	return 0;
 }