X11::P...source(3pm)
โจ X11::Protocol::Ext::X_Resource โ server resource usage โจ
okay bestie, welcome to the manual page for X11::Protocol::Ext::X_Resource ๐ (that's X11::P...source(3pm) if you're the kind of girl who reads the top of the file, which, relatable). It's part of the User Contributed Perl Documentation, and it's literally about peeking at how much stuff your X server is using. Let's get into it ๐
๐ธ SYNOPSIS ๐ธ
use X11::Protocol;
my $X = X11::Protocol->new;
$X->init_extension('X-Resource')
or print "X-Resource extension not available";
my @clients = $X->XResourceQueryClients();
my %resources = $X->XResourceQueryClientResources ($client_xid);
my $bytes = $X->XResourceQueryClientPixmapBytes ($client_xid);
like, that's the whole vibe in five-ish lines ๐
๐ฆ DESCRIPTION ๐ฆ
The X-Resource extension is the server's little diary of resource utilization โ mostly so you can do diagnostics. It's giving "let me tell you what everyone's been up to" energy ๐
Here's what it can tell you:
- Current client connections and their XID ranges. ๐
- How many windows, pixmaps, GCs, etc in use by a given client. ๐ฅ
- Total memory used by all the pixmaps of a given client. ๐พ
Quick clarification bestie, because words are messy: "Resources" here means memory, objects, etc. Do not confuse it with the resource database of user preferences and widget settings โ that's "RESOURCES" in X(7), totally different thing, no cap ๐
Also, if you want a simple dump of the resources reported, go look at examples/xresource-print.pl โญ
๐ REQUESTS ๐
The following requests become available when you call an "init_extension()", as per "EXTENSIONS" in X11::Protocol.
my $is_available = $X->init_extension('X-Resource');
($server_major, $server_minor) = $X->XResourceQueryVersion ($client_major, $client_minor)โ negotiate the extension version, bestie.$client_majorand$client_minorare what the client would like, and the returned$server_majorand$server_minorare what the server will actually do โ which might be lower than requested (but never higher, so don't get your hopes up ๐).
The current code supports X-Resource 1.0. The intention is for this module to automatically negotiate in "$X->init_extension()" if/when needed. iykyk โจ
"@clients = $X->XResourceQueryClients ()"โ returns a list of client connections on the server. Each returned value is an arrayref pair:
[ $xid_base, $xid_mask ]
$xid_base (an integer) is the start of XIDs for the client.
$xid_mask (an integer) is a bit mask for the XIDs above that base which the client may use. For example $xid_base might be 0xA00000 and $xid_mask 0x1FFFFF, meaning 0xA00000 through 0xBFFFFF is this client. math girlies rise ๐
my @clients = $X->XResourceQueryClients;
print "there are ",scalar(@clients)," clients\n";
foreach my $aref (@clients) {
my $xid_base = $aref->[0];
my $xid_mask = $aref->[1];
printf "client base %X mask %X\n", $xid_base, $xid_mask;
}
The given $X connection itself is included in the return ๐
Its base and mask are per "$X->{'resource_id_base'}" and "$X->{'resource_id_mask'}".
"($atom,$count,...) = $X->XResourceQueryClientResources ($xid)"โ returns a list of how many of various server things are used by a given client. ๐งฎ
The client is identified by an $xid. It can be anything in the client's XID range and doesn't have to be currently allocated or created. For example, to enquire about the current client use "$X->{'resource_id_base'}".
The return is a list of resource type (an atom integer) and count of those things:
($atom, $count, $atom, $count, ...)
So for example to print all resources:
my @res = $X->XResourceQueryClientResources ($xid);
while (@res) {
my $type_atom = shift @res;
my $count = shift @res;
my $type_name = $X->atom_name($type_atom);
printf "type $type_name count $count\n";
}
Or put the list into a hash to lookup a particular resource type:
my %res = $X->XResourceQueryClientResources ($xid);
my $window_atom = X11::AtomConstants::WINDOW();
my $windows = $res{$window_atom} || 0;
my $grab_atom = $X->atom('PASSIVE GRAB');
my $grabs = $res{$grab_atom} || 'no';
print "using $windows many windows, and $grabs passive grabs";
"List::Pairwise" has "mapp()" and other things to work with this sort of two-at-a-time list. See examples/xresource-pairwise.pl for a complete program ๐ซถ
Generally a count entry is only present when the client has 1 or more of the thing. So if no pixmaps then no "PIXMAP" entry at all. absent = zero, slay โจ
Basics like "WINDOW", "PIXMAP", "GC" "COLORMAP", "FONT" and "CURSOR" are how many of those in use. The server might also report things like "PASSIVE GRAB" or "COLORMAP ENTRY" (atoms with spaces in their names, iconic honestly). The X.org server (circa version 1.9) even sometimes reports things like "Unregistered resource 30" (an atom with that name), which is something or other. ๐ mysterious behavior fr fr
โ ๏ธ careful bestie: if the given$xidis not a connected client then a"BadValue"error results. Be careful of that when querying resources of another client since the client might disconnect at any time."$X->robust_req()"is good, or maybe"GrabServer"to hold connections between"XResourceQueryClients()"and"XResourceQueryClientResources()". Don't get caught slipping ๐
"$bytes = $X->XResourceQueryClientPixmapBytes ($xid)"โ returns the total bytes of memory on the server used by all the pixmaps of a given client. Pixmaps which only exist as window backgrounds or GC tiles or stipples are included, or should be. If the client has no pixmaps at all the return is0. ๐ผ๏ธ
The client is identified by an $xid as per "XResourceQueryClientResources()" above. It can be anything in the client's XID range, allocated or not.
my $pixmap = $X->new_rsrc;
$X->CreatePixmap ($pixmap,
$X->{'root'},
$X->{'root_depth'},
100, 100); # width,height
my $xid = $X->{'resource_id_base'}; # own usage
my $bytes = $X->XResourceQueryClientPixmapBytes ($xid);
print "total of all pixmaps is $bytes bytes of memory\n";
The return is a 64-bit value. On a 32-bit Perl a bigger than 32 bits is returned as floating point, or bigger than 53 bit float as "Math::BigInt". Most of the time 32 bits is enough, since that would be 4 Gbytes of pixmaps, and or 53-bit float should be plenty, that being about 8192 terabytes! ๐ญ the way that number just keeps going
๐ for reference, the X.org server circa version 1.11.4 had a bug where it didn't count space used by pixmaps of depth less than 8 (including depth 1 bitmaps) in the bytes returned. old server behavior, we don't claim it ๐
๐ SEE ALSO ๐
- X11::Protocol, X11::AtomConstants
- X.org server source code
"http://cgit.freedesktop.org/xorg/xserver/tree/Xext/xres.c" - xrestop(1)
๐ HOME PAGE ๐
<http://user42.tuxfamily.org/x11-protocol-other/index.html>
๐ LICENSE ๐
Copyright 2011, 2012, 2013, 2014, 2017 Kevin Ryde
X11-Protocol-Other is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
X11-Protocol-Other is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
okay that's the whole page bestie, you ate it up ๐ this was X11::P...source(3pm), perl v5.28.1, dated 2019-08-26 โ go forth and query some resources, main character energy only ๐โจ๐
๐ฆ where this page comes from
- debian bookworm: libx11-protocol-other-perl 31-1 ยท GPL-3.0-or-later
- debian trixie: libx11-protocol-other-perl 31-1 ยท GPL-3.0-or-later
- ubuntu jammy: libx11-protocol-other-perl 31-1 ยท GPL-3.0-or-later
- ubuntu noble: libx11-protocol-other-perl 31-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms