예제 #1
0
        internal void StartProfiler(string device, string logFile, string transport,
                                    string exePath, string buildPath, ArrayList referenceList, bool isDevEnvironment, string assemblyName)
        {
            try
            {
                PortDefinition port = Utils.GetPort(device, transport, exePath);

                m_engine  = new Engine(port);
                m_session = new ProfilerSession(m_engine);

#if DEBUG
                m_exporter = new Exporter_OffProf(m_session, logFile);
#endif

                lock (m_engine)
                {
                    m_engine.StopDebuggerOnConnect = true;
                    m_engine.Start();

                    bool connected = false;

                    connected = m_engine.TryToConnect(20, 500, true, ConnectionSource.TinyCLR);

                    if (connected)
                    {
                        if (m_engine.Capabilities.Profiling == false)
                        {
                            throw new ApplicationException("This device is not running a version of TinyCLR that supports profiling.");
                        }

                        // Deploy the test files to the device.
                        Utils.DeployToDevice(buildPath, referenceList, m_engine, transport, isDevEnvironment, assemblyName);

                        // Move IsDeviceInInitializeState(), IsDeviceInExitedState(),
                        // GetDeviceState(),EnsureProcessIsInInitializedState() to Debugger.dll?

                        m_engine.RebootDevice(Engine.RebootOption.RebootClrWaitForDebugger);

                        if (!m_engine.TryToConnect(100, 500))
                        {
                            throw new ApplicationException("Connection Failed");
                        }

                        m_engine.ThrowOnCommunicationFailure = true;
                        m_session.EnableProfiling();

                        m_session.SetProfilingOptions(true, false);
                        m_engine.OnCommand += new CommandEventHandler(OnWPCommand);
                        m_engine.ResumeExecution();
                    }
                    else
                    {
                        throw new ApplicationException("Connection failed");
                    }
                }
            }
            catch (Exception ex)
            {
                SoftDisconnectDone(null, null);
                throw ex;
            }
        }