├── .gitignore ├── .travis.yml ├── Jenkinsfile ├── LICENSE ├── README.md ├── debian ├── .gitignore ├── changelog ├── compat ├── control ├── copyright ├── docs ├── rules ├── source │ └── format ├── tarantool-gperftools.install └── tarantool-gperftools.substvars ├── gperftools ├── cpu.lua └── init.lua ├── rockspecs ├── gperftools-1.0.1-1.rockspec └── gperftools-scm-1.rockspec ├── rpm └── tarantool-gperftools.spec └── test └── gperftools.test.lua /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeFiles/ 2 | CMakeCache.txt 3 | Makefile 4 | cmake_*.cmake 5 | install_manifest.txt 6 | *.a 7 | *.cbp 8 | *.d 9 | *.dylib 10 | *.gcno 11 | *.gcda 12 | *.user 13 | *.o 14 | *.reject 15 | *.so 16 | *.log 17 | *.snap* 18 | *.xlog* 19 | *~ 20 | .gdb_history 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: C 3 | services: 4 | - docker 5 | 6 | cache: 7 | directories: 8 | - $HOME/.cache 9 | 10 | env: 11 | global: 12 | - PRODUCT=tarantool-gperftools 13 | matrix: 14 | - OS=el DIST=6 15 | - OS=el DIST=7 16 | - OS=fedora DIST=24 17 | - OS=fedora DIST=25 18 | - OS=ubuntu DIST=precise 19 | - OS=ubuntu DIST=trusty 20 | - OS=ubuntu DIST=xenial 21 | - OS=ubuntu DIST=yakkety 22 | - OS=debian DIST=wheezy 23 | - OS=debian DIST=jessie 24 | - OS=debian DIST=stretch 25 | 26 | #matrix: 27 | # allow_failures: 28 | # - env: OS=el DIST=6 29 | # - env: OS=el DIST=7 30 | # - env: OS=fedora DIST=23 31 | # - env: OS=fedora DIST=24 32 | # - env: OS=fedora DIST=25 33 | # - env: OS=ubuntu DIST=precise 34 | # - env: OS=ubuntu DIST=trusty 35 | # - env: OS=ubuntu DIST=xenial 36 | # - env: OS=ubuntu DIST=yakkety 37 | # - env: OS=debian DIST=wheezy 38 | # - env: OS=debian DIST=jessie 39 | # - env: OS=debian DIST=stretch 40 | 41 | script: 42 | - git describe --long 43 | - git clone https://github.com/packpack/packpack.git packpack 44 | - packpack/packpack 45 | 46 | before_deploy: 47 | - ls -l build/ 48 | 49 | deploy: 50 | # Deploy packages to PackageCloud 51 | - provider: packagecloud 52 | username: tarantool 53 | repository: "1_6" 54 | token: ${PACKAGECLOUD_TOKEN} 55 | dist: ${OS}/${DIST} 56 | package_glob: build/*.{deb,rpm} 57 | skip_cleanup: true 58 | on: 59 | branch: master 60 | condition: -n "${OS}" && -n "${DIST}" && -n "${PACKAGECLOUD_TOKEN}" 61 | - provider: packagecloud 62 | username: tarantool 63 | repository: "1_7" 64 | token: ${PACKAGECLOUD_TOKEN} 65 | dist: ${OS}/${DIST} 66 | package_glob: build/*.{deb,rpm} 67 | skip_cleanup: true 68 | on: 69 | branch: master 70 | condition: -n "${OS}" && -n "${DIST}" && -n "${PACKAGECLOUD_TOKEN}" 71 | - provider: packagecloud 72 | username: tarantool 73 | repository: "1_8" 74 | token: ${PACKAGECLOUD_TOKEN} 75 | dist: ${OS}/${DIST} 76 | package_glob: build/*.{deb,rpm} 77 | skip_cleanup: true 78 | on: 79 | branch: master 80 | condition: -n "${OS}" && -n "${DIST}" && -n "${PACKAGECLOUD_TOKEN}" 81 | 82 | notifications: 83 | email: 84 | recipients: 85 | - build@tarantool.org 86 | on_success: change 87 | on_failure: always 88 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | stage('Build'){ 2 | packpack = new org.tarantool.packpack() 3 | node { 4 | checkout scm 5 | packpack.prepareSources() 6 | } 7 | packpack.packpackBuildMatrix('result') 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010-2013 Tarantool AUTHORS: 2 | please see AUTHORS file in tarantool/tarantool repository. 3 | 4 | /* 5 | * Redistribution and use in source and binary forms, with or 6 | * without modification, are permitted provided that the following 7 | * conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above 10 | * copyright notice, this list of conditions and the 11 | * following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials 16 | * provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY AUTHORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | * AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 26 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 29 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gperftools - Lua bindings for Google Performance Tools CPU Profiler 2 | [![Build Status](https://travis-ci.org/tarantool/gperftools.png?branch=master)](https://travis-ci.org/tarantool/gperftools) 3 | 4 | ## Getting Started 5 | 6 | ### Prerequisites 7 | 8 | * Tarantool 1.5+ or LuaJIT 2.0+ 9 | * libprofiler.so from gperftools package 10 | - apt-get install libgoogle-perftools4 # Debian/Ubuntu, main repository 11 | - yum install gperftools-libs # RHEL/CentOS/Fedora, EPEL repository 12 | 13 | ### Installation 14 | 15 | Use package for your distribution from http://tarantool.org/ repository. 16 | You can also use LuaRocks: 17 | 18 | ``` bash 19 | luarocks install https://raw.githubusercontent.com/tarantool/gperftools/master/gperftools-scm-1.rockspec --local 20 | ``` 21 | 22 | See [tarantool/rocks][TarantoolRocks] for LuaRocks configuration details. 23 | 24 | ### Usage 25 | 26 | Start profiler: 27 | 28 | tarantool> cpuprof = require('gperftools.cpu') 29 | tarantool> cpuprof.start('/home/roman/tarantool-on-production.prof') 30 | 31 | Wait some time to get performance metricrs to be collected 32 | (at least couple minutes). 33 | 34 | Flush actual results to disk (you can do that multiple times): 35 | 36 | tarantool> cpuprof.flush() 37 | 38 | Analize the output (see [documentation][gperftools]): 39 | 40 | pprof --text /usr/bin/tarantool /home/roman/tarantool-on-production.prof 41 | 42 | Stop profiling when you don’t need it anymore: 43 | 44 | tarantool> cpuprof.stop() 45 | 46 | ## See Also 47 | 48 | * [CPU Profiler Documentation][gperftools] 49 | * [Tarantool][] 50 | * [Tarantool Rocks][TarantoolRocks] 51 | 52 | [gperftools]: https://gperftools.github.io/gperftools/cpuprofile.html 53 | [Tarantool]: http://github.com/tarantool/tarantool 54 | [TarantoolRocks]: https://github.com/tarantool/rocks 55 | -------------------------------------------------------------------------------- /debian/.gitignore: -------------------------------------------------------------------------------- 1 | tarantool-gperftools/ 2 | files 3 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | tarantool-gperftools (1.0.0-1) unstable; urgency=low 2 | 3 | * Initial release 4 | 5 | -- Roman Tsisyk Wed, 17 Jun 2015 15:57:50 +0300 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: tarantool-gperftools 2 | Priority: optional 3 | Section: database 4 | Maintainer: Roman Tsisyk 5 | Build-Depends: debhelper (>= 9), 6 | tarantool (>= 1.6.8.0), 7 | libgoogle-perftools-dev 8 | Standards-Version: 3.9.6 9 | Homepage: https://github.com/tarantool/gperftools 10 | Vcs-Git: git://github.com/tarantool/gperftools.git 11 | Vcs-Browser: https://github.com/tarantool/gperftools 12 | 13 | Package: tarantool-gperftools 14 | Architecture: all 15 | Depends: tarantool (>= 1.6.8.0), libgoogle-perftools-dev, ${misc:Depends} 16 | Description: Lua bindings for gperftools CPU profiler 17 | Lua bindings for Google Performance Tools CPU Profiler. 18 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Debianized-By: Roman Tsisyk 3 | Upstream-Name: tarantool-gperftools 4 | Upstream-Contact: roman@tarantool.org 5 | Source: https://github.com/tarantool/tarantool-gperftools 6 | 7 | Files: * 8 | Copyright: 2015 by Roman Tsisyk 9 | License: BSD-2-Clause 10 | Redistribution and use in source and binary forms, with or 11 | without modification, are permitted provided that the following 12 | conditions are met: 13 | . 14 | 1. Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | . 18 | 2. Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the following 20 | disclaimer in the documentation and/or other materials 21 | provided with the distribution. 22 | . 23 | THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 28 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | SUCH DAMAGE. 36 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ 5 | 6 | override_dh_auto_test: 7 | prove -v ./test/gperftools.test.lua 8 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/tarantool-gperftools.install: -------------------------------------------------------------------------------- 1 | gperftools/init.lua usr/share/tarantool/gperftools/ 2 | gperftools/cpu.lua usr/share/tarantool/gperftools/ 3 | -------------------------------------------------------------------------------- /debian/tarantool-gperftools.substvars: -------------------------------------------------------------------------------- 1 | misc:Depends= 2 | -------------------------------------------------------------------------------- /gperftools/cpu.lua: -------------------------------------------------------------------------------- 1 | -- gperftools.cpu 2 | 3 | local ffi = require('ffi') 4 | 5 | local status, profiler = pcall(ffi.load, 'profiler') 6 | if not status then 7 | error('Failed to load libprofiler. Please install gperftools!') 8 | end 9 | 10 | ffi.cdef[[ 11 | int ProfilerStart(const char* fname); 12 | void ProfilerStop(); 13 | void ProfilerFlush(); 14 | ]] 15 | 16 | local function start(filename) 17 | if filename == nil then 18 | error("Usage: cpu.start(filename)") 19 | end 20 | if profiler.ProfilerStart(filename) ~= 0 then 21 | return true 22 | else 23 | return nil 24 | end 25 | end 26 | 27 | local function stop() 28 | profiler.ProfilerStop() 29 | end 30 | 31 | local function flush() 32 | profiler.ProfilerFlush() 33 | end 34 | 35 | return { 36 | start = start; 37 | stop = stop; 38 | flush = flush; 39 | } 40 | -------------------------------------------------------------------------------- /gperftools/init.lua: -------------------------------------------------------------------------------- 1 | local cpu = require('gperftools.cpu') 2 | return { 3 | cpu = cpu; 4 | } 5 | -------------------------------------------------------------------------------- /rockspecs/gperftools-1.0.1-1.rockspec: -------------------------------------------------------------------------------- 1 | package = 'gperftools' 2 | version = '1.0.1-1' 3 | source = { 4 | url = 'git+https://github.com/tarantool/gperftools.git', 5 | tag = '1.0.1', 6 | } 7 | description = { 8 | summary = "Bindings for Google Performnace Tools CPU profiler", 9 | homepage = 'https://github.com/tarantool/gperftools', 10 | license = 'BSD', 11 | } 12 | dependencies = { 13 | 'lua >= 5.1' 14 | } 15 | external_dependencies = { 16 | GPERFTOOLS = { 17 | library = 'profiler' 18 | } 19 | } 20 | build = { 21 | type = 'builtin', 22 | modules = { 23 | ['gperftools'] = 'gperftools/init.lua', 24 | ['gperftools.cpu'] = 'gperftools/cpu.lua' 25 | } 26 | } 27 | -- vim: syntax=lua 28 | -------------------------------------------------------------------------------- /rockspecs/gperftools-scm-1.rockspec: -------------------------------------------------------------------------------- 1 | package = 'gperftools' 2 | version = 'scm-1' 3 | source = { 4 | url = 'git+https://github.com/tarantool/gperftools.git', 5 | branch = 'master', 6 | } 7 | description = { 8 | summary = "Bindings for Google Performnace Tools CPU profiler", 9 | homepage = 'https://github.com/tarantool/gperftools', 10 | license = 'BSD', 11 | } 12 | dependencies = { 13 | 'lua >= 5.1' 14 | } 15 | external_dependencies = { 16 | GPERFTOOLS = { 17 | library = 'profiler' 18 | } 19 | } 20 | build = { 21 | type = 'builtin', 22 | modules = { 23 | ['gperftools'] = 'gperftools/init.lua', 24 | ['gperftools.cpu'] = 'gperftools/cpu.lua' 25 | } 26 | } 27 | -- vim: syntax=lua 28 | -------------------------------------------------------------------------------- /rpm/tarantool-gperftools.spec: -------------------------------------------------------------------------------- 1 | Name: tarantool-gperftools 2 | Version: 1.0.0 3 | Release: 1%{?dist} 4 | Summary: Lua bindings for gperftools CPU Profiler 5 | Group: Applications/Databases 6 | License: BSD 7 | URL: https://github.com/tarantool/tarantool-gperftools 8 | Source0: https://github.com/tarantool/%{name}/archive/%{version}/%{name}-%{version}.tar.gz 9 | BuildArch: noarch 10 | BuildRequires: tarantool >= 1.6.8.0 11 | BuildRequires: gperftools-devel 12 | BuildRequires: /usr/bin/prove 13 | Requires: tarantool >= 1.6.8.0 14 | Requires: gperftools-devel 15 | %description 16 | Lua bindings for Google Performance Tools CPU Profiler 17 | 18 | %prep 19 | %setup -q -n %{name}-%{version} 20 | 21 | %check 22 | prove -v ./test/gperftools.test.lua 23 | 24 | %install 25 | install -d %{buildroot}%{_datarootdir}/tarantool/gperftools 26 | install -m 0644 gperftools/init.lua %{buildroot}%{_datarootdir}/tarantool/gperftools/ 27 | install -m 0644 gperftools/cpu.lua %{buildroot}%{_datarootdir}/tarantool/gperftools/ 28 | 29 | %files 30 | %{_datarootdir}/tarantool/gperftools/init.lua 31 | %{_datarootdir}/tarantool/gperftools/cpu.lua 32 | 33 | %changelog 34 | * Wed Jun 17 2015 Roman Tsisyk 1.0.0-1 35 | - Initial version of the RPM spec 36 | -------------------------------------------------------------------------------- /test/gperftools.test.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env tarantool 2 | 3 | package.path = "../?/init.lua;../?.lua;./?/init.lua;./?.lua" 4 | 5 | local cpuprof = require('gperftools.cpu') 6 | local fio = require('fio') 7 | local filename = os.tmpname() 8 | 9 | require('tap').test('gperftools', function(t) 10 | t:plan(4) 11 | 12 | t:ok(cpuprof.start(filename), "start") 13 | t:ok(fio.stat(filename) ~= nil, "file exists") 14 | 15 | cpuprof.flush() 16 | local st = fio.stat(filename) 17 | t:ok(st and st.size > 0, "flush") 18 | 19 | cpuprof.stop() 20 | t:ok(true, "stop") 21 | 22 | fio.unlink(filename) 23 | end) 24 | --------------------------------------------------------------------------------