Ejemplo n.º 1
0
        public void Run(CancellationToken cancellationToken, ProfilingType profilingType)
        {
            Guard.NotNull(cancellationToken, nameof(cancellationToken));

            if (thread != null)
            {
                throw new InvalidOperationException();
            }

            thread = new Thread(() => {
                try {
                    Profiler profiler =
                        profilingType != ProfilingType.None ?
                        new Profiler(name, profilingType) :
                        null;
                    Do(cancellationToken, profiler);
                }
                catch (Exception error) {
                    this.error = error;
                    cancellationToken.Cancel();
                }
                finally {
                    outputChannel.Finish();
                }
            })
            {
                Name         = name,
                IsBackground = true
            };
            thread.Start();
        }
Ejemplo n.º 2
0
 public void LogValue <T>(T value, ProfilingType profilingType)
 {
     if (AllowProfiling(profilingType))
     {
         LogValueInternal(value, profilingType);
     }
 }
Ejemplo n.º 3
0
        public Profiler(string name, ProfilingType profilingType)
        {
            Guard.NotNullOrWhiteSpace(name, nameof(name));

            this.name          = name;
            this.profilingType = profilingType;
        }
Ejemplo n.º 4
0
 public void BeginWatch(ProfilingType profilingType)
 {
     if (AllowProfiling(profilingType))
     {
         watch.Reset();
         watch.Start();
     }
 }
Ejemplo n.º 5
0
 public void EndWatch(ProfilingType profilingType)
 {
     if (AllowProfiling(profilingType))
     {
         watch.Stop();
         double timeMicro = (double)watch.ElapsedTicks / Stopwatch.Frequency * 1000 * 1000;
         LogValueInternal(timeMicro, profilingType);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// (Windows only) Use the Timeline profiling type.
 /// If not specified, the Sampling type is used.
 /// </summary>
 /// <param name="askUacElevationIfRequired">If false and a profiling session requires administrative privileges, the method throws an exception. If true, dotTrace will ask for UAC elevation and continue the session.</param>
 /// <returns></returns>
 public Config UseTimelineProfilingType(bool askUacElevationIfRequired = false)
 {
     if (Helper.Platform != PlatformId.Windows)
     {
         throw new InvalidOperationException("The Timeline profiling type is supported only on Windows platform");
     }
     Type = ProfilingType.Timeline;
     AskUacElevationIfRequired = askUacElevationIfRequired;
     return(this);
 }
Ejemplo n.º 7
0
        public DotTraceProcess(string exePath, string savePath, TimeSpan interval, ProfilingType profilingType)
        {
            _process  = new Process();
            _savePath = savePath;
            _interval = interval;

            var pid = Process.GetCurrentProcess().Id;

            _process.StartInfo.FileName  = exePath;
            _process.StartInfo.Arguments = $"attach {pid} --profiling-type={profilingType} --save-to=\"{savePath}\" --timeout={interval.TotalSeconds}s";

            Log.Info($"{_process.StartInfo.FileName} {_process.StartInfo.Arguments}");
        }
Ejemplo n.º 8
0
        static void Process(dynamic options, Func <dynamic, string> getSrc, Func <dynamic, string> getDest,
                            RunAsEnumerable.Action runAsEnumerable, RunAsPipeline.Action runAsPipeline)
        {
            string src  = getSrc(options);
            string dest = getDest(options);

            int jobCount = options.JobCount?.Value ?? Constants.DEFAULT_JOB_COUNT;

            jobCount = Math.Max(jobCount, 1);
            jobCount = Math.Min(jobCount, Constants.MAX_JOB_COUNT);

            int chunkSize = options.ChunkSize?.Value ?? Constants.DEFAULT_CHUNK_SIZE;

            chunkSize = Math.Max(chunkSize, Constants.MIN_CHUNK_SIZE);
            chunkSize = Math.Min(chunkSize, Constants.MAX_CHUNK_SIZE);

            var loggers = new Loggers();

            if (options.LogChunks != null)
            {
                loggers.ChunkLogger = new ChunkLogger();
            }
            else if (options.LogJobs != null)
            {
                loggers.JobLogger = new JobLogger();
            }
            else
            {
                loggers.DefaultLogger = new DefaultLogger();
            }

            Action <BinaryReader, BinaryWriter> processor;

            if (options.UsePipeline != null)
            {
                ProfilingType profilingType = options.ProfilePipeline?.Value ?? ProfilingType.None;
                processor = (reader, writer) => runAsPipeline(reader, writer, jobCount, chunkSize, _cancellationToken, loggers, profilingType);
            }
            else
            {
                processor = (reader, writer) => runAsEnumerable(reader, writer, jobCount, chunkSize, _cancellationToken, loggers);
            }

            ProcessFile(src, dest, processor);
        }
Ejemplo n.º 9
0
        public void Run(CancellationToken cancellationToken, ProfilingType profilingType)
        {
            if (cancellationToken == null)
            {
                cancellationToken = new CancellationToken();
            }

            foreach (var routine in routines)
            {
                routine.Run(cancellationToken, profilingType);
            }

            var errors = routines
                         .Select(routine => routine.Wait())
                         .Where(error => error != null)
                         .ToList();

            if (errors.Count > 0)
            {
                throw new AggregateException(errors);
            }
        }
 public async Task StartTracing(TimeSpan?interval, ProfilingType profilingType)
 {
     await _connector.StartTracing(_cancellationTokenSource.Token, interval, profilingType);
 }
Ejemplo n.º 11
0
        public static void Decompress(BinaryReader reader, BinaryWriter writer, int jobCount, int chunkSize = Constants.DEFAULT_CHUNK_SIZE,
                                      CancellationToken cancellationToken = null, Loggers loggers = null, ProfilingType profilingType = ProfilingType.None)
        {
            Guard.NotNull(reader, nameof(reader));
            Guard.NotNull(writer, nameof(writer));
            Guard.NotZeroOrNegative(jobCount, nameof(jobCount));
            Guard.NotZeroOrNegative(chunkSize, nameof(chunkSize));

            Console.WriteLine("Decompress as Pipeline");

            int index = 0;

            IDefaultLogger defaultLogger = loggers?.DefaultLogger;

            ChunkSource.ReadHeader(reader, out int chunkCount);

            var chunkEnumerator = ChunkSource.ReadChunkCompressed(reader, chunkCount).GetEnumerator();

            Pipeline <Chunk>
            .FromSource("source", (out Chunk chunk) => {
                bool next = chunkEnumerator.MoveNext();
                chunk     = next ? chunkEnumerator.Current : null;
                return(next);
            })
            .PipeMany("zip", ChunkConverter.Unzip, jobCount)
            .ToTarget("target", (Chunk chunk) => {
                ChunkTarget.WriteChunk(chunk, writer, chunkSize);

                if (profilingType == ProfilingType.None)
                {
                    defaultLogger?.LogChunksProcessed(++index, chunkCount);
                }
            })
            .Run(cancellationToken, profilingType);
        }
Ejemplo n.º 12
0
 void LogValueInternal <T>(T value, ProfilingType profilingType)
 {
     Console.WriteLine($"{profilingType.ToString().ToUpper()} - {name} : {value}");
 }
Ejemplo n.º 13
0
 bool AllowProfiling(ProfilingType profilingType)
 {
     return(this.profilingType.HasFlag(profilingType));
 }