| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Agent |
|
| 0.0;0 | ||||
| Agent$1 |
|
| 0.0;0 |
| 1 | /** | |
| 2 | * Copyright (2008) Schibsted Søk AS | |
| 3 | * This file is part of Sesat Commons. | |
| 4 | * | |
| 5 | * Sesat Commons is free software: you can redistribute it and/or modify | |
| 6 | * it under the terms of the GNU Lesser General Public License as published by | |
| 7 | * the Free Software Foundation, either version 3 of the License, or | |
| 8 | * (at your option) any later version. | |
| 9 | * | |
| 10 | * Sesat Commons is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public License | |
| 16 | * along with Sesat Commons. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | * | |
| 18 | */ | |
| 19 | ||
| 20 | package no.sesat; | |
| 21 | ||
| 22 | import java.lang.instrument.*; | |
| 23 | ||
| 24 | import no.sesat.Interpreter; | |
| 25 | ||
| 26 | 0 | public class Agent { |
| 27 | public static void premain(String agentArgs, final Instrumentation inst) { | |
| 28 | 0 | Interpreter.addFunction("loaded-classes", new Interpreter.Function() { |
| 29 | public String execute(final Interpreter.Context ctx) { | |
| 30 | 0 | String res = "Loaded:\n"; |
| 31 | 0 | for (Class<?> c : inst.getAllLoadedClasses()) { |
| 32 | 0 | if (ctx.length() == 1 && !c.getName().matches(ctx.getArgument(0))) { |
| 33 | 0 | continue; |
| 34 | } | |
| 35 | 0 | long size = inst.getObjectSize(c); |
| 36 | 0 | res += c.getName() + " - " + size + "\n" + c.getClassLoader() + "\n\n"; |
| 37 | } | |
| 38 | 0 | return res; |
| 39 | } | |
| 40 | ||
| 41 | public String describe() { | |
| 42 | 0 | return "List loaded classes. 'loaded-classes [regexp]'"; |
| 43 | } | |
| 44 | }); | |
| 45 | 0 | } |
| 46 | } |