Source of XHProf 0.10.0 released

I’ve released the source some minutes ago! Everyone who’s interested in the source of the windows-compatible release can find the sources at my github repo for XHProf and maybe soon at the Facebook repo.

For the „old-school“ user – here are the udiff patches for the two files:

1. php_xhprof.h:

1
2
3
4
5
6
7
8
9
10
11
12
25a26
> #include "win32/php_xhprof_win32.h"
33a35,37
> /**
> * PHP default module methods
> */
39a44,46
> /**
> * declare methods available in PHP
> */
45a53
>

and xhprof.c:

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
61a62,71
> #elif PHP_WIN32
> /*
> * Patch for compiling in Windows (i've used MS VC++ 6)
> * @author Benjamin Carl
> */
> # define CPU_SET(cpu_id, new_mask) (*(new_mask)) = (cpu_id + 1)
> # define CPU_ZERO(new_mask) (*(new_mask)) = 0
> # define SET_AFFINITY(pid, size, mask) SetProcessAffinityMask(pid, (*(mask)))
> # define GET_AFFINITY(pid, size, mask)
> GetProcessAffinityMask(GetCurrentProcess(), mask, &s_mask)
78c88
< #define XHPROF_VERSION "0.9.2"
---
> #define XHPROF_VERSION "0.10.0"

236c246
< static ZEND_DLEXPORT void (*_zend_execute) (zend_op_array *ops TSRMLS_DC);
---
> ZEND_DLEXPORT void (*_zend_execute) (zend_op_array *ops TSRMLS_DC);

239c249
< static ZEND_DLEXPORT void (*_zend_execute_internal) (zend_execute_data *data,
---
> ZEND_DLEXPORT void (*_zend_execute_internal) (zend_execute_data *data,

282a293,295
> static int restore_cpu_affinity(cpu_set_t * prev_mask);
> static int bind_to_cpu(uint32 cpu_id);
>
408a422
> unsigned long s_mask;
414a429
> #ifndef PHP_WIN32
415a431,434
> #else
> GetSystemInfo(&sysinfo);
> hp_globals.cpu_num = sysinfo.dwNumberOfProcessors;
> #endif
486c505,506
< int i;
---
> /* Note(bcarl): changed to uint32 like defined in struct -> hp_global_t */

> uint32 i;
488a509,511
> // duplicate call needed?
> get_all_cpu_frequencies();
>
490c513,514
< php_info_print_table_header(2, "xhprof", XHPROF_VERSION);
---
> php_info_print_table_row(2, "xhprof", "enabled");

> php_info_print_table_row(2, "xhprof version", XHPROF_VERSION);
493c517,521
< php_info_print_table_header(2, "CPU num", buf);
---
> php_info_print_table_row(2, "CPU num", buf);

> /* information about the cpu the process is bound to */
> len = snprintf(tmp, SCRATCH_BUF_LEN, " CPU %d ", hp_globals.cur_cpu_id);
> tmp[len] = 0;
> php_info_print_table_row(2, "process bound to", tmp);
501c529
< len = snprintf(tmp, SCRATCH_BUF_LEN, "%f", hp_globals.cpu_frequencies[i]);
---
> len = snprintf(tmp, SCRATCH_BUF_LEN, "%-.0f", hp_globals.cpu_frequencies[i]);

923,924d950
< int desc_len;
< char *desc;
1099,1101c1125,1127
< /* Update tv */
< tv->tv_sec = (time_in_micro / 1000000);
< tv->tv_usec = (time_in_micro % 1000000);
---
> /* Update tv Note(bcarl): added explicit typecasting (long) warning C4244 */

> tv->tv_sec = (long)(time_in_micro / 1000000);
> tv->tv_usec = (long)(time_in_micro % 1000000);
1184a1211,1219
>
> #ifdef PHP_WIN32
> __asm {
> cpuid
> rdtsc
> mov __a, eax
> mov __d, edx
> }
> #else
1185a1221,1222
> #endif
>
1230,1231c1267,1268
< start->tv_sec = incr/1000000;
< start->tv_usec = incr%1000000;
---
> start->tv_sec = (long)(incr/1000000);

> start->tv_usec = (long)(incr%1000000);
1270a1308,1309
> uint64 tsc_start;
> uint64 tsc_end;
1276c1315,1317
< uint64 tsc_start = cycle_timer();
---
>

> tsc_start = cycle_timer();
>
1284c1325,1327
< uint64 tsc_end = cycle_timer();
---
>

> tsc_end = cycle_timer();
>
1294c1337
< int id;
---
> uint32 id;

1519,1520d1561
< double gtod_value, rdtsc_value;
<
1532c1573
< hp_inc_count(counts, "wt", get_us_from_tsc(tsc_end - top->tsc_start,
---
> hp_inc_count(counts, "wt", (long)get_us_from_tsc(tsc_end - top->tsc_start,

1786,1787d1826
< zval *ret;
< char *out_url;

9 Antworten zu “Source of XHProf 0.10.0 released”

  1. Ung Vu, TO sagt:

    Hi clickalicious,

    I’m trying to build xhprof extension on windows.
    From searching on google, I found that I need the file named ‚config.w32‘ to be able to compile a PHP extension.

    From above, and on your github (https://github.com/clickalicious/xhprof), I don’t see this config file. So when I run buildconf and configure –help, I don’t see the –enable-xhprof.

    Please help me,
    Thank you

    • You will need the config.w32 if you want to compile with „make“.
      I don’t compile the extension this way. I compile the extension stand alone with VC9 on windows. So if you want to build the extension you should think about of changing your dev environment for building PHP (and extensions)?

      More information about compiling (PHP) on windows:
      https://wiki.php.net/internals/windows/stepbystepbuild
      and for the extension: http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/
      http://phpforum.de/forum/showthread.php?t=244096

      You can find a compiled extension“php_xhprof.dll“ here: https://www.phpfluesterer.de/projekte/open-source-software-projekte/xhprof-php-extension/xhprof-fur-windows-aktuelle-windows-builds/

      • Ung Vu, TO sagt:

        Hi PHPFlüsterer,

        Thank you for your quick response.
        I’ll try this and let you know the results, also may be new problems :)

        Thank bro,
        Happy coding

      • Ung Vu, TO sagt:

        Hi,

        From above, you said that „So if you want to build the extension you should think about of changing your dev environment for building PHP (and extensions)?“
        But I’ve just realized that the guide you mentioned (https://wiki.php.net/internals/windows/stepbystepbuild) show me the way to compile PHP with NMAKE, not inside Visual Studio IDE. This makes me be confused :(.

        So, if we want to compile PHP we use NMAKE and if we want to compile PHP Extension we use VS IDE. Am I right?
        And another question, how did you build your PHP? Use NMAKE or inside VSIDE. If you compile in VS IDE, plz show me how because the guide doesn’t show this.

        • sry for that confusing information ;) you’re right …

          1) i use nmake for compiling PHP so that i get
          a) my personalized PHP built which fit my needs
          b) AND the required php5ts.lib which you will need to compile an extension like XHProf (from the tutorial: … Project Properties dialog, under Configuration Properties > Linker > General add the path to the C:\Server\PHP\dev directory to the Additional Library Directories. This is the directory underneath your installed PHP binaries (not the extracted source). This directory should contain php5ts.lib…

          2) After that i use the VC9 IDE for managing the project but only in cause of the fact that otherwise you will need a build-file in a syntax i dont know and you will need the cmd „phpize“ which is afaik only available on linux. So i’ve choosen the IDE-way cause i was simply the quickest solution …

          I hope that this additional information makes everything a bit clearer to you.

          • Ung Vu, TO sagt:

            Hi, :)
            Thanks bros, everything seems to be clearer now: using NMAKE to get PHP binaries and using VS IDE for PHP extensions.

            One more problem ;): when I got your xhprof code (https://github.com/clickalicious/xhprof), followed this guides (http://www.dreamincode.net/forums/topic/244215-introduction-to-creating-a-php-extension-for-windows/, http://www.talkphp.com/vbarticles.php?do=article&articleid=49) and compiled, I faced with 2 errors: and not found. I commented those 2 lines and the compiling successes. I got the ‚xhprof.dll‘. Next, I loaded it in php.ini using: extension=xhprof.dll and started apache, checked phpinfo for xhprof, everything was OK. But when I test a simple example:
            ————————————-

            —————————————
            The apache server crashed:
            Problem signature:
            Problem Event Name: APPCRASH
            Application Name: httpd.exe
            Application Version: 2.4.3.0
            Application Timestamp: 502f70a3
            Fault Module Name: xhprof.dll
            Fault Module Version: 0.0.0.0
            Fault Module Timestamp: 50b42733
            Exception Code: c0000005
            Exception Offset: 00014f6c
            OS Version: 6.1.7600.2.0.0.256.1
            Locale ID: 1033
            Additional Information 1: 0a9e
            Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
            Additional Information 3: 0a9e
            Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

            But if I used your php_xhprof.dll, the problem was not happened :) That example above run OK and output the happy result.
            I don’t know why this happened?

            I compared 2 dlls (yours and mine):
            your dll: size 66 048 bytes
            my dll: size 55 296 bytes

            I think there was some prolems that cause my result.
            If your have free time, plz help me ;)

            Thnks bro :)

          • Ung Vu, TO sagt:

            Oh, I’ve just realized your site filters my code:
            – 2 files not found: sys -splash- time-dot-h, sys-splash-resource-dot-h, as I said, I commented those 2 lines and the compiling was successed.
            – The example code I tested and got error apache crashed: simple, 2lines:
            xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
            $xhprof_data = xhprof_disable();

            Thanks

          • When you download the source of PHP 5.4.9 for example you will find a folder named „win32“ which contains the missing header files which you need to compile the linux stuff under windows. The only thing i did was moving time.h, resource.h and the other header files to a new folder called „sys“ so that the new structure is (for example):

            C:\ … Development\PHP\php5.4-201211100030\win32\sys\time.h

            make sure you add „C:\ … Development\PHP\php5.4-201211100030\win32“ to the additional include path’s

            configuration -> C/C++ -> General -> Additional Includes

          • Ung Vu, TO sagt:

            Oh oh… :(
            I followed your instructions, create new folder named ’sys‘ in ‚win32‘, copy (you said move) all header files into there. Uncommeted 2 lines (time.h, resource.h) and the source code now revert back to the beginning point, which means I got it from your github and didn’t change any thing.
            I hit build and happily the compiling process was success. I got ‚xhprof.dll‘. But I noticed that the size of it didn’t change, still 55 296 bytes. I did rebuild 2 and 3 times more, the size still was 55 296(??).
            Then I loaded it into apache, success, check phpinfo, success and run the simple example code above => not success! The apache crashed again :(
            Problem Event Name: APPCRASH
            Application Name: httpd.exe
            Application Version: 2.4.3.0
            Application Timestamp: 502f70a3
            Fault Module Name: xhprof.dll
            Fault Module Version: 0.0.0.0
            Fault Module Timestamp: 50b49bf5
            Exception Code: c0000005
            Exception Offset: 00014f6c
            OS Version: 6.1.7600.2.0.0.256.1
            Locale ID: 1033
            Additional Information 1: 0a9e
            Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
            Additional Information 3: 0a9e
            Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

            From above, I noticed that the ‚Fault Module Version‘ was 0.0.0.0 but in phpinfo it was 0.10.3. Is this a problem?

            Thanks

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

*