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

Add Stub File For IDE Autocomplete #30

Open
mjourard opened this issue May 31, 2019 · 7 comments
Open

Add Stub File For IDE Autocomplete #30

mjourard opened this issue May 31, 2019 · 7 comments

Comments

@mjourard
Copy link

It would be great if there was a stubfile such as https://github.com/JetBrains/phpstorm-stubs/blob/master/redis/Redis.php

This would make using the extension much more user-friendly

@mjourard
Copy link
Author

mjourard commented May 31, 2019

Something like this:

<?php
/**
 * Helper autocomplete for php memprof extension
 */


/**
 * Returns whether memprof is enabled.
 * @return bool
 */
function memprof_enabled() {}

/**
 * Enables memprof and start tracking memory allocations. Note: any memory allocation made before this call is ignored.
 *
 */
function memprof_enable() {}


/**
 * Disables memprof and forget previous allocations.
 *
 */
function memprof_disable() {}


/**
 * The memprof_dump_callgrind function dumps the current memory usage to a stream in callgrind format. The file can then be read with tools such as KCacheGrind or QCacheGrind.
 *
 * Usage: memprof_dump_callgrind(fopen("output", "w"));
 */
function memprof_dump_callgrind(resource $stream) {}


/**
 * The memprof_dump_pprof function dumps the current memory usage to a stream in pprof format.
 * Usage: memprof_dump_pprof(fopen("profile.heap", "w"));
 * The file can be visualized using google-perftools's pprof tool.
 *
 * Display annotated call-graph in web browser or in gv:
 *
 * $ pprof --web profile.heap
 * $ # or:
 * $ pprof --gv profile.heap
 * pprof call-graph screenshot
 *
 * Output one line per function, sorted by own memory usage:
 *
 * $ pprof --text profile.heap
 */
function memprof_dump_pprof(resource $stream) {}


/**
 * Usage: $dump = memprof_dump_array();
 * The dump exposes the following information:
 *
 * Inclusive and exclusive memory usage of functions (counting only the memory that has is still in use when memprof_dump_array is called)
 * Inclusive and exclusive blocks count of functions (number of allocated; counting only the blocks that are still in use when memprof_dump_array is called)
 * The data is presented in call stacks. This way, if a function is called from multiple places, it is possible to see which call path caused it to leak the most memory
 * Example output:
 *
 * Array
 * (
 *   [memory_size] => 11578
 *   [blocks_count] => 236
 *   [memory_size_inclusive] => 10497691
 *   [blocks_count_inclusive] => 244
 *   [calls] => 1
 *   [called_functions] => Array
 *     (
 *       [main] => Array
 *         (
 *           [memory_size] => 288
 *           [blocks_count] => 3
 *           [memory_size_inclusive] => 10486113
 *           [blocks_count_inclusive] => 8
 *           [calls] => 1
 *           [called_functions] => Array
 *             (
 *               [a] => Array
 *                 (
 *                   [memory_size] => 4
 *                   [blocks_count] => 1
 *                   [memory_size_inclusive] => 10485825
 *                   [blocks_count_inclusive] => 5
 *                   [calls] => 1
 *                   [called_functions] => Array
 *                     (
 *                       [b] => Array
 *                         (
 *                           [memory_size] => 10485821
 *                           [blocks_count] => 4
 *                           [memory_size_inclusive] => 10485821
 *                           [blocks_count_inclusive] => 4
 *                           [calls] => 1
 *                           [called_functions] => Array
 *                             (
 *                               [str_repeat] => Array
 *                                 (
 *                                   [memory_size] => 0
 *                                   [blocks_count] => 0
 *                                   [memory_size_inclusive] => 0
 *                                   [blocks_count_inclusive] => 0
 *                                   [calls] => 1
 *                                   [called_functions] => Array
 *                                     (
 *                                     )
 *                                 )
 *                             )
 *                         )
 *                     )
 *                 )
 *               [memprof_dump_array] => Array
 *                 (
 *                   [memory_size] => 0
 *                   [blocks_count] => 0
 *                   [memory_size_inclusive] => 0
 *                   [blocks_count_inclusive] => 0
 *                   [calls] => 1
 *                   [called_functions] => Array
 *                     (
 *                     )
 *                 )
 *             )
 *         )
 *     )
 * )
 *
 * @return array
 */
function memprof_dump_array() {}

@arnaud-lb
Copy link
Owner

Good idea. Would you contribute this ? What is the best location to place these stubs ? Maybe phpstorm-stubs directly ?

@mjourard
Copy link
Author

mjourard commented Jun 3, 2019

RE in phpstorm-stubs directly, I would agree with you but I can't get their tests to pass in master on my machine and I think that's a requirement for them to accept a PR.

For reference, I did the same commands as their travis build and was still getting 5 failures each time :/

@arnaud-lb
Copy link
Owner

It might be caused by a difference in your environment ? Maybe try to submit a PR anyway

@remicollet
Copy link
Contributor

@arnaud-lb side note, you can also take benefit of PHP 8 new feature, maintain a stub.php and generate arginfo from it (using PHP 8, but usable with older versions).

@arnaud-lb
Copy link
Owner

This looks convenient, I need to try that

@remicollet
Copy link
Contributor

This looks convenient, I need to try that

See or #56 (partial, as aliased functions not handled)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants