Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ jobs:
with:
name: ga-cpp-sdk-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
path: ${{ steps.strings.outputs.build-output-dir }}/package/
retention-days: 3

2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake ..
run: cmake -DENABLE_COVERAGE=ON ..

- name: Build
working-directory: ${{github.workspace}}/build
Expand Down
126 changes: 64 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeInc
include("create_source_groups_macro")
include("eval_condition_macro")

# --------------------------- Options --------------------------- #
option(ENABLE_COVERAGE "Enable code coverage reporting" OFF)
option(GA_SHARED_LIB "Build GA as a shared library" OFF)
option(GA_UWP_BUILD "Build GA for UWP (if targeting windows)" OFF)
option(GA_BUILD_SAMPLE "Builds the GA Sample app" ON)
Expand Down Expand Up @@ -242,87 +244,87 @@ target_link_libraries(${UT_PROJECT_NAME} gtest gtest_main gmock_main)
target_link_libraries(${UT_PROJECT_NAME} ${PROJECT_NAME})

########################################

add_test(NAME ${UT_PROJECT_NAME} COMMAND GameAnalyticsUnitTests)

# --------------------------- Google Test Setup --------------------------- #

find_program(GCOV_PATH gcov)
if (NOT GCOV_PATH)
message(WARNING "program gcov not found")
endif()

find_program(LCOV_PATH lcov)
if (NOT LCOV_PATH)
message(WARNING "program lcov not found")
endif()

find_program(GENHTML_PATH genhtml)
if (NOT GENHTML_PATH)
message(WARNING "program genhtml not found")
endif()

if (LCOV_PATH AND GCOV_PATH)
# --------------------------- Code Coverage Setup --------------------------- #

target_compile_options(
GameAnalytics
PRIVATE
-g -O0 -fprofile-arcs -ftest-coverage
)
if (ENABLE_COVERAGE)
find_program(GCOV_PATH gcov)
if (NOT GCOV_PATH)
message(WARNING "program gcov not found")
endif()

target_link_libraries(
GameAnalytics
PRIVATE
--coverage
)
find_program(LCOV_PATH lcov)
if (NOT LCOV_PATH)
message(WARNING "program lcov not found")
endif()

set(covname cov)
find_program(GENHTML_PATH genhtml)
if (NOT GENHTML_PATH)
message(WARNING "program genhtml not found")
endif()

add_custom_target(cov_data
# Cleanup lcov
COMMENT "Resetting code coverage counters to zero."
${LCOV_PATH} --directory . --zerocounters
if (LCOV_PATH AND GCOV_PATH)

# Run tests
COMMAND GameAnalyticsUnitTests
target_compile_options(
GameAnalytics
PRIVATE
-g -O0 -fprofile-arcs -ftest-coverage
)

# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info
COMMAND ${LCOV_PATH} --remove ${covname}.info
'${CMAKE_SOURCE_DIR}/source/dependencies/*'
'${CMAKE_SOURCE_DIR}/test/*'
'/usr/*'
'/Applications/Xcode.app/*'
--output-file ${covname}.info.cleaned
)
target_link_libraries(
GameAnalytics
PRIVATE
--coverage
)

if (GENHTML_PATH)
add_custom_target(cov
set(covname cov)

add_custom_target(cov_data
# Cleanup lcov
COMMENT "Resetting code coverage counters to zero."
${LCOV_PATH} --directory . --zerocounters

# Run tests
COMMAND GameAnalyticsUnitTests

# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info
COMMAND ${LCOV_PATH} --remove ${covname}.info
'${CMAKE_SOURCE_DIR}/source/dependencies/*'
'/usr/*'
--output-file ${covname}.info.cleaned
--rc lcov_branch_coverage=1
--rc derive_function_end_line=0
COMMAND ${GENHTML_PATH} -o ${covname} ${covname}.info.cleaned --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
COMMAND ${CMAKE_COMMAND} -E remove ${covname}.info ${covname}.info.cleaned

COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
'${CMAKE_SOURCE_DIR}/source/dependencies/*'
'${CMAKE_SOURCE_DIR}/test/*'
'/usr/*'
'/Applications/Xcode.app/*'
--output-file ${covname}.info.cleaned
)

if (GENHTML_PATH)
add_custom_target(cov

# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters

# Run tests
COMMAND GameAnalyticsUnitTests

# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
COMMAND ${LCOV_PATH} --remove ${covname}.info
'${CMAKE_SOURCE_DIR}/source/dependencies/*'
'/usr/*'
--output-file ${covname}.info.cleaned
--rc lcov_branch_coverage=1
--rc derive_function_end_line=0
COMMAND ${GENHTML_PATH} -o ${covname} ${covname}.info.cleaned --rc lcov_branch_coverage=1 --rc derive_function_end_line=0
COMMAND ${CMAKE_COMMAND} -E remove ${covname}.info ${covname}.info.cleaned

COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
else()
message(WARNING "unable to generate coverage report: missing genhtml")
endif()

else()
message(WARNING "unable to generate coverage report: missing genhtml")
message(WARNING "unable to add coverage targets: missing coverage tools")
endif()

else()
message(WARNING "unable to add coverage targets: missing coverage tools")
endif()

54 changes: 24 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,67 @@
def run_command(command, shell=True, cwd=None):
if os.name == 'nt': # Check if the OS is Windows
command = f'powershell.exe -Command "{command}"'
result = subprocess.run(command, shell=shell, check=True, text=True)

result = subprocess.run(command, shell=shell, check=True, text=True, cwd=cwd)
return result

def main():
parser = argparse.ArgumentParser(description="CMake Build and Test Script")
parser.add_argument('--os', required=True, choices=['linux', 'windows', 'macos'], help='Operating System')
parser.add_argument('--build_type', default='Debug', choices=['Release', 'Debug'], help='Build Type')
parser.add_argument('--platform', choices=['linux_x64', 'linux_x86', 'osx', 'win32', 'win64', 'uwp'], help='Platform string for CMake')
parser.add_argument('--platform', required=True, choices=['linux_x64', 'linux_x86', 'osx', 'win32', 'win64', 'uwp'], help='Platform to build for')
parser.add_argument('--cfg', default='Debug', choices=['Release', 'Debug'], help='Configuration Type')
parser.add_argument('--build', action='store_true', help='Execute the build step')
parser.add_argument('--test', action='store_true', help='Execute the test step')
parser.add_argument('--coverage', action='store_true', help='Generate code coverage report')

args = parser.parse_args()

build_output_dir = os.path.join(os.getcwd(), 'build')
os.makedirs(build_output_dir, exist_ok=True)

if args.os == 'windows':
c_compiler = 'cl'
cpp_compiler = 'cl'
elif args.os == 'linux':
c_compiler = 'gcc'
cpp_compiler = 'g++'
elif args.os == 'macos':
c_compiler = 'clang'
cpp_compiler = 'clang++'

# Configure CMake
cmake_command = f'cmake -B {build_output_dir} -DCMAKE_CXX_COMPILER={cpp_compiler} -DCMAKE_C_COMPILER={c_compiler} -DCMAKE_BUILD_TYPE={args.build_type} -S {os.getcwd()}'
if args.os == 'macos':
# Configure
cmake_command = f'cmake -B {build_output_dir} -S {os.getcwd()}'
if args.platform == 'osx':
cmake_command += ' -G "Xcode"'
if args.platform:
cmake_command += f' -DPLATFORM:STRING={args.platform}'
if args.coverage:
cmake_command += ' -DENABLE_COVERAGE=ON'

run_command(cmake_command)

# Build
if args.build:
run_command(f'cmake --build {build_output_dir} --config {args.build_type}')
run_command(f'cmake --build {build_output_dir} --config {args.cfg}')
else:
exit(0)

# Test
if args.test:
run_command(f'ctest --build-config {args.build_type} --verbose --output-on-failure', cwd=build_output_dir)
run_command(f'ctest --build-config {args.cfg} --verbose --output-on-failure', cwd=build_output_dir)
else:
exit(0)

# Code Coverage
if args.coverage:
# Prepare coverage data
run_command(f'cmake --build {build_output_dir} --target cov', cwd=build_output_dir)

# Package Build Artifacts
package_dir = os.path.join(build_output_dir, 'package')
os.makedirs(package_dir, exist_ok=True)
files_to_copy = glob.glob(f'{build_output_dir}/{args.build_type}/*GameAnalytics.*')
files_to_copy = glob.glob(f'{build_output_dir}/{args.cfg}/*GameAnalytics.*')
for file in files_to_copy:
shutil.copy(file, package_dir)
shutil.copytree(os.path.join(os.getcwd(), 'include'), os.path.join(package_dir, 'include'), dirs_exist_ok=True)

# Print Package Contents
if args.os == 'windows':
if args.platform.startswith('win'):
run_command(f'dir {package_dir}', shell=True)
else:
run_command(f'ls -la {package_dir}', shell=True)

# Print architecture information
#use lipo on macos and linux and dumpbin on windows
if args.os == 'macos':
if args.platform == 'osx':
run_command(f'lipo -info {package_dir}/*GameAnalytics.*')
elif args.os == 'linux':
run_command(f'file {package_dir}/*GameAnalytics.*')
elif args.os == 'windows':
run_command(f'dumpbin /headers {package_dir}/GameAnalytics.lib | findstr machine')


if __name__ == "__main__":
main()
main()
13 changes: 6 additions & 7 deletions source/gameanalytics/GAHealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ namespace gameanalytics

int GAHealth::getMemoryPercent(int64_t memory)
{
if((memory > 0) && (_totalMemory > 0))
{
int memoryPercent = std::round(static_cast<double>(memory) / static_cast<double>(_totalMemory) * 100.0);
return std::min(memoryPercent, 100);
}

return 0;
if((memory > 0) && (_totalMemory > 0))
{
int memoryPercent = std::round(static_cast<double>(memory) / static_cast<double>(_totalMemory) * 100.0);
return memoryPercent;
}

return -1;
}

void GAHealth::doAppMemoryReading(int64_t memory)
Expand Down
Loading