commit 894804e756cd1f6c793aca5bdfbc65652c41c105 Author: themancalledjakob Date: Sun May 17 11:09:47 2020 +0200 initial commit diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..b920a0e --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,43 @@ +version: 1.0.{build} + +environment: + global: + APPVEYOR_OS_NAME: windows + matrix: + #MSYS2 Building + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + platform: x86 + BUILDER: MSYS2 + + #VisualStudio Building + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + platform: x86 + BUILDER : VS + BITS: 32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + platform: x64 + BUILDER : VS + BITS: 64 + +configuration: Debug +shallow_clone: true +clone_depth: 10 + +init: +- set MSYS2_PATH=c:\msys64 +- set CHERE_INVOKING=1 +- if "%BUILDER%_%PLATFORM%"=="MSYS2_x86" set MSYSTEM=MINGW32 +- if "%BUILDER%_%PLATFORM%"=="MSYS2_x64" set MSYSTEM=MINGW64 +- '%MSYS2_PATH%\usr\bin\bash -lc "pacman --noconfirm -S --needed unzip rsync"' +- if "%BUILDER%"=="VS" set PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin;%PATH% + +install: +- cd .. +- git clone --depth=1 --branch=master https://github.com/openframeworks/openFrameworks +- call openFrameworks\scripts\ci\addons\install.cmd + +build_script: +- cd %OF_PATH% +- scripts\ci\addons\build.cmd + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..593962f --- /dev/null +++ b/.gitignore @@ -0,0 +1,107 @@ +######################### +# general patterns +######################### + +docs/html +docs/tagfile.xml + +*/bin/* +!*/bin/data/ + +# for bin folder in root +/bin/* +!/bin/data/ + +[Bb]uild/ +[Oo]bj/ +*.o +[Dd]ebug*/ +[Rr]elease*/ +*.mode* +*.app/ +*.pyc +.svn/ + +######################### +# IDE +######################### + +# XCode +*.pbxuser +*.perspective +*.perspectivev3 +*.mode1v3 +*.mode2v3 +#XCode 4 +xcuserdata +*.xcworkspace + +# Code::Blocks +*.depend +*.layout +*.cbTemp + +# Visual Studio +*.sdf +*.opensdf +*.suo +*.pdb +*.ilk +*.aps +ipch/ + +# Eclipse +.metadata +local.properties +.externalToolBuilders + +# Codelite +*.session +*.tags +*.workspace.* + +######################### +# operating system +######################### + +# Linux +*~ +# KDE +.directory +.AppleDouble + +# OSX +.DS_Store +*.swp +*~.nib +# Thumbnails +._* + +# Windows +# Windows image file caches +Thumbs.db +# Folder config file +Desktop.ini + +#Android +.csettings + +######################### +# packages +######################### + +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases +*.log +*.sql +*.sqlite diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c4b3e2e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,199 @@ +# This file allows testing your addon using travis CI servers to use it you'll need to +# create an account in travis.org and enable your addon there. +# +# By default it will test linux 64bit and osx against the master and stable OF branches. +# Other platforms can be enabled by uncommenting the corresponding sections. +# +# If any extra install is needed to use the addon it can be included in the corresponding +# install script in: +# +# scripts/ci/$TARGET/install.sh +# + + +language: c++ +compiler: gcc +sudo: true +matrix: + include: + # fully specify builds, include can't dynamically expand matrix entries + # relative order of sudo and env is important so that addons: is recognized + +# Linux 64bit, OF master + - os: linux + dist: trusty + sudo: required + env: TARGET="linux64" OF_BRANCH="master" + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.9 + - g++-4.9 + - gdb + +# Linux 64bit, OF stable: Not supported yet +# - os: linux +# dist: trusty +# sudo: required +# env: TARGET="linux64" OF_BRANCH="stable" +# addons: +# apt: +# sources: +# - ubuntu-toolchain-r-test +# packages: +# - gcc-4.9 +# - g++-4.9 +# - gdb + +# OSX, OF master + - os: osx + osx_image: xcode8 + compiler: clang + env: TARGET="osx" OF_BRANCH="master" + +# OSX, OF stable: Not supported yet +# - os: osx +# osx_image: xcode8 +# compiler: clang +# env: TARGET="osx" OF_BRANCH="stable" + +# Linux ARM6, OF master: Uncomment following lines to enable +# - os: linux +# sudo: required +# dist: trusty +# env: TARGET="linuxarmv6l" OF_BRANCH="master" + + +# Linux ARM6, OF stable: Not supported yet +# - os: linux +# sudo: required +# dist: trusty +# env: TARGET="linuxarmv6l" OF_BRANCH="stable" + +# Linux ARM7, OF master: Uncomment following lines to enable +# - os: linux +# sudo: false +# env: TARGET="linuxarmv7l" OF_BRANCH="master" +# cache: +# directories: +# - ~/rpi2_toolchain +# - ~/firmware-master +# - ~/archlinux + +# Linux ARM7, OF stable: Not supported yet +# - os: linux +# sudo: false +# env: TARGET="linuxarmv7l" OF_BRANCH="stable" +# cache: +# directories: +# - ~/rpi2_toolchain +# - ~/firmware-master +# - ~/archlinux + + +# Emscripten, OF master: Uncomment following lines to enable +# - os: linux +# sudo: false +# env: TARGET="emscripten" OF_BRANCH="master" +# addons: +# apt: +# sources: +# - ubuntu-toolchain-r-test +# packages: +# - libstdc++6 + + +# Emscripten, OF stable: Not supported yet +# - os: linux +# sudo: false +# env: TARGET="emscripten" OF_BRANCH="stable" +# addons: +# apt: +# sources: +# - ubuntu-toolchain-r-test +# packages: +# - libstdc++6 + + +# iOS, OF master: Not supported yet +# - os: osx +# osx_image: xcode8 +# compiler: clang +# env: TARGET="ios" OF_BRANCH="master" + + +# iOS, OF stable: Not supported yet +# - os: osx +# osx_image: xcode8 +# compiler: clang +# env: TARGET="ios" OF_BRANCH="stable" + + +# tvOS, OF master: Not supported yet +# - os: osx +# osx_image: xcode8 +# compiler: clang +# env: TARGET="tvos" OF_BRANCH="master" + + +# tvOS, OF stable: Not supported yet +# - os: osx +# osx_image: xcode8 +# compiler: clang +# env: TARGET="tvos" OF_BRANCH="stable" + + +# Android armv7, OF master: Uncomment following lines to enable +# - os: linux +# sudo: false +# env: TARGET="android" OPT="armv7" OF_BRANCH="master" +# cache: +# directories: +# - ~/android-ndk-r12b + + +# Android armv7, OF stable: Not supported yet +# - os: linux +# sudo: false +# env: TARGET="android" OPT="armv7" OF_BRANCH="stable" +# cache: +# directories: +# - ~/android-ndk-r12b + + +# Android x86, OF master: Uncomment following lines to enable +# - os: linux +# sudo: false +# env: TARGET="android" OPT="x86" OF_BRANCH="master" +# cache: +# directories: +# - ~/android-ndk-r12b + + +# Android x86, OF stable: Not supported yet +# - os: linux +# sudo: false +# env: TARGET="android" OPT="x86" OF_BRANCH="stable" +# cache: +# directories: +# - ~/android-ndk-r12b + + + # Exclude the default build that would otherwise be generated + # see https://github.com/travis-ci/travis-ci/issues/1228 + exclude: + - compiler: gcc + +install: + - cd ~ + - git clone --depth=1 --branch=$OF_BRANCH https://github.com/openframeworks/openFrameworks + - cd openFrameworks + - scripts/ci/addons/install.sh + +script: + - scripts/ci/addons/build.sh + +git: + depth: 10 diff --git a/README.md b/README.md new file mode 100644 index 0000000..00e5541 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +ofxProfile +================ + +OpenFrameworks addon for simple and quick thread safe profiling. +Then throw the result in chrome://tracing + +This addon is practically cut and paste from https://github.com/TheCherno/Hazel/blob/master/Hazel/src/Hazel/Debug/Instrumentor.h + + + +## Usage + +add ofxProfiler to your application with projectGenerator (or whatever method you prefer) + +ofApp.h +``` +// uncommment to profile +// #define OFX_PROFILER 1 + +#include "ofxProfiler.h" + +// ... bla bla bla +``` + +ofApp.cpp +``` +//-------------------------------------------------------------- +void ofApp::setup() { + OFX_PROFILER_BEGIN_SESSION("a test","result.json"); + OFX_PROFILER_FUNCTION(); + + +} // end of scope => profile function ends + +//-------------------------------------------------------------- +void ofApp::update() { + OFX_PROFILER_FUNCTION(); + + { + OFX_PROFILER_SCOPE("scope 1"); + } + + { + OFX_PROFILER_SCOPE("scope 2"); + } +} + +//-------------------------------------------------------------- +void ofApp::exit() { + OFX_PROFILER_END_SESSION(); +} +``` + +then open the json with chrome://tracing diff --git a/addon_config.mk b/addon_config.mk new file mode 100644 index 0000000..7a406bf --- /dev/null +++ b/addon_config.mk @@ -0,0 +1,103 @@ +# All variables and this file are optional, if they are not present the PG and the +# makefiles will try to parse the correct values from the file system. +# +# Variables that specify exclusions can use % as a wildcard to specify that anything in +# that position will match. A partial path can also be specified to, for example, exclude +# a whole folder from the parsed paths from the file system +# +# Variables can be specified using = or += +# = will clear the contents of that variable both specified from the file or the ones parsed +# from the file system +# += will add the values to the previous ones in the file or the ones parsed from the file +# system +# +# The PG can be used to detect errors in this file, just create a new project with this addon +# and the PG will write to the console the kind of error and in which line it is + +meta: + ADDON_NAME = ofxProfiler + ADDON_DESCRIPTION = profile your applications, use chrome or firefox for visualisation + ADDON_AUTHOR = @themancalledjakob + ADDON_TAGS = "profiling" "tracing" "performance" + ADDON_URL = http://github.com/themancalledjakb/ofxProfiler + +common: + # dependencies with other addons, a list of them separated by spaces + # or use += in several lines + # ADDON_DEPENDENCIES = + + # include search paths, this will be usually parsed from the file system + # but if the addon or addon libraries need special search paths they can be + # specified here separated by spaces or one per line using += + # ADDON_INCLUDES = + + # any special flag that should be passed to the compiler when using this + # addon + # ADDON_CFLAGS = + + # any special flag that should be passed to the compiler for c++ files when + # using this addon + # ADDON_CPPFLAGS = + + # any special flag that should be passed to the linker when using this + # addon, also used for system libraries with -lname + # ADDON_LDFLAGS = + + # source files, these will be usually parsed from the file system looking + # in the src folders in libs and the root of the addon. if your addon needs + # to include files in different places or a different set of files per platform + # they can be specified here + # ADDON_SOURCES = + + # source files that will be included as C files explicitly + # ADDON_C_SOURCES = + + # source files that will be included as header files explicitly + # ADDON_HEADER_SOURCES = + + # source files that will be included as c++ files explicitly + # ADDON_CPP_SOURCES = + + # source files that will be included as objective c files explicitly + # ADDON_OBJC_SOURCES = + + # derines that will be passed to the compiler when including this addon + # ADDON_DEFINES + + # some addons need resources to be copied to the bin/data folder of the project + # specify here any files that need to be copied, you can use wildcards like * and ? + # ADDON_DATA = + + # when parsing the file system looking for libraries exclude this for all or + # a specific platform + # ADDON_LIBS_EXCLUDE = + + # binary libraries, these will be usually parsed from the file system but some + # libraries need to passed to the linker in a specific order/ + # + # For example in the ofxOpenCV addon we do something like this: + # + # ADDON_LIBS = + # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_legacy.a + # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_calib3d.a + # ... + + +linux64: + # linux only, any library that should be included in the project using + # pkg-config + # ADDON_PKG_CONFIG_LIBRARIES = +vs: + # After compiling copy the following dynamic libraries to the executable directory + # only windows visual studio + # ADDON_DLLS_TO_COPY = + +linuxarmv6l: +linuxarmv7l: +android/armeabi: +android/armeabi-v7a: +osx: + # osx/iOS only, any framework that should be included in the project + # ADDON_FRAMEWORKS = +ios: + diff --git a/example-empty/Makefile b/example-empty/Makefile new file mode 100644 index 0000000..177e172 --- /dev/null +++ b/example-empty/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=$(realpath ../../..) +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/example-empty/addons.make b/example-empty/addons.make new file mode 100644 index 0000000..e4f38ae --- /dev/null +++ b/example-empty/addons.make @@ -0,0 +1 @@ +ofxProfiler diff --git a/example-empty/bin/data/.gitkeep b/example-empty/bin/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/example-empty/config.make b/example-empty/config.make new file mode 100644 index 0000000..836fce7 --- /dev/null +++ b/example-empty/config.make @@ -0,0 +1,141 @@ +################################################################################ +# CONFIGURE PROJECT MAKEFILE (optional) +# This file is where we make project specific configurations. +################################################################################ + +################################################################################ +# OF ROOT +# The location of your root openFrameworks installation +# (default) OF_ROOT = ../../.. +################################################################################ +# OF_ROOT = ../../.. + +################################################################################ +# PROJECT ROOT +# The location of the project - a starting place for searching for files +# (default) PROJECT_ROOT = . (this directory) +# +################################################################################ +# PROJECT_ROOT = . + +################################################################################ +# PROJECT SPECIFIC CHECKS +# This is a project defined section to create internal makefile flags to +# conditionally enable or disable the addition of various features within +# this makefile. For instance, if you want to make changes based on whether +# GTK is installed, one might test that here and create a variable to check. +################################################################################ +# None + +################################################################################ +# PROJECT EXTERNAL SOURCE PATHS +# These are fully qualified paths that are not within the PROJECT_ROOT folder. +# Like source folders in the PROJECT_ROOT, these paths are subject to +# exlclusion via the PROJECT_EXLCUSIONS list. +# +# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXTERNAL_SOURCE_PATHS = + +################################################################################ +# PROJECT EXCLUSIONS +# These makefiles assume that all folders in your current project directory +# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations +# to look for source code. The any folders or files that match any of the +# items in the PROJECT_EXCLUSIONS list below will be ignored. +# +# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete +# string unless teh user adds a wildcard (%) operator to match subdirectories. +# GNU make only allows one wildcard for matching. The second wildcard (%) is +# treated literally. +# +# (default) PROJECT_EXCLUSIONS = (blank) +# +# Will automatically exclude the following: +# +# $(PROJECT_ROOT)/bin% +# $(PROJECT_ROOT)/obj% +# $(PROJECT_ROOT)/%.xcodeproj +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXCLUSIONS = + +################################################################################ +# PROJECT LINKER FLAGS +# These flags will be sent to the linker when compiling the executable. +# +# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs +# +# Note: Leave a leading space when adding list items with the += operator +# +# Currently, shared libraries that are needed are copied to the +# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to +# add a runtime path to search for those shared libraries, since they aren't +# incorporated directly into the final executable application binary. +################################################################################ +# PROJECT_LDFLAGS=-Wl,-rpath=./libs + +################################################################################ +# PROJECT DEFINES +# Create a space-delimited list of DEFINES. The list will be converted into +# CFLAGS with the "-D" flag later in the makefile. +# +# (default) PROJECT_DEFINES = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_DEFINES = + +################################################################################ +# PROJECT CFLAGS +# This is a list of fully qualified CFLAGS required when compiling for this +# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS +# defined in your platform specific core configuration files. These flags are +# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. +# +# (default) PROJECT_CFLAGS = (blank) +# +# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in +# your platform specific configuration file will be applied by default and +# further flags here may not be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CFLAGS = + +################################################################################ +# PROJECT OPTIMIZATION CFLAGS +# These are lists of CFLAGS that are target-specific. While any flags could +# be conditionally added, they are usually limited to optimization flags. +# These flags are added BEFORE the PROJECT_CFLAGS. +# +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) +# +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) +# +# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the +# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration +# file will be applied by default and further optimization flags here may not +# be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE = +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG = + +################################################################################ +# PROJECT COMPILERS +# Custom compilers can be set for CC and CXX +# (default) PROJECT_CXX = (blank) +# (default) PROJECT_CC = (blank) +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CXX = +# PROJECT_CC = diff --git a/example-empty/example-empty.qbs b/example-empty/example-empty.qbs new file mode 100644 index 0000000..1ff9af2 --- /dev/null +++ b/example-empty/example-empty.qbs @@ -0,0 +1,68 @@ +import qbs +import qbs.Process +import qbs.File +import qbs.FileInfo +import qbs.TextFile +import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp + +Project{ + property string of_root: "../../.." + + ofApp { + name: { return FileInfo.baseName(sourceDirectory) } + + files: [ + 'src/main.cpp', + 'src/ofApp.cpp', + 'src/ofApp.h', + ] + + of.addons: [ + 'ofxProfiler', + ] + + // additional flags for the project. the of module sets some + // flags by default to add the core libraries, search paths... + // this flags can be augmented through the following properties: + of.pkgConfigs: [] // list of additional system pkgs to include + of.includePaths: [] // include search paths + of.cFlags: [] // flags passed to the c compiler + of.cxxFlags: [] // flags passed to the c++ compiler + of.linkerFlags: [] // flags passed to the linker + of.defines: [] // defines are passed as -D to the compiler + // and can be checked with #ifdef or #if in the code + of.frameworks: [] // osx only, additional frameworks to link with the project + of.staticLibraries: [] // static libraries + of.dynamicLibraries: [] // dynamic libraries + + // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html + // eg: this will enable ccache when compiling + // + // cpp.compilerWrapper: 'ccache' + + Depends{ + name: "cpp" + } + + // common rules that parse the include search paths, core libraries... + Depends{ + name: "of" + } + + // dependency with the OF library + Depends{ + name: "openFrameworks" + } + } + + property bool makeOF: true // use makfiles to compile the OF library + // will compile OF only once for all your projects + // otherwise compiled per project with qbs + + + property bool precompileOfMain: false // precompile ofMain.h + // faster to recompile when including ofMain.h + // but might use a lot of space per project + + references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")] +} diff --git a/example-empty/example-empty.qbs.user b/example-empty/example-empty.qbs.user new file mode 100644 index 0000000..9f7dad7 --- /dev/null +++ b/example-empty/example-empty.qbs.user @@ -0,0 +1,278 @@ + + + + + + EnvironmentId + {e431ad30-ff23-41b5-9d64-7a888d70a36b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 24 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {a59f5d47-09f7-45f4-8f6a-af2e6553b46c} + 0 + 0 + 0 + + 2 + /home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/build-example-empty-Desktop-Debug + + + true + Qbs Build + Qbs.BuildStep + false + + debug + qtc_Desktop_842209c4 + false + + false + true + 48 + false + false + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qbs Clean + Qbs.CleanStep + false + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qbs.QbsBuildConfiguration + Debug_Desktop_038b678e9426a45b + 2 + 2 + + + 2 + /home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/build-example-empty-Desktop-Release + + + true + Qbs Build + Qbs.BuildStep + false + + release + qtc_Desktop_842209c4 + + false + true + 0 + false + false + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qbs Clean + Qbs.CleanStep + false + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qbs.QbsBuildConfiguration + Release_Desktop_9467cca98300890e + 2 + 2 + + 2 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qbs.RunConfiguration:example-empty. + example-empty. + + false + + false + true + true + false + false + true + + /home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/example-empty/bin + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/example-empty/src/main.cpp b/example-empty/src/main.cpp new file mode 100644 index 0000000..da14d4d --- /dev/null +++ b/example-empty/src/main.cpp @@ -0,0 +1,11 @@ +#include "ofApp.h" + +int main(){ + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + + ofSetupOpenGL(1024, 768, OF_WINDOW); + + ofRunApp(new ofApp()); +} diff --git a/example-empty/src/ofApp.cpp b/example-empty/src/ofApp.cpp new file mode 100644 index 0000000..c45fa27 --- /dev/null +++ b/example-empty/src/ofApp.cpp @@ -0,0 +1,62 @@ +#include "ofApp.h" + + +//-------------------------------------------------------------- +void ofApp::setup(){ + +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/example-empty/src/ofApp.h b/example-empty/src/ofApp.h new file mode 100644 index 0000000..91a3c65 --- /dev/null +++ b/example-empty/src/ofApp.h @@ -0,0 +1,25 @@ +#pragma once + +#define HZ_PROFILE 1 + +#include "ofMain.h" +#include "ofxProfiler.h" + + +class ofApp: public ofBaseApp{ + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + +}; diff --git a/example-slowFastRendering/Makefile b/example-slowFastRendering/Makefile new file mode 100644 index 0000000..177e172 --- /dev/null +++ b/example-slowFastRendering/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=$(realpath ../../..) +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/example-slowFastRendering/addons.make b/example-slowFastRendering/addons.make new file mode 100644 index 0000000..e4f38ae --- /dev/null +++ b/example-slowFastRendering/addons.make @@ -0,0 +1 @@ +ofxProfiler diff --git a/example-slowFastRendering/bin/data/.gitkeep b/example-slowFastRendering/bin/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/example-slowFastRendering/config.make b/example-slowFastRendering/config.make new file mode 100644 index 0000000..836fce7 --- /dev/null +++ b/example-slowFastRendering/config.make @@ -0,0 +1,141 @@ +################################################################################ +# CONFIGURE PROJECT MAKEFILE (optional) +# This file is where we make project specific configurations. +################################################################################ + +################################################################################ +# OF ROOT +# The location of your root openFrameworks installation +# (default) OF_ROOT = ../../.. +################################################################################ +# OF_ROOT = ../../.. + +################################################################################ +# PROJECT ROOT +# The location of the project - a starting place for searching for files +# (default) PROJECT_ROOT = . (this directory) +# +################################################################################ +# PROJECT_ROOT = . + +################################################################################ +# PROJECT SPECIFIC CHECKS +# This is a project defined section to create internal makefile flags to +# conditionally enable or disable the addition of various features within +# this makefile. For instance, if you want to make changes based on whether +# GTK is installed, one might test that here and create a variable to check. +################################################################################ +# None + +################################################################################ +# PROJECT EXTERNAL SOURCE PATHS +# These are fully qualified paths that are not within the PROJECT_ROOT folder. +# Like source folders in the PROJECT_ROOT, these paths are subject to +# exlclusion via the PROJECT_EXLCUSIONS list. +# +# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXTERNAL_SOURCE_PATHS = + +################################################################################ +# PROJECT EXCLUSIONS +# These makefiles assume that all folders in your current project directory +# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations +# to look for source code. The any folders or files that match any of the +# items in the PROJECT_EXCLUSIONS list below will be ignored. +# +# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete +# string unless teh user adds a wildcard (%) operator to match subdirectories. +# GNU make only allows one wildcard for matching. The second wildcard (%) is +# treated literally. +# +# (default) PROJECT_EXCLUSIONS = (blank) +# +# Will automatically exclude the following: +# +# $(PROJECT_ROOT)/bin% +# $(PROJECT_ROOT)/obj% +# $(PROJECT_ROOT)/%.xcodeproj +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXCLUSIONS = + +################################################################################ +# PROJECT LINKER FLAGS +# These flags will be sent to the linker when compiling the executable. +# +# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs +# +# Note: Leave a leading space when adding list items with the += operator +# +# Currently, shared libraries that are needed are copied to the +# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to +# add a runtime path to search for those shared libraries, since they aren't +# incorporated directly into the final executable application binary. +################################################################################ +# PROJECT_LDFLAGS=-Wl,-rpath=./libs + +################################################################################ +# PROJECT DEFINES +# Create a space-delimited list of DEFINES. The list will be converted into +# CFLAGS with the "-D" flag later in the makefile. +# +# (default) PROJECT_DEFINES = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_DEFINES = + +################################################################################ +# PROJECT CFLAGS +# This is a list of fully qualified CFLAGS required when compiling for this +# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS +# defined in your platform specific core configuration files. These flags are +# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. +# +# (default) PROJECT_CFLAGS = (blank) +# +# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in +# your platform specific configuration file will be applied by default and +# further flags here may not be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CFLAGS = + +################################################################################ +# PROJECT OPTIMIZATION CFLAGS +# These are lists of CFLAGS that are target-specific. While any flags could +# be conditionally added, they are usually limited to optimization flags. +# These flags are added BEFORE the PROJECT_CFLAGS. +# +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) +# +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) +# +# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the +# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration +# file will be applied by default and further optimization flags here may not +# be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE = +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG = + +################################################################################ +# PROJECT COMPILERS +# Custom compilers can be set for CC and CXX +# (default) PROJECT_CXX = (blank) +# (default) PROJECT_CC = (blank) +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CXX = +# PROJECT_CC = diff --git a/example-slowFastRendering/example-slowFastRendering.qbs b/example-slowFastRendering/example-slowFastRendering.qbs new file mode 100644 index 0000000..1ff9af2 --- /dev/null +++ b/example-slowFastRendering/example-slowFastRendering.qbs @@ -0,0 +1,68 @@ +import qbs +import qbs.Process +import qbs.File +import qbs.FileInfo +import qbs.TextFile +import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp + +Project{ + property string of_root: "../../.." + + ofApp { + name: { return FileInfo.baseName(sourceDirectory) } + + files: [ + 'src/main.cpp', + 'src/ofApp.cpp', + 'src/ofApp.h', + ] + + of.addons: [ + 'ofxProfiler', + ] + + // additional flags for the project. the of module sets some + // flags by default to add the core libraries, search paths... + // this flags can be augmented through the following properties: + of.pkgConfigs: [] // list of additional system pkgs to include + of.includePaths: [] // include search paths + of.cFlags: [] // flags passed to the c compiler + of.cxxFlags: [] // flags passed to the c++ compiler + of.linkerFlags: [] // flags passed to the linker + of.defines: [] // defines are passed as -D to the compiler + // and can be checked with #ifdef or #if in the code + of.frameworks: [] // osx only, additional frameworks to link with the project + of.staticLibraries: [] // static libraries + of.dynamicLibraries: [] // dynamic libraries + + // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html + // eg: this will enable ccache when compiling + // + // cpp.compilerWrapper: 'ccache' + + Depends{ + name: "cpp" + } + + // common rules that parse the include search paths, core libraries... + Depends{ + name: "of" + } + + // dependency with the OF library + Depends{ + name: "openFrameworks" + } + } + + property bool makeOF: true // use makfiles to compile the OF library + // will compile OF only once for all your projects + // otherwise compiled per project with qbs + + + property bool precompileOfMain: false // precompile ofMain.h + // faster to recompile when including ofMain.h + // but might use a lot of space per project + + references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")] +} diff --git a/example-slowFastRendering/example-slowFastRendering.qbs.user b/example-slowFastRendering/example-slowFastRendering.qbs.user new file mode 100644 index 0000000..79d9efd --- /dev/null +++ b/example-slowFastRendering/example-slowFastRendering.qbs.user @@ -0,0 +1,278 @@ + + + + + + EnvironmentId + {e431ad30-ff23-41b5-9d64-7a888d70a36b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 24 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {a59f5d47-09f7-45f4-8f6a-af2e6553b46c} + 0 + 0 + 0 + + 2 + /home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/build-example-slowFastRendering-Desktop-Debug + + + true + Qbs Build + Qbs.BuildStep + false + + debug + qtc_Desktop_842209c4 + false + + false + true + 48 + false + false + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qbs Clean + Qbs.CleanStep + false + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qbs.QbsBuildConfiguration + Debug_Desktop_038b678e9426a45b + 2 + 2 + + + 2 + /home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/build-example-slowFastRendering-Desktop-Release + + + true + Qbs Build + Qbs.BuildStep + false + + release + qtc_Desktop_842209c4 + + false + true + 0 + false + false + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qbs Clean + Qbs.CleanStep + false + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qbs.QbsBuildConfiguration + Release_Desktop_9467cca98300890e + 2 + 2 + + 2 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/example-slowFastRendering/src/main.cpp b/example-slowFastRendering/src/main.cpp new file mode 100644 index 0000000..8bce185 --- /dev/null +++ b/example-slowFastRendering/src/main.cpp @@ -0,0 +1,14 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main( ){ + + ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new ofApp()); + +} diff --git a/example-slowFastRendering/src/ofApp.cpp b/example-slowFastRendering/src/ofApp.cpp new file mode 100644 index 0000000..6fa83d8 --- /dev/null +++ b/example-slowFastRendering/src/ofApp.cpp @@ -0,0 +1,182 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup() { + OFX_PROFILER_BEGIN_SESSION("test","result.json"); + OFX_PROFILER_FUNCTION(); + + ofBackgroundHex(0x57554c); + ofSetFrameRate(60); + ofSetVerticalSync(true); + + + // slow = 1 + // faster = 2 + // super fast = 3 + mode = 1; + +} + +//-------------------------------------------------------------- +void ofApp::update() { + OFX_PROFILER_FUNCTION(); + // add points all the time + if(points.size() < 500000) { + for (int i=0; i<30; i++) { + addPoint(ofGetWidth()/2, ofGetHeight()/2); + } + } + + // move all the points around + for (unsigned int i=0; i ofGetWidth()) points[i].x = 1; + if(points[i].x < 0) points[i].x = ofGetWidth()-1; + if(points[i].y > ofGetHeight()) points[i].y = 1; + if(points[i].y < 0) points[i].y = ofGetHeight()-1; + } + +} + +//-------------------------------------------------------------- +void ofApp::draw() { + OFX_PROFILER_FUNCTION(); + + // draw the points the slow way + if(mode == 1) { + OFX_PROFILER_SCOPE("mode 1"); + #ifdef TARGET_OPENGLES + ofSetColor(255); + ofDrawBitmapString("OpenGL immediate mode not available in OpenGL ES. Press 2 or 3.",ofGetWidth() / 2.0f - 300,ofGetHeight() / 2.0f); + #else + ofSetColor(255); + glBegin(GL_POINTS); + for (unsigned int i=0; i points; + vector speeds; + + // in super fast mode we use a vbo + ofVbo vbo; + + // mode switcher + int mode; + + +}; diff --git a/src/ofxProfiler.h b/src/ofxProfiler.h new file mode 100644 index 0000000..ce41fc6 --- /dev/null +++ b/src/ofxProfiler.h @@ -0,0 +1,190 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include "ofMain.h" + +// this is coming from: https://github.com/TheCherno/Hazel + +namespace ofxProfiler { + + using FloatingPointMicroseconds = chrono::duration; + + struct ProfileResult + { + string Name; + + FloatingPointMicroseconds Start; + chrono::microseconds ElapsedTime; + thread::id ThreadID; + }; + + struct InstrumentationSession + { + string Name; + }; + + class Instrumentor + { + private: + mutex m_Mutex; + InstrumentationSession* m_CurrentSession; + ofstream m_OutputStream; + public: + Instrumentor() + : m_CurrentSession(nullptr) + { + } + + void BeginSession(const string& name, const string& filepath = "results.json") + { + lock_guard lock(m_Mutex); + if (m_CurrentSession) { + // If there is already a current session, then close it before beginning new one. + // Subsequent profiling output meant for the original session will end up in the + // newly opened session instead. That's better than having badly formatted + // profiling output. + ofLog(OF_LOG_ERROR,"Instrumentor::BeginSession('%s') when session '%s' already open.", name.c_str(), m_CurrentSession->Name.c_str()); + InternalEndSession(); + } + m_OutputStream.open(filepath); + + if (m_OutputStream.is_open()) { + m_CurrentSession = new InstrumentationSession({name}); + WriteHeader(); + } else { + ofLog(OF_LOG_ERROR,"Instrumentor could not open results file '%s'.", filepath.c_str()); + } + } + + void EndSession() + { + lock_guard lock(m_Mutex); + InternalEndSession(); + } + + void WriteProfile(const ProfileResult& result) + { + stringstream json; + + string name = result.Name; + replace(name.begin(), name.end(), '"', '\''); + + json << setprecision(3) << fixed; + json << ",{"; + json << "\"cat\":\"function\","; + json << "\"dur\":" << (result.ElapsedTime.count()) << ','; + json << "\"name\":\"" << name << "\","; + json << "\"ph\":\"X\","; + json << "\"pid\":0,"; + json << "\"tid\":" << result.ThreadID << ","; + json << "\"ts\":" << result.Start.count(); + json << "}"; + + lock_guard lock(m_Mutex); + if (m_CurrentSession) { + m_OutputStream << json.str(); + m_OutputStream.flush(); + } + } + + static Instrumentor& Get() { + static Instrumentor instance; + return instance; + } + + private: + void WriteHeader() + { + m_OutputStream << "{\"otherData\": {},\"traceEvents\":[{}"; + m_OutputStream.flush(); + } + + void WriteFooter() + { + m_OutputStream << "]}"; + m_OutputStream.flush(); + } + + // Note: you must already own lock on m_Mutex before + // calling InternalEndSession() + void InternalEndSession() { + if (m_CurrentSession) { + WriteFooter(); + m_OutputStream.close(); + delete m_CurrentSession; + m_CurrentSession = nullptr; + } + } + + }; + + class InstrumentationTimer + { + public: + InstrumentationTimer(const char* name) + : m_Name(name), m_Stopped(false) + { + m_StartTimepoint = chrono::steady_clock::now(); + } + + ~InstrumentationTimer() + { + if (!m_Stopped) + Stop(); + } + + void Stop() + { + auto endTimepoint = chrono::steady_clock::now(); + auto highResStart = FloatingPointMicroseconds{ m_StartTimepoint.time_since_epoch() }; + auto elapsedTime = chrono::time_point_cast(endTimepoint).time_since_epoch() - chrono::time_point_cast(m_StartTimepoint).time_since_epoch(); + + Instrumentor::Get().WriteProfile({ m_Name, highResStart, elapsedTime, this_thread::get_id() }); + + m_Stopped = true; + } + private: + const char* m_Name; + chrono::time_point m_StartTimepoint; + bool m_Stopped; + }; +} + +//#define OFX_PROFILER 0 +#if OFX_PROFILER + // Resolve which function signature macro will be used. Note that this only + // is resolved when the (pre)compiler starts, so the syntax highlighting + // could mark the wrong one in your editor! + #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) + #define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__ + #elif defined(__DMC__) && (__DMC__ >= 0x810) + #define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__ + #elif defined(__FUNCSIG__) + #define OFX_PROFILER_FUNC_SIG __FUNCSIG__ + #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) + #define OFX_PROFILER_FUNC_SIG __FUNCTION__ + #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) + #define OFX_PROFILER_FUNC_SIG __FUNC__ + #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) + #define OFX_PROFILER_FUNC_SIG __func__ + #elif defined(__cplusplus) && (__cplusplus >= 201103) + #define OFX_PROFILER_FUNC_SIG __func__ + #else + #define OFX_PROFILER_FUNC_SIG "OFX_PROFILER_FUNC_SIG unknown!" + #endif + + #define OFX_PROFILER_BEGIN_SESSION(name, filepath) ::ofxProfiler::Instrumentor::Get().BeginSession(name, filepath) + #define OFX_PROFILER_END_SESSION() ::ofxProfiler::Instrumentor::Get().EndSession() + #define OFX_PROFILER_SCOPE(name) ::ofxProfiler::InstrumentationTimer timer##__LINE__(name); + #define OFX_PROFILER_FUNCTION() OFX_PROFILER_SCOPE(OFX_PROFILER_FUNC_SIG) +#else + #define OFX_PROFILER_BEGIN_SESSION(name, filepath) + #define OFX_PROFILER_END_SESSION() + #define OFX_PROFILER_SCOPE(name) + #define OFX_PROFILER_FUNCTION() +#endif