Exemple #1
0
 private void setProcessFlags() throws RpcException {
   if (ProcessMode.BY_PID.equals(processMode)) {
     // setting flags only for selected processes
     if (processes != null) {
       for (final TracedProcess process : processes) {
         if (process.isSelected()) {
           tracerBackend.call(
               Constants.TTB_MODULE,
               FUN_P,
               "xx",
               process.getPid(),
               createProcessFlagsArray(process.getFlags()));
         }
       }
     }
   } else {
     // setting global flags
     tracerBackend.call(
         Constants.TTB_MODULE,
         FUN_P,
         "ax",
         processMode.toAtom(),
         createProcessFlagsArray(processFlags));
   }
 }
Exemple #2
0
 /**
  * Loads traces from active result set ( {@link #setActiveResultSet(TracingResultsNode)}). Index
  * of last trace which will be loaded is <code>max(number_of_traces, endIndex)</code>.
  *
  * @param theStartIndex number of first trace
  * @param endIndex number of last trace
  */
 public void loadDataFromFile(final long theStartIndex, final long endIndex) {
   if (!tracing && !loading) {
     synchronized (this) {
       if (!tracing && !loading) {
         try {
           loading = true;
           loadingFileInfo = false;
           startIndex = theStartIndex;
           handler = new TraceEventHandler();
           getBackend(true);
           TraceCollections.getTracesList().clear();
           tracerBackend.getEventDaemon().addHandler(handler);
           final OtpErlangLong start = new OtpErlangLong(theStartIndex);
           final OtpErlangLong stop = new OtpErlangLong(endIndex);
           tracerBackend.call(
               Constants.ERLANG_HELPER_MODULE,
               FUN_LOAD,
               "sii",
               new OtpErlangString(activeResultSet.getFileName()),
               start,
               stop);
         } catch (final RpcException e) {
           ErlLogger.error(e);
           errorObject = e;
           finishLoading(TracingStatus.EXCEPTION_THROWN);
         }
       }
     }
   }
 }
Exemple #3
0
 private void setFunctionTracePatterns() {
   for (final TracePattern tracePattern : tracePatterns) {
     if (tracePattern.isEnabled()) {
       final String function = tracePattern.isLocal() ? FUN_TPL : FUN_TP;
       try {
         OtpErlangObject matchSpec = null;
         if (tracePattern.getMatchSpec().getMsObject() != null) {
           matchSpec = tracePattern.getMatchSpec().getMsObject();
         } else {
           matchSpec = new OtpErlangList();
         }
         if (tracePattern.getArity() < 0) {
           tracerBackend.call(
               Constants.TTB_MODULE,
               function,
               "aax",
               tracePattern.getModuleName(),
               tracePattern.getFunctionName(),
               matchSpec);
         } else {
           tracerBackend.call(
               Constants.TTB_MODULE,
               function,
               "aaxx",
               tracePattern.getModuleName(),
               tracePattern.getFunctionName(),
               new OtpErlangInt(tracePattern.getArity()),
               matchSpec);
         }
       } catch (final RpcException e) {
         ErlLogger.error("Could not add pattern: " + e.getMessage());
       }
     }
   }
 }
Exemple #4
0
    public Object[] getElements(final Object parent) {
      final IBackend bk = getBackend();
      if (bk == null) {
        return new OtpErlangObject[] {};
      }
      bk.getEventDaemon().addHandler(handler);

      final OtpErlangList r = ErlideProclist.getProcessList(bk);
      if (r.arity() == 0) {
        return new OtpErlangObject[] {};
      }
      final OtpErlangObject[] ss = new OtpErlangObject[r.elements().length];

      for (int i = 0; i < r.elements().length; i++) {
        final OtpErlangTuple e = (OtpErlangTuple) r.elementAt(i);
        ss[i] = e;
      }

      return ss;
    }
Exemple #5
0
 /**
  * Loads information about given file.
  *
  * @param path path
  */
 public void loadFile(final String path) {
   if (!tracing && !loading) {
     synchronized (this) {
       if (!tracing && !loading) {
         try {
           loading = true;
           loadingFileInfo = true;
           handler = new TraceEventHandler();
           getBackend(true);
           tracerBackend.getEventDaemon().addHandler(handler);
           tracerBackend.call(
               Constants.ERLANG_HELPER_MODULE, FUN_FILE_INFO, "s", new OtpErlangString(path));
         } catch (final RpcException e) {
           ErlLogger.error(e);
           errorObject = e;
           finishLoading(TracingStatus.EXCEPTION_THROWN);
         }
       }
     }
   }
 }
Exemple #6
0
 /**
  * Performs actions after loading file or trace data.
  *
  * @param status status
  */
 private void finishLoading(final TracingStatus status) {
   tracerBackend.getEventDaemon().removeHandler(handler);
   for (final ITraceNodeObserver listener : listeners) {
     try {
       if (loadingFileInfo) {
         listener.finishLoadingFile(status);
       } else {
         listener.finishLoadingTraces(status);
       }
     } catch (final Exception e) {
       ErlLogger.error(e);
     }
   }
   loading = false;
   tracing = false;
 }
Exemple #7
0
 /** Stops tracing. */
 public void stop() {
   if (tracing && !loading) {
     synchronized (this) {
       if (tracing && !loading) {
         try {
           loading = true;
           tracerBackend.call(Constants.ERLANG_HELPER_MODULE, FUN_STOP, "");
         } catch (final RpcException e) {
           ErlLogger.error("Could not stop tracing tool: " + e.getMessage());
           errorObject = e;
           finishLoading(TracingStatus.EXCEPTION_THROWN);
         }
       }
     }
   }
 }
Exemple #8
0
  /**
   * Starts tracing given nodes.
   *
   * @return <code>true</code> if successful, <code>false</code> otherwise
   */
  public TracingStatus start() {
    TracingStatus status = TracingStatus.OK;
    if (!tracing) {
      synchronized (this) {
        if (!tracing) {
          try {
            tracing = true;
            getBackend(true);
            loadingFileInfo = true;
            handler = new TraceEventHandler();
            tracerBackend.getEventDaemon().addHandler(handler);

            // list of nodes being traced
            final List<OtpErlangObject> erlangObjects = new ArrayList<OtpErlangObject>();
            notActivatedNodes = new HashSet<String>();
            for (final TracedNode tracedNode : tracedNodes) {
              if (tracedNode.isEnabled()) {
                final OtpErlangAtom name = new OtpErlangAtom(tracedNode.getNodeName());
                final OtpErlangAtom cookie = new OtpErlangAtom(tracedNode.getCookie());

                erlangObjects.add(new OtpErlangTuple(new OtpErlangObject[] {name, cookie}));
                notActivatedNodes.add(tracedNode.getNodeName());
              }
            }
            final OtpErlangList nodes =
                new OtpErlangList(erlangObjects.toArray(new OtpErlangObject[erlangObjects.size()]));

            // net tick time
            final int tickTimeValue =
                Activator.getDefault().getPreferenceStore().getInt(PreferenceNames.TICK_TIME);
            final OtpErlangInt netTickTime = new OtpErlangInt(tickTimeValue);

            final OtpErlangObject callResult =
                tracerBackend.call(
                    Constants.ERLANG_HELPER_MODULE,
                    FUN_START,
                    "xsi",
                    nodes,
                    Constants.OUTPUT_FILE,
                    netTickTime);
            status = processResult(callResult);

            if (TracingStatus.OK.equals(status)
                || TracingStatus.NOT_ALL_NODES_ACTIVATED.equals(status)) {
              setProcessFlags();
              setFunctionTracePatterns();
              for (final ITraceNodeObserver listener : listeners) {
                try {
                  listener.startTracing();
                } catch (final Exception e) {
                  ErlLogger.error(e);
                }
              }
            } else {
              tracing = false;
            }
          } catch (final Exception e) {
            e.printStackTrace();
            ErlLogger.error("Could not start tracing tool: " + e.getMessage());
            status = TracingStatus.EXCEPTION_THROWN;
            errorObject = e;
            tracing = false;
          }
        }
      }
    }
    return status;
  }
Exemple #9
0
 public void dispose() {
   final IBackend backend = getBackend();
   if (backend != null) {
     backend.getEventDaemon().removeHandler(handler);
   }
 }
Exemple #10
0
  @Override
  protected IProject[] build(
      final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor)
      throws CoreException {
    final IProject project = getProject();
    if (project == null || !project.isAccessible()) {
      return new IProject[0];
    }

    if (BuilderHelper.isDebugging()) {
      ErlLogger.debug(
          "Starting build "
              + helper.buildKind(kind)
              + " of "
              + project.getName()
              + " @ "
              + new Date(System.currentTimeMillis()));
    }
    try {
      MarkerUtils.deleteMarkers(project);
      initializeBuilder(monitor);

      final OtpErlangList compilerOptions = CompilerPreferences.get(project);

      ErlLogger.debug("******** building %s: %s", getProject().getName(), compilerOptions);

      final Set<String> resourcesToBuild = getResourcesToBuild(kind, args, project);
      final int n = resourcesToBuild.size();
      if (n > 0) {
        final IBackend backend = BackendCore.getBackendManager().getBuildBackend(project);
        if (backend == null) {
          final String message =
              "No backend with the required " + "version could be found. Can't build.";
          MarkerUtils.addProblemMarker(project, null, null, message, 0, IMarker.SEVERITY_ERROR);
          throw new BackendException(message);
        }

        notifier.setProgressPerCompilationUnit(1.0f / n);

        final IPath projectPath = project.getLocation();
        final IErlProject erlProject = CoreScope.getModel().getErlangProject(project);
        final String outputDir = projectPath.append(erlProject.getOutputLocation()).toString();
        helper.ensureDirExists(outputDir);

        final Collection<IPath> includeDirs = helper.getAllIncludeDirs(project);

        final RpcEventProcessor processor =
            new RpcEventProcessor(new BuildHandler(), backend.createMbox());
        final OtpErlangPid watcher = processor.getPid();
        final OtpErlangPid builder =
            (OtpErlangPid)
                backend.call(
                    "erlide_builder",
                    "build_resources",
                    "lsslsxp",
                    resourcesToBuild,
                    outputDir,
                    includeDirs,
                    compilerOptions,
                    watcher);
        processor.setStarter(builder);
        processor.run();
      }

    } catch (final Exception e) {
      ErlLogger.error(e);
      final String msg =
          NLS.bind(BuilderMessages.build_inconsistentProject, e.getLocalizedMessage());
      MarkerUtils.addProblemMarker(project, null, null, msg, 0, IMarker.SEVERITY_ERROR);
    } finally {
      cleanup();
      if (BuilderHelper.isDebugging()) {
        ErlLogger.debug(
            "Finished build of "
                + project.getName() // $NON-NLS-1$
                + " @ "
                + new Date(System.currentTimeMillis()));
      }
    }
    return null;
  }