Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coz: Causal profiler #3282

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 33 additions & 0 deletions recipes/coz/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.1)
project(coz CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Threads REQUIRED)

file(GLOB_RECURSE sources source_subfolder/libcoz/*.cpp)
file(GLOB_RECURSE headers source_subfolder/include/*.h)

add_library(${PROJECT_NAME} SHARED ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES
PUBLIC_HEADER "${headers}"
VERSION ${CONAN_PACKAGE_VERSION})
target_include_directories(${PROJECT_NAME}
PUBLIC source_subfolder/libcoz
PRIVATE source_subfolder/include)
target_link_libraries(${PROJECT_NAME} PUBLIC dl rt Threads::Threads elf++ dwarf++)

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME})

install(PROGRAMS source_subfolder/coz DESTINATION bin)
install(FILES source_subfolder/LICENSE.md DESTINATION licenses)
8 changes: 8 additions & 0 deletions recipes/coz/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"0.2.2":
url: "https://github.com/plasma-umass/coz/archive/0.2.2.tar.gz"
sha256: "5e671c5b7e2920e295d2da793e5eb4d60b36889fd86c9dc40cacfe0d3ec24d0f"
patches:
"0.2.2":
- patch_file: "patches/gettid.patch"
base_path: "source_subfolder"
59 changes: 59 additions & 0 deletions recipes/coz/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration


class CozConan(ConanFile):
name = "coz"
description = "Causal profiler, uses performance experiments to predict the effect of optimizations"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://coz-profiler.org"
license = "BSD-2-Clause"
topics = ("conan", "coz", "profiler", "causal")

settings = "os", "arch", "compiler", "build_type"

requires = "libelfin/0.3"
exports_sources = "CMakeLists.txt", "patches/*"
generators = "cmake"

_source_subfolder = "source_subfolder"
_cmake = None

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("libelfin doesn't support compiler: {} on OS: {}.".
format(self.settings.compiler, self.settings.os))
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "Coz"
if self.settings.os != "Windows":
self.cpp_info.system_libs = ["-Wl,--push-state,--no-as-needed", "-ldl", "-Wl,--pop-state"]
26 changes: 26 additions & 0 deletions recipes/coz/all/patches/gettid.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
commit 040144656146014d1ae356f73af96fefda1a3090
Author: pmcgleenon <pmcgleenon@users.noreply.github.com>
Date: Fri Oct 9 12:42:55 2020 +0100

Fixed issue with gettid() not available with glibc < 2.30.

In that case use the syscall interface directly

https://stackoverflow.com/questions/30680550/c-gettid-was-not-declared-in-this-scope

diff --git a/libcoz/perf.h b/libcoz/perf.h
index 88f26cf..4ad60f8 100644
--- a/libcoz/perf.h
+++ b/libcoz/perf.h
@@ -18,6 +18,11 @@
#include "ccutil/log.h"
#include "ccutil/wrapped_array.h"

+#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
+#include <sys/syscall.h>
+#define gettid() syscall(SYS_gettid)
+#endif
+
// Workaround for missing hw_breakpoint.h include file:
// This include file just defines constants used to configure watchpoint registers.
// This will be constant across x86 systems.
8 changes: 8 additions & 0 deletions recipes/coz/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
19 changes: 19 additions & 0 deletions recipes/coz/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if tools.cross_building(self.settings):
return
bin_path = os.path.join("bin", "test_package")
self.run("coz run --- " + bin_path, run_environment=True)
print(open("profile.coz").read())
11 changes: 11 additions & 0 deletions recipes/coz/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <coz/coz.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
COZ_PROGRESS_NAMED("something");
printf("Hello, Coz!\n");

return 0;
}
3 changes: 3 additions & 0 deletions recipes/coz/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.2.2":
folder: "all"
76 changes: 76 additions & 0 deletions recipes/libelfin/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.1)
project(libelfin CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(PythonInterp 3 REQUIRED)

file(GLOB_RECURSE elf_sources source_subfolder/elf/*.cc)
set(elf_headers
source_subfolder/elf/common.hh
source_subfolder/elf/data.hh
source_subfolder/elf/elf++.hh)
file(GLOB_RECURSE dwarf_sources source_subfolder/dwarf/*.cc)
set(dwarf_headers
source_subfolder/dwarf/data.hh
source_subfolder/dwarf/dwarf++.hh
source_subfolder/dwarf/small_vector.hh)

add_custom_command(
OUTPUT source_subfolder/elf/to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '// Automatically generated' > to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '// DO NOT EDIT' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '\#include \"data.hh\"' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '\#include \"to_hex.hh\"' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo 'ELFPP_BEGIN_NAMESPACE' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${PYTHON_EXECUTABLE} enum-print.py -u --hex --no-type --mask shf --mask pf -x loos -x hios -x loproc -x hiproc < data.hh >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo 'ELFPP_END_NAMESPACE' >> to_string.cc
DEPENDS source_subfolder/elf/enum-print.py source_subfolder/elf/data.hh
WORKING_DIRECTORY source_subfolder/elf)

add_custom_command(
OUTPUT source_subfolder/dwarf/to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '// Automatically generated' > to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '// DO NOT EDIT' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo '\#include \"internal.hh\"' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo 'DWARFPP_BEGIN_NAMESPACE' >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc
COMMAND ${PYTHON_EXECUTABLE} ../elf/enum-print.py < dwarf++.hh >> to_string.cc
COMMAND ${PYTHON_EXECUTABLE} ../elf/enum-print.py -s _ -u --hex -x hi_user -x lo_user < data.hh >> to_string.cc
COMMAND ${CMAKE_COMMAND} -E echo 'DWARFPP_END_NAMESPACE' >> to_string.cc
DEPENDS source_subfolder/elf/enum-print.py source_subfolder/dwarf/data.hh
WORKING_DIRECTORY source_subfolder/dwarf)

add_library(elf++ ${elf_sources} source_subfolder/elf/to_string.cc)
set_target_properties(elf++ PROPERTIES
PUBLIC_HEADER "${elf_headers}"
VERSION ${CONAN_PACKAGE_VERSION})

add_library(dwarf++ ${dwarf_sources} source_subfolder/dwarf/to_string.cc)
set_target_properties(dwarf++ PROPERTIES
PUBLIC_HEADER "${dwarf_headers}"
VERSION ${CONAN_PACKAGE_VERSION})

install(TARGETS elf++
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/libelfin/elf)
install(TARGETS dwarf++
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/libelfin/dwarf)

install(FILES source_subfolder/LICENSE DESTINATION licenses)
8 changes: 8 additions & 0 deletions recipes/libelfin/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"0.3":
url: "https://github.com/aclements/libelfin/archive/v0.3.tar.gz"
sha256: "c338942b967582922b3514b54b93175ca9051a9668db92dd8ef619824d443ac7"
patches:
"0.3":
- patch_file: "patches/946dde57e5caef8297b9339f3a7971401d540840.patch"
base_path: "source_subfolder"
64 changes: 64 additions & 0 deletions recipes/libelfin/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration


class LibelfinConan(ConanFile):
name = "libelfin"
description = "C++11 library for reading ELF binaries and DWARFv4 debug information"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/aclements/libelfin"
license = "MIT"
topics = ("conan", "elf", "dwarf", "libelfin")

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

exports_sources = "CMakeLists.txt", "patches/*"
generators = "cmake"

_source_subfolder = "source_subfolder"
_cmake = None

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("libelfin doesn't support compiler: {} on OS: {}.".
format(self.settings.compiler, self.settings.os))
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.components["libelf++"].names["pkg_config"] = "libelf++"
self.cpp_info.components["libelf++"].libs = ["elf++"]
self.cpp_info.components["libdwarf++"].names["pkg_config"] = "libdwarf++"
self.cpp_info.components["libdwarf++"].libs = ["dwarf++"]
self.cpp_info.components["libdwarf++"].requires = ["libelf++"]
Loading