pinpoint-apm / pinpoint-c-agent

Pinpoint C Agent helps your monitor your PHP/PYTHON applications into [pinpoint-apm](https://github.com/pinpoint-apm/pinpoint).
http://pinpoint-apm.github.io/pinpoint/
Apache License 2.0
263 stars 77 forks source link

Pinpoint Php Agent for PHP 7.2 (Archlinux) #25

Closed ofauchon closed 5 years ago

ofauchon commented 6 years ago

Hi,

I'm trying to run pinpoint php on Archlinux (Php-fmp 7.2)

$ pacman -Q | grep php php 7.2.8-1 php-apache 7.2.8-1 php-fpm 7.2.9-1 gcc-libs 8.1.1+20180531-1

But the provided .so PHP module are not compatible:

$ php PHP Warning: PHP Startup: pinpoint: Unable to initialize module Module compiled with module API=20160303 PHP compiled with module API=20170718

So I decided to build it ... But I get the following error :

trace_data_sender.cpp: In member function ‘int32_t Pinpoint::Agent::TraceDataSender::init()’: trace_data_sender.cpp:53:89: error: no matching function for call to ‘apache::thrift::protocol::TCompactProtocolT::TCompactProtocolT(boost::shared_ptr&)’ TCompactProtocol *tp = new(std::nothrow) TCompactProtocol(this->transportOut);

Any help welcome.

Olivier Fauchon

ChenGXQQ commented 6 years ago

It seems that you don't install thrift. Can you give us more compile information?

6666422 commented 6 years ago

we alwayz get the error message during compiled php-agent. can anybody help us?

env: centos 7 php 7.2.9 nginx 1.12.1 boost 1.5.8 thrift 0.11 gcc 6.1

[root@www pinpoint_php]# ./Build.sh

ChenGXQQ commented 6 years ago

@6666422 Do you install thrift here: /usr/local/thrift? Can you show its version?

6666422 commented 6 years ago

yes, as following:

[root@www pinpoint_php]# protoc --version libprotoc 3.5.0

[root@www pinpoint_php]# thrift --version Thrift version 0.11.0

[root@www pinpoint_php]# whereis thrift thrift: /usr/bin/thrift /usr/local/bin/thrift /usr/include/thrift /usr/local/thrift

ChenGXQQ commented 6 years ago

@6666422 It seems that there are multi thrift installed in your server. Please set WITH_THRIFT_PATH to the right path.

6666422 commented 6 years ago

@ChenGXQQ no, no, had set up the path.

[root@www pinpoint_php]# echo $WITH_THRIFT_PATH /usr/local/thrift

ChenGXQQ commented 6 years ago

@6666422 Please show me this file: $WITH_THRIFT_PATH/config.h

EyelynSu commented 6 years ago

@6666422 Please try 'export $WITH_THRIFT_PATH=/usr ' 1536561252

6666422 commented 6 years ago

@EyelynSu set it, also set '$WITH_BOOST_PATH=/usr', get the message, what we lose to install something?

EyelynSu commented 6 years ago

@6666422 Could please show us your 'ls /usr/include/'?

ChenGXQQ commented 6 years ago

@6666422 I recommand that you use our auto-install script. Delete WITH_BOOST_PATH and WITH_THRIFT_PATH. The script will install thrift and boost automaticly.

default

6666422 commented 6 years ago

@EyelynSu here is the result. [root@www ~]# ls /usr/include/boost accumulators filesystem memory_order.hpp regex.hpp algorithm filesystem.hpp move scoped_array.hpp aligned_storage.hpp flyweight mpi scoped_ptr.hpp any.hpp flyweight.hpp mpi.hpp scope_exit.hpp archive foreach_fwd.hpp mpl serialization array.hpp foreach.hpp msm shared_array.hpp asio format multi_array shared_container_iterator.hpp asio.hpp format.hpp multi_array.hpp shared_ptr.hpp assert.hpp function multi_index signal.hpp assign functional multi_index_container_fwd.hpp signals assign.hpp functional.hpp multi_index_container.hpp signals2 atomic function_equal.hpp multiprecision signals2.hpp atomic.hpp function.hpp next_prior.hpp signals.hpp bimap function_output_iterator.hpp noncopyable.hpp smart_ptr bimap.hpp function_types nondet_random.hpp smart_ptr.hpp bind fusion none.hpp spirit bind.hpp generator_iterator.hpp none_t.hpp spirit.hpp blank_fwd.hpp geometry non_type.hpp statechart blank.hpp geometry.hpp numeric static_assert.hpp call_traits.hpp get_pointer.hpp operators.hpp strong_typedef.hpp cast.hpp gil optional swap.hpp cerrno.hpp graph optional.hpp system checked_delete.hpp heap parameter test chrono icl parameter.hpp thread chrono.hpp implicit_cast.hpp pending thread.hpp circular_buffer indirect_reference.hpp phoenix throw_exception.hpp circular_buffer_fwd.hpp integer phoenix.hpp timer circular_buffer.hpp integer_fwd.hpp pointee.hpp timer.hpp compatibility integer.hpp pointer_cast.hpp token_functions.hpp compressed_pair.hpp integer_traits.hpp pointer_to_other.hpp token_iterator.hpp concept interprocess polygon tokenizer.hpp concept_archetype.hpp intrusive pool tr1 concept_check intrusive_ptr.hpp preprocessor tuple concept_check.hpp io preprocessor.hpp type.hpp config io_fwd.hpp program_options typeof config.hpp iostreams program_options.hpp type_traits container is_placeholder.hpp progress.hpp type_traits.hpp context iterator property_map units coroutine iterator_adaptors.hpp property_tree unordered crc.hpp iterator.hpp proto unordered_map.hpp cregex.hpp lambda ptr_container unordered_set.hpp cstdint.hpp last_value.hpp python utility cstdlib.hpp lexical_cast.hpp python.hpp utility.hpp current_function.hpp limits.hpp random uuid date_time locale random.hpp variant date_time.hpp locale.hpp range variant.hpp detail local_function range.hpp version.hpp dynamic_bitset local_function.hpp ratio visit_each.hpp dynamic_bitset_fwd.hpp lockfree ratio.hpp wave dynamic_bitset.hpp logic rational.hpp wave.hpp enable_shared_from_this.hpp make_shared.hpp ref.hpp weak_ptr.hpp exception math regex xpressive exception.hpp math_fwd.hpp regex_fwd.hpp exception_ptr.hpp mem_fn.hpp regex.h

[root@www ~]# ls /usr/include/thrift async config.h protocol TApplicationException.h Thrift.h transport c_glib cxxfunctional.h qt TDispatchProcessor.h TLogging.h TReflectionLocal.h concurrency processor server thrift-config.h TProcessor.h

6666422 commented 6 years ago

@ChenGXQQ I just do it according the guide, but Build.sh should be in pinpoint_php folder.

ChenGXQQ commented 6 years ago

@6666422 If you set the env variables WITH_BOOST_PATH and WITH_THRIFT_PATH, it will use your libraries. Unset the two variables and let the script downloads and compile these libraries automaticly.

ofauchon commented 6 years ago

I'm wondering if the problem is related to gcc>4. I'll try to rebuild the module with gcc4 with the same procedure.

ofauchon commented 6 years ago

I found out that GCC >= 4.7 is C++11 (https://gcc.gnu.org/projects/cxx-status.html#cxx11) When c++11 flags are enable, it offers have full support for std::shared_ptr.

This is the reason thrift is build with std::shared_ptr instead of boost::shared_ptr :-(

To allow thrift to be build with boost::shared_ptr, we have to build thrift with "#define FORCE_BOOST_SMART_PTR" in thrift/stdcxx.h ( See thrift/stdcxx.h for more.) Refs: https://jira.apache.org/jira/browse/THRIFT-2221 https://thrift.apache.org/lib/cpp https://gcc.gnu.org/projects/cxx-status.html#cxx11

Please note you have to apply this patch too to fix some errors too :

--- a/pinpoint_common/Makefile
+++ b/pinpoint_common/Makefile
@@ -16,12 +16,12 @@ ifeq ($(RUN_TEST),1)
        CPPFLAGS+=-g3 -DRUN_TEST -DDEBUG $(RUN_TEST_FLAGS)
 else ifeq ($(DEBUG), YES)
     # debug
-    CFLAGS+=-g3 -DDEBUG -Werror
-       CPPFLAGS+=-g3 -DDEBUG -Werror
+    CFLAGS+=-g3 -DDEBUG 
+       CPPFLAGS+=-g3 -DDEBUG 
 else
     # release
-    CFLAGS+=-O3 -DNDEBUG -Werror
-       CPPFLAGS+=-O3 -DNDEBUG -Werror
+    CFLAGS+=-O3 -DNDEBUG 
+       CPPFLAGS+=-O3 -DNDEBUG 
 endif

 ifeq ($(WITH_BOOST_PATH), $(wildcard $(WITH_BOOST_PATH)))
diff --git a/pinpoint_common/utility.cpp b/pinpoint_common/utility.cpp
index 00683d1..da25012 100644
--- a/pinpoint_common/utility.cpp
+++ b/pinpoint_common/utility.cpp
@@ -331,7 +331,7 @@ namespace Pinpoint
             const char* p = value.c_str();

             /* skip space */
-            for (; p != '\0' && ((char)*p == ' ' || (char)*p == '\t'); p++)
+            for (; p != NULL && ((char)*p == ' ' || (char)*p == '\t'); p++)
                 ;

             if (strlen(p) == 0)
diff --git a/pinpoint_php/php_common.cpp b/pinpoint_php/php_common.cpp
index 10e9b83..923366b 100644
--- a/pinpoint_php/php_common.cpp
+++ b/pinpoint_php/php_common.cpp
@@ -74,7 +74,7 @@ static inline std::string getNameFromHeaderMap(const char* pstr)
 static uint32_t find_first_of_char(const char*pstr, uint32_t strLen ,char C)
 {
     uint32_t i =0;
-    for( ;pstr != '\0' && i < strLen ;pstr++,i++)
+    for( ;pstr != NULL && i < strLen ;pstr++,i++)
     {
         if((char)*pstr == C)
             break;

Here is my build procedure too:


mkdir -p $HOME/tmp/pp-php72/tgz
mkdir -p $HOME/tmp/pp-php72/3rd-build
mkdir -p $HOME/tmp/pp-php72/3rd-install

cd $HOME/tmp/pp-php72/tgz
wget "https://dl.bintray.com/boostorg/release/1.63.0/source/boost_1_63_0.tar.bz2"
wget "http://apache.crihan.fr/dist/thrift/0.11.0/thrift-0.11.0.tar.gz"

cd $HOME/tmp/pp-php72/3rd-build
tar xvfj ../tgz/boost_1_63_0.tar.bz2
tar xvfz ../tgz/thrift-0.11.0.tar.gz
ln -s thrift-0.11.0 thrift
ln -s boost_1_63_0 boost

cd boost
./bootstrap.sh
./b2 install --prefix=$HOME/tmp/pp-php72/3rd-install/boost

cd ../thrift
./configure --with-cpp=yes --with-go=no --with-csharp=no --with-php=no --with-python=no --with-nodejs=no --with-lua=no --with-boost=$HOME/tmp/pp-php72/3rd-install/boost  --prefix=$HOME/tmp/pp-php72/3rd-install/thrift

cd $HOME/tmp/pp-php72/
git clone https://github.com/naver/pinpoint-c-agent.git

cd pinpoint-c-agent/pinpoint_php

export WITH_THRIFT_PATH=$HOME/tmp/pp-php72/3rd-install/thrift
export WITH_BOOST_PATH=$HOME/tmp/pp-php72/3rd-install/boost

./Build.sh

At the moment, I could build the pinpoint php module, but I could not run it because of some inconsistancies on its dependancies:

[olivier@psx pinpoint_php]$ ldd /home/olivier/tmp/pp-php72/pinpoint-c-agent/pinpoint_php/modules/pinpoint.so | egrep "(boost|thr)"
        libboost_system.so.1.63.0 => not found
        libboost_thread.so.1.63.0 => not found
        libboost_filesystem.so.1.63.0 => not found
        libboost_date_time.so.1.63.0 => not found
        libthrift-0.11.0.so => /home/XXXX/tmp/pp-php72/3rd-install/thrift/lib/libthrift-0.11.0.so (0x00007fc2b40f9000)

I'd be great if boost and thrift code are embedded in the .so itself instead ...

I'll continue working on that.

Hope that helps Olivier Fauchon

ChenGXQQ commented 6 years ago

@ofauchon Thanks for your help. Your information is useful for us to make full compatibility with C++11.

ofauchon commented 5 years ago

Hi,

I could build pinpoint php agent on Arch Linux... But the module is linked to the custom thrift/boost libraries (see above)

Is it possible to static link boost/thrift to the pinpoint php module ?

Thanks Olivier

ldd /home/olivier/dev/BUILD-PP-PHP/build/pinpoint-c-agent-ArchBuild/pinpoint_php/modules/pinpoint.so linux-vdso.so.1 (0x00007ffc879a5000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f64a5cb0000) libboost_system.so.1.63.0 => /home/olivier/dev/BUILD-PP-PHP/install/lib/libboost_system.so.1.63.0 (0x00007f64a5aac000) libboost_thread.so.1.63.0 => /home/olivier/dev/BUILD-PP-PHP/install/lib/libboost_thread.so.1.63.0 (0x00007f64a5884000) libboost_filesystem.so.1.63.0 => /home/olivier/dev/BUILD-PP-PHP/install/lib/libboost_filesystem.so.1.63.0 (0x00007f64a566b000) libboost_date_time.so.1.63.0 => /home/olivier/dev/BUILD-PP-PHP/install/lib/libboost_date_time.so.1.63.0 (0x00007f64a5459000) libthrift-0.11.0.so => /home/olivier/dev/BUILD-PP-PHP/install/lib/libthrift-0.11.0.so (0x00007f64a50e6000) libm.so.6 => /usr/lib/libm.so.6 (0x00007f64a4d9a000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f64a4b83000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f64a47cb000) /usr/lib64/ld-linux-x86-64.so.2 (0x00007f64a63eb000) librt.so.1 => /usr/lib/librt.so.1 (0x00007f64a45c3000) libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f64a43a5000) libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007f64a413b000) libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007f64a3cbe000) libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f64a3aba000)

ofauchon commented 5 years ago

I could compile pinpoint.so with thrift/boost embedded by hand :

[olivier@royale pinpoint_php]$ cc -shared .libs/pinpoint_ext.o .libs/aop_hook.o .libs/interceptor.o .libs/php_common.o .libs/php_plugin.o .libs/php_interfaces.o .libs/php_function_helper.o plugins/.libs/request_plugin.o plugins/.libs/internel_functions_plugin.o -Wl,--rpath -Wl,/home/olivier/dev/BUILD-PP-PHP/install/lib -Wl,--rpath -Wl,/home/olivier/dev/BUILD-PP-PHP/install/lib -lstdc++ -L/home/olivier/dev/BUILD-PP-PHP/build/pinpoint-c-agent-ArchBuild/pinpoint_common -lpinpointcommon -L/home/olivier/dev/BUILD-PP-PHP/install/lib ../../../install/lib/libthrift.a ../../../install/lib/libboost*a -lm -Wl,-soname -Wl,pinpoint.so -o .libs/pinpoint.so

[olivier@royale pinpoint_php]$ ldd .libs/pinpoint.so linux-vdso.so.1 (0x00007ffea179f000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f6d91544000) libm.so.6 => /usr/lib/libm.so.6 (0x00007f6d911f8000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f6d90fe1000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f6d90c29000) /usr/lib64/ld-linux-x86-64.so.2 (0x00007f6d91ca9000)

... But this requires to build boost and thrift with "-fPIC"

(boost) ./b2 cxxflags=-fPIC cflags=-fPIC install --prefix=$WD/install

(thrift) ./configure CXXFLAGS='-DFORCE_BOOST_SMART_PTR -fPIC' -with-cpp=yes --enable-shared --with-pic --with-c_glib=no --with-go=no --with-csharp=no --with-php=no --with-python=no --with-nodejs=no --with-lua=no --with-boost=$WD/install --prefix=$WD/install

ofauchon commented 5 years ago

Hi,

For those wanting to build the module on Archlinux (or any other distributions), please find the following procedure:

mkdir tmp; cd tmp git clone https://github.com/ofauchon/pinpoint-c-agent.git git checkout ArchBuild cd ArchBuild ./build.sh .... [olivier@royale ArchBuild]$ ldd ../pinpoint_php/modules/pinpoint.so linux-vdso.so.1 (0x00007ffdf1fa4000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f0765c4d000) libm.so.6 => /usr/lib/libm.so.6 (0x00007f0765901000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f07656ea000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f0765332000) /usr/lib64/ld-linux-x86-64.so.2 (0x00007f07663b2000)

Tested on versions:

PHP 7.1.12 (cli) (built: Nov 22 2017 17:43:08) ( NTS ) gcc version 7.2.0 (GCC) glibc 2.26-6

eeliu commented 5 years ago

Hi, all We had released https://github.com/naver/pinpoint-c-agent/releases/tag/v0.2.0. This version had removed such annoying dependencies, make agent more easy to use, hope you use it.

So I close this issue.