|
1 | | -package com.laytonsmith.core.functions; |
2 | | - |
3 | | -import com.laytonsmith.annotations.api; |
4 | | -import com.laytonsmith.core.CHVersion; |
5 | | -import com.laytonsmith.core.Prefs; |
6 | | -import com.laytonsmith.core.Static; |
7 | | -import com.laytonsmith.core.constructs.CVoid; |
8 | | -import com.laytonsmith.core.constructs.Construct; |
9 | | -import com.laytonsmith.core.constructs.Target; |
10 | | -import com.laytonsmith.core.environments.Environment; |
11 | | -import com.laytonsmith.core.exceptions.CRE.CRESecurityException; |
12 | | -import com.laytonsmith.core.exceptions.CRE.CREThrowable; |
13 | | -import com.laytonsmith.core.exceptions.ConfigRuntimeException; |
14 | | -import java.io.File; |
15 | | -import java.io.IOException; |
16 | | -import java.util.logging.Level; |
17 | | -import java.util.logging.Logger; |
18 | | -import org.perf4j.StopWatch; |
19 | | - |
20 | | -/** |
21 | | - * |
22 | | - * |
23 | | - */ |
24 | | -public class Performance { |
25 | | - |
26 | | - public static boolean PERFORMANCE_LOGGING = false; |
27 | | - |
28 | | - public static String docs() { |
29 | | - return "This class provides functions for hooking into CommandHelper's powerful Performance measuring. To use the functions, you must have" |
30 | | - + " allow-profiling option set to true in your preferences file."; |
31 | | - } |
32 | | - |
33 | | - public static void DoLog(File root, StopWatch stopWatch) { |
34 | | - try { |
35 | | - Static.QuickAppend(Static.profilingLogFile(root), "start[" + stopWatch.getStartTime() + "] time[" + stopWatch.getElapsedTime() + "] " |
36 | | - + "tag[" + stopWatch.getTag() + "]\n"); |
37 | | - } catch(IOException ex) { |
38 | | - Logger.getLogger(Performance.class.getName()).log(Level.SEVERE, null, ex); |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - @api |
43 | | - public static class enable_performance_logging extends AbstractFunction { |
44 | | - |
45 | | - @Override |
46 | | - public String getName() { |
47 | | - return "enable_performance_logging"; |
48 | | - } |
49 | | - |
50 | | - @Override |
51 | | - public Integer[] numArgs() { |
52 | | - return new Integer[]{1}; |
53 | | - } |
54 | | - |
55 | | - @Override |
56 | | - public String docs() { |
57 | | - return "void {boolean} Enables performance logging. The allow-profiling option must be set to true in your preferences file," |
58 | | - + " and play-dirty mode must be active. If allow-profiling is set to false, a SecurityException is thrown." |
59 | | - + " The debug filters are used by the performance logger, if you choose to filter through the events." |
60 | | - + " See the documenation" |
61 | | - + " for more details on performance logging."; |
62 | | - } |
63 | | - |
64 | | - @Override |
65 | | - public Class<? extends CREThrowable>[] thrown() { |
66 | | - return new Class[]{CRESecurityException.class}; |
67 | | - } |
68 | | - |
69 | | - @Override |
70 | | - public boolean isRestricted() { |
71 | | - return true; |
72 | | - } |
73 | | - |
74 | | - @Override |
75 | | - public CHVersion since() { |
76 | | - return CHVersion.V3_3_0; |
77 | | - } |
78 | | - |
79 | | - @Override |
80 | | - public Boolean runAsync() { |
81 | | - return null; |
82 | | - } |
83 | | - |
84 | | - @Override |
85 | | - public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { |
86 | | - if(!Prefs.AllowProfiling()) { |
87 | | - throw new CRESecurityException("allow-profiling is currently off, you must set it to true in your preferences.", t); |
88 | | - } |
89 | | - PERFORMANCE_LOGGING = Static.getBoolean(args[0], t); |
90 | | - return CVoid.VOID; |
91 | | - } |
92 | | - |
93 | | - } |
94 | | -} |
| 1 | +package com.laytonsmith.core.functions; |
| 2 | + |
| 3 | +import com.laytonsmith.annotations.api; |
| 4 | +import com.laytonsmith.core.CHVersion; |
| 5 | +import com.laytonsmith.core.Prefs; |
| 6 | +import com.laytonsmith.core.Static; |
| 7 | +import com.laytonsmith.core.constructs.CVoid; |
| 8 | +import com.laytonsmith.core.constructs.Construct; |
| 9 | +import com.laytonsmith.core.constructs.Target; |
| 10 | +import com.laytonsmith.core.environments.Environment; |
| 11 | +import com.laytonsmith.core.exceptions.CRE.CRESecurityException; |
| 12 | +import com.laytonsmith.core.exceptions.CRE.CREThrowable; |
| 13 | +import com.laytonsmith.core.exceptions.ConfigRuntimeException; |
| 14 | +import java.io.File; |
| 15 | +import java.io.IOException; |
| 16 | +import java.util.logging.Level; |
| 17 | +import java.util.logging.Logger; |
| 18 | +import org.perf4j.StopWatch; |
| 19 | + |
| 20 | +/** |
| 21 | + * |
| 22 | + * |
| 23 | + */ |
| 24 | +public class Performance { |
| 25 | + |
| 26 | + public static boolean PERFORMANCE_LOGGING = false; |
| 27 | + |
| 28 | + public static String docs() { |
| 29 | + return "This class provides functions for hooking into CommandHelper's powerful Performance measuring. To use the functions, you must have" |
| 30 | + + " allow-profiling option set to true in your preferences file."; |
| 31 | + } |
| 32 | + |
| 33 | + public static void DoLog(File root, StopWatch stopWatch) { |
| 34 | + try { |
| 35 | + Static.QuickAppend(Static.profilingLogFile(root), "start[" + stopWatch.getStartTime() + "] time[" + stopWatch.getElapsedTime() + "] " |
| 36 | + + "tag[" + stopWatch.getTag() + "]\n"); |
| 37 | + } catch(IOException ex) { |
| 38 | + Logger.getLogger(Performance.class.getName()).log(Level.SEVERE, null, ex); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @api |
| 43 | + public static class enable_performance_logging extends AbstractFunction { |
| 44 | + |
| 45 | + @Override |
| 46 | + public String getName() { |
| 47 | + return "enable_performance_logging"; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public Integer[] numArgs() { |
| 52 | + return new Integer[]{1}; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public String docs() { |
| 57 | + return "void {boolean} Enables performance logging. The allow-profiling option must be set to true in your preferences file," |
| 58 | + + " and play-dirty mode must be active. If allow-profiling is set to false, a SecurityException is thrown." |
| 59 | + + " The debug filters are used by the performance logger, if you choose to filter through the events." |
| 60 | + + " See the documenation" |
| 61 | + + " for more details on performance logging."; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public Class<? extends CREThrowable>[] thrown() { |
| 66 | + return new Class[]{CRESecurityException.class}; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public boolean isRestricted() { |
| 71 | + return true; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public CHVersion since() { |
| 76 | + return CHVersion.V3_3_0; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public Boolean runAsync() { |
| 81 | + return null; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { |
| 86 | + if(!Prefs.AllowProfiling()) { |
| 87 | + throw new CRESecurityException("allow-profiling is currently off, you must set it to true in your preferences.", t); |
| 88 | + } |
| 89 | + PERFORMANCE_LOGGING = Static.getBoolean(args[0], t); |
| 90 | + return CVoid.VOID; |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | +} |
0 commit comments