提交 931effb6 编写于 作者: wu-sheng's avatar wu-sheng

Output all instrumented classes into physical files.

上级 d12c28b8
......@@ -52,6 +52,12 @@ public class Config {
* memory cost estimated.
*/
public static int SPAN_LIMIT_PER_SEGMENT = 300;
/**
* If true, skywalking agent will save all instrumented classes files. And you can send them to skywalking team,
* in order to resolve compatible problem.
*/
public static boolean IS_OPEN_DEBUGGING_CLASS = false;
}
public static class Collector {
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* @author wu-sheng
*/
public enum InstrumentDebuggingClass {
INSTANCE;
private static final ILog logger = LogManager.getLogger(InstrumentDebuggingClass.class);
private File debuggingClassesRootPath;
public void log(TypeDescription typeDescription, DynamicType dynamicType) {
if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) {
return;
}
/**
* try to do I/O things in synchronized way, to avoid unexpected situations.
*/
synchronized (INSTANCE) {
try {
if (debuggingClassesRootPath == null) {
try {
debuggingClassesRootPath = new File(AgentPackagePath.getPath(), "/debugging");
if (!debuggingClassesRootPath.exists()) {
debuggingClassesRootPath.mkdir();
}
} catch (AgentPackageNotFoundException e) {
logger.error(e, "Can't find the root path for creating /debugging folder.");
}
}
File newClassFileFolder = new File(debuggingClassesRootPath, typeDescription.getPackage().getActualName().replaceAll("\\.", "/"));
if (!newClassFileFolder.exists()) {
newClassFileFolder.mkdirs();
}
File newClassFile = new File(newClassFileFolder, typeDescription.getSimpleName() + ".class");
FileOutputStream fos = null;
try {
if (newClassFile.exists()) {
newClassFile.delete();
}
newClassFile.createNewFile();
fos = new FileOutputStream(newClassFile);
fos.write(dynamicType.getBytes());
fos.flush();
} catch (IOException e) {
logger.error(e, "Can't save class {} to file." + typeDescription.getActualName());
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
} catch (Throwable t) {
logger.error(t, "Save debugging classes fail.");
}
}
}
}
......@@ -18,6 +18,8 @@
package org.skywalking.apm.agent;
import java.lang.instrument.Instrumentation;
import java.util.List;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
......@@ -26,10 +28,11 @@ import org.skywalking.apm.agent.core.boot.ServiceManager;
import org.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.agent.core.plugin.*;
import java.lang.instrument.Instrumentation;
import java.util.List;
import org.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
import org.skywalking.apm.agent.core.plugin.EnhanceContext;
import org.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.skywalking.apm.agent.core.plugin.PluginException;
import org.skywalking.apm.agent.core.plugin.PluginFinder;
/**
* The main entrance of sky-waking agent,
......@@ -103,6 +106,8 @@ public class SkyWalkingAgent {
if (logger.isDebugEnable()) {
logger.debug("On Transformation class {}.", typeDescription.getName());
}
InstrumentDebuggingClass.INSTANCE.log(typeDescription, dynamicType);
}
@Override
......@@ -113,7 +118,7 @@ public class SkyWalkingAgent {
@Override public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded,
Throwable throwable) {
logger.error("Failed to enhance class " + typeName, throwable);
logger.error("Enhance class " + typeName + " error.", throwable);
}
@Override
......
......@@ -12,6 +12,10 @@ agent.application_code=Your_ApplicationName
# Ignore the segments if their operation names start with these suffix.
# agent.ignore_suffix=.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg
# If true, skywalking agent will save all instrumented classes files. And you can send them to skywalking team,
# in order to resolve compatible problem.
# agent.is_open_debugging_class = true
# Server addresses.
# Mapping to `agent_server/jetty/port` in `config/application.yml` of Collector.
# Examples:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册