From: "larry on
That's not really what I'm after. Let me try an example:

function foo($id) {
static $foos = array();

if (empty($foos[$id]) {
$foos[$id] = load_foo($id);
}
return $foos[$id];
}

When load_foo() is slow (e.g., lots of DB traffic or remote-server calls
or whatever), such caching can have a significant performance boost.
Sometime after foo() has been called 15 times from 30 places in code,
when I get to the end of the request (or just every time I call foo()
would be fine) I want to be able to do something like:

$cost = get_memory_used_by($foos);

So that I can determine how much memory that caching is costing me over
the lifetime of the page, and determine if it's a worthwhile trade-off.

--Larry Garfield

dsiembab01(a)gmail.com wrote:
> function check_memory_usage(&$memory)
> {
> $memory[] = memory_get_usage();
> return $memory;
> }
>
> something like this?
> you can put it wherever you like and returns an array for further
> processing. You could optionally add a second argument to set the index
> to a name and check if the name exists to add 1 to the end of the name
> so your indexes stay maintained.
>
From: Rene Veerman on
global $fooSize = 0;

function foo($id) {
.....
global $fooSize;
if (empty($foos($id)) {
$b = get_memory_usage(true);
$foos[$id] = load_foo($id);
$fooSize+= $b - get_memory_usage(true);
}
....
}
On Wed, Mar 3, 2010 at 8:16 PM, larry(a)garfieldtech.com
<larry(a)garfieldtech.com> wrote:
> That's not really what I'm after.  Let me try an example:
>
> function foo($id) {
>  static $foos = array();
>
>  if (empty($foos[$id]) {
>    $foos[$id] = load_foo($id);
>  }
>  return $foos[$id];
> }
>
> When load_foo() is slow (e.g., lots of DB traffic or remote-server calls or
> whatever), such caching can have a significant performance boost. Sometime
> after foo() has been called 15 times from 30 places in code, when I get to
> the end of the request (or just every time I call foo() would be fine) I
> want to be able to do something like:
>
> $cost = get_memory_used_by($foos);
>
> So that I can determine how much memory that caching is costing me over the
> lifetime of the page, and determine if it's a worthwhile trade-off.
>
> --Larry Garfield
>
> dsiembab01(a)gmail.com wrote:
>>
>> function check_memory_usage(&$memory)
>> {
>>    $memory[] = memory_get_usage();
>>    return $memory;
>> }
>>
>> something like this?
>> you can put it wherever you like and returns an array for further
>> processing. You could optionally add a second argument to set the index to a
>> name and check if the name exists to add 1 to the end of the name so your
>> indexes stay maintained.
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
From: dsiembab01 on
couple questions Larry is this application composed of classes or
straight up no holes barred procedural code?

larry(a)garfieldtech.com wrote:
> That's not really what I'm after. Let me try an example:
>
> function foo($id) {
> static $foos = array();
>
> if (empty($foos[$id]) {
> $foos[$id] = load_foo($id);
> }
> return $foos[$id];
> }
>
> When load_foo() is slow (e.g., lots of DB traffic or remote-server calls
> or whatever), such caching can have a significant performance boost.
> Sometime after foo() has been called 15 times from 30 places in code,
> when I get to the end of the request (or just every time I call foo()
> would be fine) I want to be able to do something like:
>
> $cost = get_memory_used_by($foos);
>
> So that I can determine how much memory that caching is costing me over
> the lifetime of the page, and determine if it's a worthwhile trade-off.
>
> --Larry Garfield
>
> dsiembab01(a)gmail.com wrote:
>> function check_memory_usage(&$memory)
>> {
>> $memory[] = memory_get_usage();
>> return $memory;
>> }
>>
>> something like this?
>> you can put it wherever you like and returns an array for further
>> processing. You could optionally add a second argument to set the
>> index to a name and check if the name exists to add 1 to the end of
>> the name so your indexes stay maintained.
>>
From: "larry on
Currently it's mostly procedural with some components that are OO. I
suspect most of the memory sinks are large arrays (we have a lot of
them), but I am not certain of that. Hence my interest in more accurate
investigation tools.

--Larry Garfield

dsiembab01(a)gmail.com wrote:
> couple questions Larry is this application composed of classes or
> straight up no holes barred procedural code?
>
> larry(a)garfieldtech.com wrote:
>> That's not really what I'm after. Let me try an example:
>>
>> function foo($id) {
>> static $foos = array();
>>
>> if (empty($foos[$id]) {
>> $foos[$id] = load_foo($id);
>> }
>> return $foos[$id];
>> }
>>
>> When load_foo() is slow (e.g., lots of DB traffic or remote-server
>> calls or whatever), such caching can have a significant performance
>> boost. Sometime after foo() has been called 15 times from 30 places in
>> code, when I get to the end of the request (or just every time I call
>> foo() would be fine) I want to be able to do something like:
>>
>> $cost = get_memory_used_by($foos);
>>
>> So that I can determine how much memory that caching is costing me
>> over the lifetime of the page, and determine if it's a worthwhile
>> trade-off.
>>
>> --Larry Garfield
>>
>> dsiembab01(a)gmail.com wrote:
>>> function check_memory_usage(&$memory)
>>> {
>>> $memory[] = memory_get_usage();
>>> return $memory;
>>> }
>>>
>>> something like this?
>>> you can put it wherever you like and returns an array for further
>>> processing. You could optionally add a second argument to set the
>>> index to a name and check if the name exists to add 1 to the end of
>>> the name so your indexes stay maintained.
>>>
>
From: dsiembab01 on
you could read this
http://xdebug.org/docs/execution_trace
and then parse trace files to get the memory usage
create a global to store user functions, I think user function do not
populate get_defined_functions(); until the function is called;
$t = get_defined_functions();
$userFunctions = $t['user'];
$file = xdebug_get_tracefile_name();
parse the file and then create a function to call the said variable.
I think you can figure it out.
larry(a)garfieldtech.com wrote:
> Currently it's mostly procedural with some components that are OO. I
> suspect most of the memory sinks are large arrays (we have a lot of
> them), but I am not certain of that. Hence my interest in more accurate
> investigation tools.
>
> --Larry Garfield
>
> dsiembab01(a)gmail.com wrote:
>> couple questions Larry is this application composed of classes or
>> straight up no holes barred procedural code?
>>
>> larry(a)garfieldtech.com wrote:
>>> That's not really what I'm after. Let me try an example:
>>>
>>> function foo($id) {
>>> static $foos = array();
>>>
>>> if (empty($foos[$id]) {
>>> $foos[$id] = load_foo($id);
>>> }
>>> return $foos[$id];
>>> }
>>>
>>> When load_foo() is slow (e.g., lots of DB traffic or remote-server
>>> calls or whatever), such caching can have a significant performance
>>> boost. Sometime after foo() has been called 15 times from 30 places
>>> in code, when I get to the end of the request (or just every time I
>>> call foo() would be fine) I want to be able to do something like:
>>>
>>> $cost = get_memory_used_by($foos);
>>>
>>> So that I can determine how much memory that caching is costing me
>>> over the lifetime of the page, and determine if it's a worthwhile
>>> trade-off.
>>>
>>> --Larry Garfield
>>>
>>> dsiembab01(a)gmail.com wrote:
>>>> function check_memory_usage(&$memory)
>>>> {
>>>> $memory[] = memory_get_usage();
>>>> return $memory;
>>>> }
>>>>
>>>> something like this?
>>>> you can put it wherever you like and returns an array for further
>>>> processing. You could optionally add a second argument to set the
>>>> index to a name and check if the name exists to add 1 to the end of
>>>> the name so your indexes stay maintained.
>>>>
>>
First  |  Prev  | 
Pages: 1 2
Prev: gentoo php
Next: basic authentication and redirection