-
Notifications
You must be signed in to change notification settings - Fork 37
/
profiling_HOWTO
62 lines (30 loc) · 12.4 KB
/
profiling_HOWTO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Below describes an aborted attempt to use gcc generated gprof profiling information. A better approach is to use oprofile, which is a sampling profiling built into the linux kernel, or valgrind's callgrind tool.
To Run oprofile:
$ sudo modprobe oprofile
$ sudo oprofile --start
$ ./bench
$ sudo oprofile --stop # optional really
$ opreport -l ./bench # to view the results
To Run callgrind
$ valgrind --tool=callgrind ./bench # generate a callgrind.xxxxx.out file
$ kcachegrind callgrind.xxxxx.out # view the file. 'xxxxx' is the process id.
The old gprof approach, which I couldnt make work:
Profiling code generated by phc is somewhat difficult. By default, phc links to the PHP embad SAPI using a shared library. However, profiling does not work with a shared library. Instead, PHP must be configured to be a static library (we must have a libphp5.a).
To do this, the flags --enable-embed=static must be set. But actually, this doesnt work.
Instead, configure it with --enable-embed=shared (or just --enable-embed)
In your PHP directory:
CFLAGS="-pg -O0 -g" ./configure --enable-debug --enable-maintainer-zts --enable-embed=shared --prefix=/usr/local/profiled-php
# Note that enable-embed=shared is not a typo.
make
ar rcs libphp5.a ext/libxml/.libs/libxml.o ext/pcre/pcrelib/.libs/pcre_chartables.o ext/pcre/pcrelib/.libs/pcre_ucp_searchfuncs.o ext/pcre/pcrelib/.libs/pcre_compile.o ext/pcre/pcrelib/.libs/pcre_config.o ext/pcre/pcrelib/.libs/pcre_exec.o ext/pcre/pcrelib/.libs/pcre_fullinfo.o ext/pcre/pcrelib/.libs/pcre_get.o ext/pcre/pcrelib/.libs/pcre_globals.o ext/pcre/pcrelib/.libs/pcre_info.o ext/pcre/pcrelib/.libs/pcre_maketables.o ext/pcre/pcrelib/.libs/pcre_newline.o ext/pcre/pcrelib/.libs/pcre_ord2utf8.o ext/pcre/pcrelib/.libs/pcre_refcount.o ext/pcre/pcrelib/.libs/pcre_study.o ext/pcre/pcrelib/.libs/pcre_tables.o ext/pcre/pcrelib/.libs/pcre_try_flipped.o ext/pcre/pcrelib/.libs/pcre_valid_utf8.o ext/pcre/pcrelib/.libs/pcre_version.o ext/pcre/pcrelib/.libs/pcre_xclass.o ext/pcre/.libs/php_pcre.o ext/ctype/.libs/ctype.o ext/date/.libs/php_date.o ext/date/lib/.libs/astro.o ext/date/lib/.libs/dow.o ext/date/lib/.libs/parse_date.o ext/date/lib/.libs/parse_tz.o ext/date/lib/.libs/timelib.o ext/date/lib/.libs/tm2unixtime.o ext/date/lib/.libs/unixtime2tm.o ext/dom/.libs/php_dom.o ext/dom/.libs/attr.o ext/dom/.libs/document.o ext/dom/.libs/domerrorhandler.o ext/dom/.libs/domstringlist.o ext/dom/.libs/domexception.o ext/dom/.libs/namelist.o ext/dom/.libs/processinginstruction.o ext/dom/.libs/cdatasection.o ext/dom/.libs/documentfragment.o ext/dom/.libs/domimplementation.o ext/dom/.libs/element.o ext/dom/.libs/node.o ext/dom/.libs/string_extend.o ext/dom/.libs/characterdata.o ext/dom/.libs/documenttype.o ext/dom/.libs/domimplementationlist.o ext/dom/.libs/entity.o ext/dom/.libs/nodelist.o ext/dom/.libs/text.o ext/dom/.libs/comment.o ext/dom/.libs/domconfiguration.o ext/dom/.libs/domimplementationsource.o ext/dom/.libs/entityreference.o ext/dom/.libs/notation.o ext/dom/.libs/xpath.o ext/dom/.libs/dom_iterators.o ext/dom/.libs/typeinfo.o ext/dom/.libs/domerror.o ext/dom/.libs/domlocator.o ext/dom/.libs/namednodemap.o ext/dom/.libs/userdatahandler.o ext/filter/.libs/filter.o ext/filter/.libs/sanitizing_filters.o ext/filter/.libs/logical_filters.o ext/filter/.libs/callback_filter.o ext/hash/.libs/hash.o ext/hash/.libs/hash_md.o ext/hash/.libs/hash_sha.o ext/hash/.libs/hash_ripemd.o ext/hash/.libs/hash_haval.o ext/hash/.libs/hash_tiger.o ext/hash/.libs/hash_gost.o ext/hash/.libs/hash_snefru.o ext/hash/.libs/hash_whirlpool.o ext/hash/.libs/hash_adler32.o ext/hash/.libs/hash_crc32.o ext/iconv/.libs/iconv.o ext/json/.libs/json.o ext/json/.libs/utf8_to_utf16.o ext/json/.libs/utf8_decode.o ext/json/.libs/JSON_parser.o ext/pdo/.libs/pdo.o ext/pdo/.libs/pdo_dbh.o ext/pdo/.libs/pdo_stmt.o ext/pdo/.libs/pdo_sql_parser.o ext/pdo/.libs/pdo_sqlstate.o ext/pdo_sqlite/.libs/pdo_sqlite.o ext/pdo_sqlite/.libs/sqlite_driver.o ext/pdo_sqlite/.libs/sqlite_statement.o ext/pdo_sqlite/sqlite/src/.libs/attach.o ext/pdo_sqlite/sqlite/src/.libs/auth.o ext/pdo_sqlite/sqlite/src/.libs/btree.o ext/pdo_sqlite/sqlite/src/.libs/build.o ext/pdo_sqlite/sqlite/src/.libs/callback.o ext/pdo_sqlite/sqlite/src/.libs/date.o ext/pdo_sqlite/sqlite/src/.libs/delete.o ext/pdo_sqlite/sqlite/src/.libs/expr.o ext/pdo_sqlite/sqlite/src/.libs/func.o ext/pdo_sqlite/sqlite/src/.libs/hash.o ext/pdo_sqlite/sqlite/src/.libs/insert.o ext/pdo_sqlite/sqlite/src/.libs/legacy.o ext/pdo_sqlite/sqlite/src/.libs/main.o ext/pdo_sqlite/sqlite/src/.libs/os_unix.o ext/pdo_sqlite/sqlite/src/.libs/os_win.o ext/pdo_sqlite/sqlite/src/.libs/os.o ext/pdo_sqlite/sqlite/src/.libs/pager.o ext/pdo_sqlite/sqlite/src/.libs/pragma.o ext/pdo_sqlite/sqlite/src/.libs/prepare.o ext/pdo_sqlite/sqlite/src/.libs/printf.o ext/pdo_sqlite/sqlite/src/.libs/random.o ext/pdo_sqlite/sqlite/src/.libs/select.o ext/pdo_sqlite/sqlite/src/.libs/table.o ext/pdo_sqlite/sqlite/src/.libs/tokenize.o ext/pdo_sqlite/sqlite/src/.libs/analyze.o ext/pdo_sqlite/sqlite/src/.libs/complete.o ext/pdo_sqlite/sqlite/src/.libs/trigger.o ext/pdo_sqlite/sqlite/src/.libs/update.o ext/pdo_sqlite/sqlite/src/.libs/utf.o ext/pdo_sqlite/sqlite/src/.libs/util.o ext/pdo_sqlite/sqlite/src/.libs/vacuum.o ext/pdo_sqlite/sqlite/src/.libs/vdbeapi.o ext/pdo_sqlite/sqlite/src/.libs/vdbeaux.o ext/pdo_sqlite/sqlite/src/.libs/vdbe.o ext/pdo_sqlite/sqlite/src/.libs/vdbemem.o ext/pdo_sqlite/sqlite/src/.libs/where.o ext/pdo_sqlite/sqlite/src/.libs/parse.o ext/pdo_sqlite/sqlite/src/.libs/opcodes.o ext/pdo_sqlite/sqlite/src/.libs/alter.o ext/pdo_sqlite/sqlite/src/.libs/vdbefifo.o ext/pdo_sqlite/sqlite/src/.libs/vtab.o ext/pdo_sqlite/sqlite/src/.libs/loadext.o ext/posix/.libs/posix.o ext/reflection/.libs/php_reflection.o ext/session/.libs/session.o ext/session/.libs/mod_files.o ext/session/.libs/mod_mm.o ext/session/.libs/mod_user.o ext/simplexml/.libs/simplexml.o ext/spl/.libs/php_spl.o ext/spl/.libs/spl_functions.o ext/spl/.libs/spl_engine.o ext/spl/.libs/spl_iterators.o ext/spl/.libs/spl_array.o ext/spl/.libs/spl_directory.o ext/spl/.libs/spl_sxe.o ext/spl/.libs/spl_exceptions.o ext/spl/.libs/spl_observer.o ext/sqlite/.libs/sqlite.o ext/sqlite/.libs/sess_sqlite.o ext/sqlite/.libs/pdo_sqlite2.o ext/sqlite/libsqlite/src/.libs/opcodes.o ext/sqlite/libsqlite/src/.libs/parse.o ext/sqlite/libsqlite/src/.libs/encode.o ext/sqlite/libsqlite/src/.libs/auth.o ext/sqlite/libsqlite/src/.libs/btree.o ext/sqlite/libsqlite/src/.libs/build.o ext/sqlite/libsqlite/src/.libs/delete.o ext/sqlite/libsqlite/src/.libs/expr.o ext/sqlite/libsqlite/src/.libs/func.o ext/sqlite/libsqlite/src/.libs/hash.o ext/sqlite/libsqlite/src/.libs/insert.o ext/sqlite/libsqlite/src/.libs/main.o ext/sqlite/libsqlite/src/.libs/os.o ext/sqlite/libsqlite/src/.libs/pager.o ext/sqlite/libsqlite/src/.libs/printf.o ext/sqlite/libsqlite/src/.libs/random.o ext/sqlite/libsqlite/src/.libs/select.o ext/sqlite/libsqlite/src/.libs/table.o ext/sqlite/libsqlite/src/.libs/tokenize.o ext/sqlite/libsqlite/src/.libs/update.o ext/sqlite/libsqlite/src/.libs/util.o ext/sqlite/libsqlite/src/.libs/vdbe.o ext/sqlite/libsqlite/src/.libs/attach.o ext/sqlite/libsqlite/src/.libs/btree_rb.o ext/sqlite/libsqlite/src/.libs/pragma.o ext/sqlite/libsqlite/src/.libs/vacuum.o ext/sqlite/libsqlite/src/.libs/copy.o ext/sqlite/libsqlite/src/.libs/vdbeaux.o ext/sqlite/libsqlite/src/.libs/date.o ext/sqlite/libsqlite/src/.libs/where.o ext/sqlite/libsqlite/src/.libs/trigger.o regex/.libs/regcomp.o regex/.libs/regexec.o regex/.libs/regerror.o regex/.libs/regfree.o ext/standard/.libs/array.o ext/standard/.libs/base64.o ext/standard/.libs/basic_functions.o ext/standard/.libs/browscap.o ext/standard/.libs/crc32.o ext/standard/.libs/crypt.o ext/standard/.libs/cyr_convert.o ext/standard/.libs/datetime.o ext/standard/.libs/dir.o ext/standard/.libs/dl.o ext/standard/.libs/dns.o ext/standard/.libs/exec.o ext/standard/.libs/file.o ext/standard/.libs/filestat.o ext/standard/.libs/flock_compat.o ext/standard/.libs/formatted_print.o ext/standard/.libs/fsock.o ext/standard/.libs/head.o ext/standard/.libs/html.o ext/standard/.libs/image.o ext/standard/.libs/info.o ext/standard/.libs/iptc.o ext/standard/.libs/lcg.o ext/standard/.libs/link.o ext/standard/.libs/mail.o ext/standard/.libs/math.o ext/standard/.libs/md5.o ext/standard/.libs/metaphone.o ext/standard/.libs/microtime.o ext/standard/.libs/pack.o ext/standard/.libs/pageinfo.o ext/standard/.libs/quot_print.o ext/standard/.libs/rand.o ext/standard/.libs/reg.o ext/standard/.libs/soundex.o ext/standard/.libs/string.o ext/standard/.libs/scanf.o ext/standard/.libs/syslog.o ext/standard/.libs/type.o ext/standard/.libs/uniqid.o ext/standard/.libs/url.o ext/standard/.libs/url_scanner.o ext/standard/.libs/var.o ext/standard/.libs/versioning.o ext/standard/.libs/assert.o ext/standard/.libs/strnatcmp.o ext/standard/.libs/levenshtein.o ext/standard/.libs/incomplete_class.o ext/standard/.libs/url_scanner_ex.o ext/standard/.libs/ftp_fopen_wrapper.o ext/standard/.libs/http_fopen_wrapper.o ext/standard/.libs/php_fopen_wrapper.o ext/standard/.libs/credits.o ext/standard/.libs/css.o ext/standard/.libs/var_unserializer.o ext/standard/.libs/ftok.o ext/standard/.libs/sha1.o ext/standard/.libs/user_filters.o ext/standard/.libs/uuencode.o ext/standard/.libs/filters.o ext/standard/.libs/proc_open.o ext/standard/.libs/streamsfuncs.o ext/standard/.libs/http.o ext/tokenizer/.libs/tokenizer.o ext/xml/.libs/xml.o ext/xml/.libs/compat.o ext/xmlreader/.libs/php_xmlreader.o ext/xmlwriter/.libs/php_xmlwriter.o TSRM/.libs/TSRM.o TSRM/.libs/tsrm_strtok_r.o TSRM/.libs/tsrm_virtual_cwd.o main/.libs/main.o main/.libs/snprintf.o main/.libs/spprintf.o main/.libs/php_sprintf.o main/.libs/safe_mode.o main/.libs/fopen_wrappers.o main/.libs/alloca.o main/.libs/php_scandir.o main/.libs/php_ini.o main/.libs/SAPI.o main/.libs/rfc1867.o main/.libs/php_content_types.o main/.libs/strlcpy.o main/.libs/strlcat.o main/.libs/mergesort.o main/.libs/reentrancy.o main/.libs/php_variables.o main/.libs/php_ticks.o main/.libs/network.o main/.libs/php_open_temporary_file.o main/.libs/php_logos.o main/.libs/output.o main/streams/.libs/streams.o main/streams/.libs/cast.o main/streams/.libs/memory.o main/streams/.libs/filter.o main/streams/.libs/plain_wrapper.o main/streams/.libs/userspace.o main/streams/.libs/transports.o main/streams/.libs/xp_socket.o main/streams/.libs/mmap.o Zend/.libs/zend_language_parser.o Zend/.libs/zend_language_scanner.o Zend/.libs/zend_ini_parser.o Zend/.libs/zend_ini_scanner.o Zend/.libs/zend_alloc.o Zend/.libs/zend_compile.o Zend/.libs/zend_constants.o Zend/.libs/zend_dynamic_array.o Zend/.libs/zend_execute_API.o Zend/.libs/zend_highlight.o Zend/.libs/zend_llist.o Zend/.libs/zend_opcode.o Zend/.libs/zend_operators.o Zend/.libs/zend_ptr_stack.o Zend/.libs/zend_stack.o Zend/.libs/zend_variables.o Zend/.libs/zend.o Zend/.libs/zend_API.o Zend/.libs/zend_extensions.o Zend/.libs/zend_hash.o Zend/.libs/zend_list.o Zend/.libs/zend_indent.o Zend/.libs/zend_builtin_functions.o Zend/.libs/zend_sprintf.o Zend/.libs/zend_ini.o Zend/.libs/zend_qsort.o Zend/.libs/zend_multibyte.o Zend/.libs/zend_ts_hash.o Zend/.libs/zend_stream.o Zend/.libs/zend_iterators.o Zend/.libs/zend_interfaces.o Zend/.libs/zend_exceptions.o Zend/.libs/zend_strtod.o Zend/.libs/zend_objects.o Zend/.libs/zend_object_handlers.o Zend/.libs/zend_objects_API.o Zend/.libs/zend_default_classes.o Zend/.libs/zend_execute.o sapi/embed/.libs/php_embed.o main/.libs/internal_functions.o /usr/lib/librt.a /usr/lib/libresolv.a /usr/lib/libm.a /usr/lib/libdl.a /usr/lib/libnsl.a /usr/lib/libxml2.a /usr/lib/libz.a /usr/lib/libcrypt.a /usr/lib/libpthread.a
# I kid you not. For some reason, this doesnt seem to work with --enable-embed=static
cp libphp5.a where_ever/
# make install wont install libphp5.a
# To compile the zend_benchmark, generate C first, then link it to the archive:
src/phc --generate-C test/subjects/3rdparty/benchmarks/zend/bench.php > bench.c
libtool --mode=link gcc -all-static -pg -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -lphp5 -static -pthread -lxml2 -lcrypt -lresolv -lm -ldl -lz -L. bench.c -o bench_prof
# this is equivalent to:
gcc -static -pg -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -pthread bench.c -o bench_prof -lphp5 /usr/lib/libxml2.a -lcrypt -lresolv -lm -ldl -lz -L/home/pbiggar/phc_work/dup
# If you're missing libraries, try
sudo apt-get build-dep php5
# Actually, I still get no timing information. The journey continues.