Skip to content

Commit

Permalink
A few tweaks and Qt5 package fix, adding JS Profiler::BeginBlock supp…
Browse files Browse the repository at this point in the history
…ort and TypeScript decl
  • Loading branch information
JoshEngebretson committed Jun 28, 2017
1 parent ac8bc4a commit d826df8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Script/Packages/Atomic/Core.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"subscribeToEvent(sender:AObject, eventType:string, callback:(data: any) => void);",
"subscribeToEvent(eventMetaData:Atomic.EventMetaData);",
"subscribeToEvent(sender:AObject, eventMetaData:Atomic.EventMetaData);"
],
"Profiler" : [
"beginBlock(name:string, filename:string, line:number, argb?:number, status?:Atomic.ProfilerBlockStatus );"
]
},
"haxe_decl" : {
Expand Down
4 changes: 2 additions & 2 deletions Source/Atomic/Core/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool Profiler::GetEventProfilingEnabled() const
return enableEventProfiling_;
}

void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned int color, unsigned char status)
void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned int argb, unsigned char status)
{
#if ATOMIC_PROFILING
// Line used as starting hash value for efficiency.
Expand All @@ -142,7 +142,7 @@ void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned
{
String uniqueName = ToString("%s:%d", file, line);
desc = ::profiler::registerDescription((::profiler::EasyBlockStatus)status, uniqueName.CString(), name, file,
line, ::profiler::BLOCK_TYPE_BLOCK, color, true);
line, ::profiler::BLOCK_TYPE_BLOCK, argb, true);
}
else
desc = it->second_;
Expand Down
52 changes: 52 additions & 0 deletions Source/AtomicJS/Javascript/JSCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

#include <Atomic/Core/ProcessUtils.h>
#include <Atomic/Core/Profiler.h>

#include "JSCore.h"
#include "JSEventHelper.h"
Expand Down Expand Up @@ -224,6 +225,51 @@ static int Atomic_GetArguments(duk_context* ctx)

}

static int Profiler_BeginBlock(duk_context* ctx)
{

#if ATOMIC_PROFILING
// Get the Profiler instance
duk_push_this(ctx);
Profiler* profiler = js_to_class_instance<Profiler>(ctx, -1, 0);
duk_pop(ctx);

// early out, this should never happen
if (!profiler)
{
return 0;
}

// get the number of args
duk_idx_t top = duk_get_top(ctx);

// we need at least 3
if ( top < 3)
{
return 0;
}

// parse args
const char* name = duk_require_string(ctx, 0);
const char* filename = duk_require_string(ctx, 1);
int line = duk_require_number(ctx, 2);
unsigned argb = (top > 3) ? (unsigned) duk_require_number(ctx, 3) : PROFILER_COLOR_DEFAULT;
unsigned char status = (top > 4) ? (unsigned) duk_require_number(ctx, 4) : ProfilerBlockStatus::ON;

profiler->BeginBlock(name, filename, line, argb, status);

#else
static bool warned = false;
if (!warned)
{
warned = true;
ATOMIC_LOGWARNING("Engine is built without profiler support.");
}
#endif

return 0;
}

void jsapi_init_core(JSVM* vm)
{
duk_context* ctx = vm->GetJSContext();
Expand All @@ -241,6 +287,12 @@ void jsapi_init_core(JSVM* vm)
duk_push_c_function(ctx, Object_SendEvent, DUK_VARARGS);
duk_put_prop_string(ctx, -2, "sendEvent");
duk_pop(ctx); // pop AObject prototype

js_class_get_prototype(ctx, "Atomic", "Profiler");
duk_push_c_function(ctx, Profiler_BeginBlock, DUK_VARARGS);
duk_put_prop_string(ctx, -2, "beginBlock");
duk_pop(ctx); // pop Profiler prototype

}

}
11 changes: 10 additions & 1 deletion Source/ThirdParty/easy_profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set(EASY_PROGRAM_VERSION_PATCH 0)
set(EASY_PRODUCT_VERSION_STRING "${EASY_PROGRAM_VERSION_MAJOR}.${EASY_PROGRAM_VERSION_MINOR}.${EASY_PROGRAM_VERSION_PATCH}")

# ATOMIC BEGIN

find_package(Qt5Widgets)

set(EASY_OPTION_LIB_STATIC ON CACHE BOOL "" FORCE)
set(EASY_OPTION_PREDEFINED_COLORS ON CACHE BOOL "" FORCE)
set(EASY_PROFILER_NO_SAMPLES ON CACHE BOOL "" FORCE)
Expand All @@ -30,7 +33,13 @@ macro(easy_define_target_option TARGET SOURCE_OPTION TARGET_DEFINITION)
endmacro()

add_subdirectory(easy_profiler_core)
add_subdirectory(profiler_gui)

# ATOMIC BEGIN
# Only include the Qt client if on we're building desktop platform and Qt5 was found on system
if (ATOMIC_DESKTOP AND Qt5Widgets_FOUND)
add_subdirectory(profiler_gui)
endif()
#ATOMIC END

if (NOT EASY_PROFILER_NO_SAMPLES)
add_subdirectory(sample)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ install(
)
endif ()

if (MSVC)
# If we're on MSVC, we need a /MD version of the easy profiler library to link with Qt
if (MSVC AND Qt5Widgets_FOUND)
add_library(easy_profiler_md ${EASY_OPTION_LIB_TYPE} ${SOURCES} resources.rc)
foreach(prop COMPILE_DEFINITIONS COMPILE_OPTIONS CXX_STANDARD CXX_STANDARD_REQUIRED INCLUDE_DIRECTORIES INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES)
get_target_property(val easy_profiler ${prop})
Expand Down
7 changes: 5 additions & 2 deletions Source/ThirdParty/easy_profiler/profiler_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Widgets)
# ATOMIC BEGIN
# moved to easy profiler root CMake, to avoid duplicate checks
# find_package(Qt5Widgets)
# ATOMIC END

if (NOT Qt5Widgets_FOUND)
if (Qt5Widgets_FOUND)
if (NOT("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WIN32)
set(APPLICATION_PLATFORM WIN32)
endif ()
Expand Down

0 comments on commit d826df8

Please sign in to comment.