You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by mo...@apache.org on 2017/03/21 20:36:52 UTC

reef git commit: [REEF-1629] Move ProfilingEnabled from REEFEnvironment to WakeProfiler

Repository: reef
Updated Branches:
  refs/heads/master 3cca11846 -> 11201cbdc


[REEF-1629] Move ProfilingEnabled from REEFEnvironment to WakeProfiler

JIRA: [REEF-1629](https://issues.apache.org/jira/browse/REEF-1629)

Closes #1271


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/11201cbd
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/11201cbd
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/11201cbd

Branch: refs/heads/master
Commit: 11201cbdc5bdf588d0f8f3804d33a52dd0f160da
Parents: 3cca118
Author: Shouheng Yi <sh...@microsoft.com>
Authored: Mon Mar 20 12:25:56 2017 -0700
Committer: Sergiy Matusevych <mo...@apache.org>
Committed: Tue Mar 21 12:51:26 2017 -0700

----------------------------------------------------------------------
 .../reef/runtime/common/REEFEnvironment.java    | 12 +---
 .../reef/wake/profiler/ProfilerState.java       | 58 ++++++++++++++++++++
 2 files changed, 60 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/11201cbd/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/REEFEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/REEFEnvironment.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/REEFEnvironment.java
index d643ebf..3d3ae67 100644
--- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/REEFEnvironment.java
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/REEFEnvironment.java
@@ -26,12 +26,11 @@ import org.apache.reef.tang.Configuration;
 import org.apache.reef.tang.Configurations;
 import org.apache.reef.tang.Injector;
 import org.apache.reef.tang.Tang;
-import org.apache.reef.tang.annotations.Name;
-import org.apache.reef.tang.annotations.NamedParameter;
 import org.apache.reef.tang.exceptions.InjectionException;
 import org.apache.reef.util.EnvironmentUtils;
 import org.apache.reef.util.REEFVersion;
 import org.apache.reef.wake.profiler.WakeProfiler;
+import org.apache.reef.wake.profiler.ProfilerState;
 import org.apache.reef.wake.time.Clock;
 
 import java.util.logging.Level;
@@ -44,13 +43,6 @@ import java.util.logging.Logger;
  */
 public final class REEFEnvironment implements Runnable, AutoCloseable {
 
-  /**
-   * Parameter to enable Wake network profiling. By default profiling is disabled.
-   * TODO[REEF-1629] Move that parameter and related code into Wake package.
-   */
-  @NamedParameter(doc = "If true, profiling will be enabled", short_name = "profiling", default_value = "false")
-  private static final class ProfilingEnabled implements Name<Boolean> { }
-
   private static final Logger LOG = Logger.getLogger(REEFEnvironment.class.getName());
 
   private static final String CLASS_NAME = REEFEnvironment.class.getCanonicalName();
@@ -83,7 +75,7 @@ public final class REEFEnvironment implements Runnable, AutoCloseable {
 
     final Injector injector = TANG.newInjector(config);
 
-    if (injector.getNamedInstance(ProfilingEnabled.class)) {
+    if (ProfilerState.isProfilingEnabled(injector)) {
       final WakeProfiler profiler = new WakeProfiler();
       ProfilingStopHandler.setProfiler(profiler);
       injector.bindAspect(profiler);

http://git-wip-us.apache.org/repos/asf/reef/blob/11201cbd/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/profiler/ProfilerState.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/profiler/ProfilerState.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/profiler/ProfilerState.java
new file mode 100644
index 0000000..74148b9
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/profiler/ProfilerState.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.reef.wake.profiler;
+
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+/**
+ * A class that contains parameters and states for wake profiler.
+ */
+public final class ProfilerState {
+
+  private ProfilerState() {}
+
+  /**
+   * Parameter to enable Wake network profiling. By default profiling is disabled.
+   */
+  @NamedParameter(doc = "If true, profiling will be enabled", short_name = "profiling", default_value = "false")
+  private static final class ProfilingEnabled implements Name<Boolean> { }
+
+  /**
+   * Gets the class of the NamedParameter ProfilingEnabled.
+   *
+   * @return Class of ProflingEnabled which should be Name<Boolean>
+   */
+  private static Class<? extends Name<Boolean>> getProfilingEnabledClass() {
+    return ProfilingEnabled.class;
+  }
+
+  /**
+   * Checks if profiling is enabled.
+   *
+   * @param injector the tang injector that stores value of ProfilingEnabled.
+   * @return true if profiling is enabled
+   * @throws InjectionException if name resolution fails
+   */
+  public static boolean isProfilingEnabled(final Injector injector) throws InjectionException {
+    return injector.getNamedInstance(getProfilingEnabledClass());
+  }
+}