feat: 能耗监控添加忽略列表 详见monitor.yml

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
2016-07-16 22:24:43 +08:00
parent 08fc991e85
commit c282213d02
7 changed files with 18 additions and 10 deletions

View File

@ -59,9 +59,6 @@ public class Yum extends JavaPlugin {
new VersionChecker(this);
YumAPI.updateRepo(Bukkit.getConsoleSender());
YumAPI.updateCheck(Bukkit.getConsoleSender());
if (ConfigManager.i().isMonitorEnable()) {
YumAPI.updateInject();
}
}
@Override

View File

@ -106,7 +106,7 @@ public class YumAPI {
* 插件
*/
public static void inject(final Plugin plugin) {
if (plugin.isEnabled()) {
if (plugin.isEnabled() && !ConfigManager.i().getMonitorIgnoreList().contains(plugin.getName())) {
CommandInjector.inject(plugin);
ListenerInjector.inject(plugin);
TaskInjector.inject(plugin);

View File

@ -40,6 +40,7 @@ public class MonitorCommand implements HandlerCommands {
private final String total = "§6总耗时: §a%.2f毫秒 ";
private final String count = "§6执行次数: §b%s次 ";
private final String avg = "§6平均耗时: §d%.5f毫秒!";
private final String avg_warn = "§6平均耗时: §c%.5f毫秒!";
private final String p_n_f = prefix + "§c插件 §b%s §c不存在!";
private final double um = 1000000.0;
@ -127,7 +128,8 @@ public class MonitorCommand implements HandlerCommands {
str.append(String.format(total, eventTotalTime.get(event) / um));
str.append(String.format(count, eventCount.get(event)));
if (eventCount.get(event) != 0) {
str.append(String.format(avg, eventTotalTime.get(event) / um / eventCount.get(event)));
final double avgTime = eventTotalTime.get(event) / um / eventCount.get(event);
str.append(String.format(avgTime < 10 ? avg : avg_warn, avgTime));
}
e.getSender().sendMessage(str.toString());
}

View File

@ -15,6 +15,7 @@ import org.bukkit.plugin.TimedRegisteredListener;
import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.managers.ConfigManager;
public class ListenerInjector implements EventExecutor {
private final String prefix = "§6[§bYum §a事件监控§6] ";
@ -70,7 +71,7 @@ public class ListenerInjector implements EventExecutor {
final long end = System.nanoTime();
final String en = event.getEventName();
final long lag = end - start;
if (lag / 1000000 > 10) {
if (lag / 1000000 > 10 && !ConfigManager.i().getMonitorIgnoreList().contains(plugin.getName())) {
PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时§c耗时 §4" + lag / 1000000 + "ms!");
}
if (eventTotalTime.containsKey(en)) {

View File

@ -40,6 +40,10 @@ public class ConfigManager {
return config.getStringList("ignorelist");
}
public List<String> getMonitorIgnoreList() {
return monitor.getStringList(IGNORE);
}
public List<String> getNetworkBlackList() {
return network.getStringList(BLACK);
}
@ -96,5 +100,6 @@ public class ConfigManager {
setop.reload();
network.reload();
thread.reload();
monitor.reload();
}
}

View File

@ -3,7 +3,10 @@
############################
#配置版本号 请勿修改!!!
Version: 1.0
Version: 1.1
#是否开启
Enable: true
Enable: true
#忽略检测列表
Ignore:
- Essentials