Ejemplo n.º 1
0
  /**
   * Returns object of class ‘"proc_time"’ which is a numeric vector of length 5, containing the
   * user, system, and total elapsed times for the currently running R process, and the cumulative
   * sum of user and system times of any child processes spawned by it on which it has waited.
   *
   * <p>_The ‘user time’ is the CPU time charged for the execution of user instructions of the
   * calling process. The ‘system time’ is the CPU time charged for execution by the system on
   * behalf of the calling process._
   */
  @Builtin("proc.time")
  public static DoubleVector procTime() {

    DoubleArrayVector.Builder result = new DoubleArrayVector.Builder();
    StringVector.Builder names = new StringVector.Builder();

    long totalCPUTime;
    long userCPUTime;
    long elapsedTime;

    // There doesn't seem to be any platform-independent way of accessing
    // CPU use for the whole JVM process, so we'll have to make do
    // with the timings for the thread we're running on.
    //
    // Additionally, the MX Beans may not be available in all environments,
    // so we need to fallback to app
    try {
      ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
      totalCPUTime = threadMXBean.getCurrentThreadCpuTime();
      userCPUTime = threadMXBean.getCurrentThreadUserTime();

      RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
      elapsedTime = runtimeMXBean.getUptime();
    } catch (Error e) {
      // ThreadMXBean is not available in all environments
      // Specifically, AppEngine will throw variously SecurityErrors or
      // ClassNotFoundErrors if we try to access these classes
      userCPUTime = totalCPUTime = java.lang.System.nanoTime();
      elapsedTime = new Date().getTime();
    }

    // user.self
    names.add("user.self");
    result.add(userCPUTime / NANOSECONDS_PER_SECOND);

    // sys.self
    names.add("sys.self");
    result.add((totalCPUTime - userCPUTime) / NANOSECONDS_PER_SECOND);

    // elapsed
    // (wall clock time)
    names.add("elapsed");
    result.add(elapsedTime);

    // AFAIK, we don't have any platform independent way of accessing
    // this info.

    // user.child
    names.add("user.child");
    result.add(0);

    // sys.child
    names.add("sys.child");
    result.add(0);

    result.setAttribute(Symbols.NAMES, names.build());
    result.setAttribute(Symbols.CLASS, StringVector.valueOf("proc_time"));
    return result.build();
  }
Ejemplo n.º 2
0
 /**
  * Expand a path name, for example by replacing a leading tilde by the user's home directory (if
  * defined on that platform).
  *
  * @param path
  * @return the expanded path
  */
 @DataParallel
 @Internal("path.expand")
 public static String pathExpand(String path) {
   if (path.startsWith("~/")) {
     return java.lang.System.getProperty("user.home") + path.substring(2);
   } else {
     return path;
   }
 }
Ejemplo n.º 3
0
  @Internal
  public static DoubleVector gc(boolean verbose, boolean reset) {
    try {
      java.lang.System.gc();
    } catch (Exception e) {

    }
    return new DoubleArrayVector();
  }
Ejemplo n.º 4
0
  @Internal("Sys.info")
  public static StringVector sysInfo() {
    StringVector.Builder sb = new StringVector.Builder();
    sb.add(java.lang.System.getProperty("os.name"));
    sb.add(java.lang.System.getProperty("os.version"));
    /*
     * os.build does not exist! maybe we can put jvm info instead?
     *
     */
    sb.add(java.lang.System.getProperty("os.build"));
    try {
      sb.add(InetAddress.getLocalHost().getHostName());
    } catch (Exception e) {
      sb.add("Can not get hostname");
    }
    sb.add(java.lang.System.getProperty("os.arch"));
    /*
     *
     * login.name does not exist!
     */
    sb.add(java.lang.System.getProperty("login.name"));
    sb.add(java.lang.System.getProperty("user.name"));

    sb.setAttribute(
        "names",
        new StringArrayVector(
            "sysname", "release", "version", "nodename", "machine", "login", "user"));
    return (sb.build());
  }
Ejemplo n.º 5
0
 /**
  * <strong>According to the R docs:</strong> a subdirectory of the temporary directory found by
  * the following rule. The environment variables TMPDIR, TMP and TEMP are checked in turn and the
  * first found which points to a writable directory is used: if none succeeds the value of R_USER
  * (see Rconsole) is used. If the path to the directory contains a space in any of the components,
  * the path returned will use the shortnames version of the path.
  *
  * <p>This implementation also returns the value of {@code System.getProperty(java.io.tmpdir) }
  *
  * @return temporary sub directory
  */
 @Internal
 public static String tempdir() {
   return java.lang.System.getProperty("java.io.tmpdir");
 }