Skip to content

Instantly share code, notes, and snippets.

@ingenthr
Last active March 22, 2017 06:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ingenthr/6116473 to your computer and use it in GitHub Desktop.
Save ingenthr/6116473 to your computer and use it in GitHub Desktop.
Various DTrace scripts for memcached

These are various scripts I've written in the past for tracing through memcached

LICENSE

The MIT License (MIT)

Copyright (c) 2013, Matt Ingenthron

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#!/usr/sbin/dtrace -Zqs
# The MIT License (MIT)
#
# Copyright (c) 2013, Matt Ingenthron
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
BEGIN
{
start = timestamp;
}
memcached*::command-get
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-set
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-add
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-replace
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-prepend
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-append
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-cas
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-delete
{
@hotfound[copyinstr(arg1, arg2)] = count();
}
memcached*::command-get
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-set
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-add
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-replace
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-prepend
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-append
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-cas
/ (signed int)arg3 == -1 /
{
@hotmissing[copyinstr(arg1, arg2)] = count();
}
memcached*::command-*
{
@ops[probename] = count();
}
memcached*::command-*
/ (signed int) arg3 == -1 /
{
@opsnotfound[probename] = count();
}
profile:::tick-3sec
{
trunc(@hotfound, 20);
trunc(@hotmissing, 20);
normalize(@hotfound, (timestamp - start) / 1000000000);
normalize(@hotmissing, (timestamp - start) / 1000000000);
normalize(@ops, (timestamp - start) / 1000000000);
normalize(@opsnotfound, (timestamp - start) / 1000000000);
printf("BEGIN\n");
printf("\nhotfound");
printa(@hotfound);
printf("\nhotmissing");
printa(@hotmissing);
printf("\nops");
printa(@ops);
printf("\nopsnotfound");
printa(@opsnotfound);
printf("END\n");
clear(@hotfound);
clear(@hotmissing);
clear(@ops);
clear(@opsnotfound);
start = timestamp;
}
#!/usr/sbin/dtrace -Zs
# The MIT License (MIT)
#
# Copyright (c) 2013, Matt Ingenthron
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
/*
* Show the flow through memcached with the next operation.
*
* This is mostly used to figure out what else to poke later when hunting
* certain kinds of operations.
*
* Requires the pid as an argument
*
*/
#pragma D option flowindent
memcached*::process-command-start
{
self->traceme = 1;
}
pid$1:::entry,
pid$1:::return
/ self->traceme /
{
}
memcached*::process-command-end
/ self->traceme /
{
self->traceme = 0;
exit(0)
}
#!/usr/sbin/dtrace -Zqs
# The MIT License (MIT)
#
# Copyright (c) 2013, Matt Ingenthron
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
/*
* show memcached keys as they're retrieved via either an ascii
* or binary get operation
*/
memcached*::command-get
/ (signed int) arg3 != -1 /
{
printf("get %s, FOUND KEY\n", copyinstr(arg1, arg2));
}
memcached*::command-get
/ (signed int) arg3 == -1 /
{
printf("get %s, NOT FOUND\n", copyinstr(arg1, arg2));
}
memcached*::command-add
/ (signed int) arg3 != -1 /
{
printf("add %s, FOUND KEY\n", copyinstr(arg1, arg2));
}
memcached*::command-add
/ (signed int) arg3 == -1 /
{
printf("add %s, NOT FOUND\n", copyinstr(arg1, arg2));
}
memcached*::command-replace
/ (signed int) arg3 != -1 /
{
printf("replace %s, FOUND KEY\n", copyinstr(arg1, arg2));
}
memcached*::command-replace
/ (signed int) arg3 == -1 /
{
printf("replace %s, NOT FOUND\n", copyinstr(arg1, arg2));
}
memcached*::command-set
/ (signed int) arg3 != -1 /
{
printf("set %s, FOUND KEY, STORED\n", copyinstr(arg1, arg2));
}
memcached*::command-set
/ (signed int) arg3 == -1 /
{
printf("set %s, NOT FOUND, STORED\n", copyinstr(arg1, arg2));
}
memcached*::command-incr
{
printf("incr %s, FOUND KEY, %d\n", copyinstr(arg1, arg2), arg3);
}
memcached*::command-decr
{
printf("decr %s, FOUND KEY, %d\n", copyinstr(arg1, arg2), arg3);
}
#!/usr/sbin/dtrace -Zs
# The MIT License (MIT)
#
# Copyright (c) 2013, Matt Ingenthron
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
/*
* Show aggregated operations on a 1 second interval.
*
*/
BEGIN
{
start = timestamp;
}
memcached*::command-*
{
@ops[probename] = count();
}
memcached*::command-*
/ (signed int) arg3 == -1 /
{
@opsnotfound[probename] = count();
}
profile:::tick-1sec
{
printf("BEGIN\n");
normalize(@ops, (timestamp - start) / 1000000000);
printa(@ops);
normalize(@opsnotfound, (timestamp - start) / 1000000000);
printa(@opsnotfound);
printf("END\n");
clear(@ops);
clear(@opsnotfound);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment