Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
efae6b73
Commit
efae6b73
authored
11 years ago
by
Per Hedbor
Browse files
Options
Downloads
Patches
Plain Diff
Updated pp_memory_usge to use the new fields in memory_usage.
Also format it slightly differently.
parent
c848fdb2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Debug.pmod/module.pmod
+72
-11
72 additions, 11 deletions
lib/modules/Debug.pmod/module.pmod
with
72 additions
and
11 deletions
lib/modules/Debug.pmod/module.pmod
+
72
−
11
View file @
efae6b73
...
...
@@ -5,6 +5,7 @@ constant verify_internals = _verify_internals;
constant memory_usage = _memory_usage;
constant gc_status = _gc_status;
constant describe_program = _describe_program;
constant size_object = _size_object;
#if constant(_debug)
// These functions require --with-rtldebug.
...
...
@@ -32,29 +33,89 @@ constant dump_dmalloc_locations = _dump_dmalloc_locations;
constant compiler_trace = _compiler_trace;
#endif
/* significantly more compact version of size2string */
private string mi2sz( int i )
{
constant un = ({ "", "k","M","G","T" });
float x = (float)i;
int u = 0;
do
{
x /= 1024.0;
u++;
} while( x > 1000.0 );
return sprintf("%.1f%s",x,un[u]);
}
//! Returns a pretty printed version of the
//! output from @[memory_usage].
string pp_memory_usage() {
string ret=" Num Bytes\n";
mapping mu = memory_usage();
foreach( ({ "array", "callable", "callback", "frame", "mapping",
"multiset", "object", "program", "string" }),
string what) {
ret += sprintf("%-8s %6d %6d (%s)\n", what, mu["num_"+what+"s"],
mu[what+"_bytes"], String.int2size(mu[what+"_bytes"]));
}
return ret;
string ret=" Num Bytes\n";
mapping q = _memory_usage();
mapping res = ([]), malloc = ([]);
foreach( q; string key; int val )
{
mapping in = res;
string sub ;
if( has_suffix( key, "_bytes" ) )
{
sub = "bytes";
key = key[..<6]+"s";
if( key == "mallocs" )
key = "malloc";
}
if( has_prefix( key, "num_" ) )
{
sub = "num";
key = key[4..];
}
if( key == "short_pike_strings" )
key = "strings";
if(key == "free_blocks" || key == "malloc" || key == "malloc_blocks" )
in = malloc;
if( val )
{
if( !in[key] )
in[key] = ([]);
in[key][sub] += val;
}
}
string output_one( mapping res, bool trailer )
{
array output = ({});
foreach( res; string key; mapping what )
output += ({({ what->bytes, what->num, key })});
output = reverse(sort( output ));
string format_row( array x )
{
return sprintf("%-20s %10s %10d\n", x[2], mi2sz(x[0]), x[1] );
};
return
sprintf("%-20s %10s %10s\n", "Type", "Bytes", "Num")+
"-"*(21+11+10)+"\n"+
map( output, format_row )*""+
"-"*(21+11+10)+"\n"+
(trailer?
format_row( ({ Array.sum( column(output,0) ), Array.sum( column(output,1) ), "total" }) ):"");
};
return output_one(res,true) +
"\nMalloc info:\n"+output_one(malloc,false);
}
//! Returns the number of objects of every kind in memory.
mapping(string:int) count_objects() {
mapping(string:int) count_objects()
{
int orig_enabled = Pike.gc_parameters()->enabled;
Pike.gc_parameters( (["enabled":0]) );
mapping(string:int) ret = ([]);
object obj = next_object();
// while( zero_type(_prev(obj)) ) obj=_prev(obj);
while(1) {
object next_obj;
if(catch(next_obj=_next(obj))) break;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment