예제 #1
0
        public string GetSampleExecutionSource()
        {
            string executor;

            if (_samplesDirectory.Contains("aspnet"))
            {
                executor = $"C:\\Program Files{(Environment.Is64BitProcess ? string.Empty : " (x86)")}\\IIS Express\\iisexpress.exe";
            }
            else if (IsCoreClr())
            {
                executor = EnvironmentTools.IsWindows() ? "dotnet.exe" : "dotnet";
            }
            else
            {
                var appFileName = $"{FullSampleName}.exe";
                executor = Path.Combine(GetSampleApplicationOutputDirectory(), appFileName);

                if (!File.Exists(executor))
                {
                    throw new Exception($"Unable to find executing assembly at {executor}");
                }
            }

            return(executor);
        }
예제 #2
0
        public string GetSampleApplicationOutputDirectory(string packageVersion = "", string framework = "")
        {
            var targetFramework = string.IsNullOrEmpty(framework) ? GetTargetFramework() : framework;
            var binDir          = Path.Combine(
                GetSampleProjectDirectory(),
                "bin");

            string outputDir;

            if (_samplesDirectory.Contains("aspnet"))
            {
                outputDir = binDir;
            }
            else if (EnvironmentTools.GetOS() == "win")
            {
                outputDir = Path.Combine(
                    binDir,
                    packageVersion,
                    EnvironmentTools.GetPlatform(),
                    EnvironmentTools.GetBuildConfiguration(),
                    targetFramework);
            }
            else
            {
                outputDir = Path.Combine(
                    binDir,
                    packageVersion,
                    EnvironmentTools.GetBuildConfiguration(),
                    targetFramework,
                    "publish");
            }

            return(outputDir);
        }
예제 #3
0
        public string GetDotNetTest()
        {
            if (EnvironmentTools.IsWindows() && !IsCoreClr())
            {
                string filePattern = @"C:\Program Files (x86)\Microsoft Visual Studio\{0}\{1}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";
                List <Tuple <string, string> > lstTuple = new List <Tuple <string, string> >
                {
                    Tuple.Create("2019", "Enterprise"),
                    Tuple.Create("2019", "Professional"),
                    Tuple.Create("2019", "Community"),
                    Tuple.Create("2017", "Enterprise"),
                    Tuple.Create("2017", "Professional"),
                    Tuple.Create("2017", "Community"),
                };

                foreach (Tuple <string, string> tuple in lstTuple)
                {
                    var tryPath = string.Format(filePattern, tuple.Item1, tuple.Item2);
                    if (File.Exists(tryPath))
                    {
                        return(tryPath);
                    }
                }
            }

            return(GetDotnetExe());
        }
예제 #4
0
        public static string GetTracerNativeDLLPath()
        {
            var tracerHome = GetTracerHomePath();

            var(extension, dir) = (EnvironmentTools.GetOS(), EnvironmentTools.GetPlatform()) switch
            {
                ("win", "X64") => ("dll", "win-x64"),
                ("win", "X86") => ("dll", "win-x86"),
                ("linux", "X64") => ("so", null),
                ("linux", "Arm64") => ("so", null),
                ("osx", _) => ("dylib", null),
                _ => throw new PlatformNotSupportedException()
            };

            var fileName = $"Datadog.Trace.ClrProfiler.Native.{extension}";

            var path = dir is null
                           ? Path.Combine(tracerHome, fileName)
                           : Path.Combine(tracerHome, dir, fileName);

            if (!File.Exists(path))
            {
                throw new Exception($"Unable to find profiler at {path}");
            }

            return(path);
        }
예제 #5
0
        public static string GetTracerHomePath()
        {
            var tracerHomeDirectoryEnvVar = "TracerHomeDirectory";
            var tracerHome = Environment.GetEnvironmentVariable(tracerHomeDirectoryEnvVar);

            if (string.IsNullOrEmpty(tracerHome))
            {
                // default
                return(Path.Combine(
                           GetMonitoringHomePath(),
                           "tracer"));
            }

            if (!Directory.Exists(tracerHome))
            {
                throw new InvalidOperationException($"{tracerHomeDirectoryEnvVar} was set to '{tracerHome}', but directory does not exist");
            }

            // basic verification
            var tfmDirectory = EnvironmentTools.GetTracerTargetFrameworkDirectory();
            var dllLocation  = Path.Combine(tracerHome, tfmDirectory);

            if (!Directory.Exists(dllLocation))
            {
                throw new InvalidOperationException($"{tracerHomeDirectoryEnvVar} was set to '{tracerHome}', but location does not contain expected folder '{tfmDirectory}'");
            }

            return(tracerHome);
        }
예제 #6
0
 public static string GetMonitoringHomePath()
 {
     // default
     return(Path.Combine(
                EnvironmentTools.GetSolutionDirectory(),
                "shared",
                "bin",
                "monitoring-home"));
 }
예제 #7
0
 private string GetProfilerProjectBin()
 {
     return(Path.Combine(
                GetSolutionDirectory(),
                "src",
                "Datadog.Trace.ClrProfiler.Native",
                "bin",
                EnvironmentTools.GetBuildConfiguration(),
                EnvironmentTools.GetPlatform().ToLower()));
 }
예제 #8
0
        public string GetProfilerPath()
        {
            if (_profilerFileLocation == null)
            {
                string extension = EnvironmentTools.GetOS() switch
                {
                    "win" => "dll",
                    "linux" => "so",
                    "osx" => "dylib",
                    _ => throw new PlatformNotSupportedException()
                };

                string fileName = $"Datadog.Trace.ClrProfiler.Native.{extension}";

                var directory = GetSampleApplicationOutputDirectory();

                var relativePath = Path.Combine(
                    "profiler-lib",
                    fileName);

                _profilerFileLocation = Path.Combine(
                    directory,
                    relativePath);

                // TODO: get rid of the fallback options when we have a consistent convention

                if (!File.Exists(_profilerFileLocation))
                {
                    _output?.WriteLine($"Attempt 1: Unable to find profiler at {_profilerFileLocation}.");
                    // Let's try the executing directory, as dotnet publish ignores the Copy attributes we currently use
                    _profilerFileLocation = Path.Combine(
                        GetExecutingProjectBin(),
                        relativePath);
                }

                if (!File.Exists(_profilerFileLocation))
                {
                    _output?.WriteLine($"Attempt 2: Unable to find profiler at {_profilerFileLocation}.");
                    // One last attempt at the actual native project directory
                    _profilerFileLocation = Path.Combine(
                        GetProfilerProjectBin(),
                        fileName);
                }

                if (!File.Exists(_profilerFileLocation))
                {
                    throw new Exception($"Attempt 3: Unable to find profiler at {_profilerFileLocation}");
                }

                _output?.WriteLine($"Found profiler at {_profilerFileLocation}.");
            }

            return(_profilerFileLocation);
        }
예제 #9
0
        protected TestHelper(EnvironmentHelper environmentHelper, ITestOutputHelper output)
        {
            EnvironmentHelper = environmentHelper;
            Output            = output;

            Output.WriteLine($"Platform: {EnvironmentTools.GetPlatform()}");
            Output.WriteLine($"Configuration: {EnvironmentTools.GetBuildConfiguration()}");
            Output.WriteLine($"TargetFramework: {EnvironmentHelper.GetTargetFramework()}");
            Output.WriteLine($".NET Core: {EnvironmentHelper.IsCoreClr()}");
            Output.WriteLine($"Tracer Native DLL: {EnvironmentHelper.GetTracerNativeDLLPath()}");
            Output.WriteLine($"Native Loader DLL: {EnvironmentHelper.GetNativeLoaderPath()}");
        }
        internal static string GetProfilerTargetFolder()
        {
            var tracerHome = EnvironmentHelper.GetTracerHomePath();
            var targetFrameworkDirectory = EnvironmentTools.GetTracerTargetFrameworkDirectory();

            var finalDirectory = Path.Combine(tracerHome, targetFrameworkDirectory);

            if (Directory.Exists(finalDirectory))
            {
                return(finalDirectory);
            }

            return(null);
        }
예제 #11
0
        public static string GetNativeLoaderPath()
        {
            var monitoringHome = GetMonitoringHomePath();

            string fileName = (EnvironmentTools.GetOS(), EnvironmentTools.GetPlatform()) switch
            {
                ("win", "X64") => "Datadog.AutoInstrumentation.NativeLoader.x64.dll",
                ("win", "X86") => "Datadog.AutoInstrumentation.NativeLoader.x86.dll",
                ("linux", "X64") => "Datadog.AutoInstrumentation.NativeLoader.so",
                ("linux", "Arm64") => "Datadog.AutoInstrumentation.NativeLoader.so",
                ("osx", _) => throw new PlatformNotSupportedException("The Native Loader is not yet supported on osx"),
                      _ => throw new PlatformNotSupportedException()
            };

            var path = Path.Combine(monitoringHome, fileName);

            if (!File.Exists(path))
            {
                throw new Exception($"Unable to find Native Loader at {path}");
            }

            return(path);
        }
예제 #12
0
 public static string GetSolutionDirectory()
 {
     return(EnvironmentTools.GetSolutionDirectory());
 }
예제 #13
0
 public static string GetRuntimeIdentifier()
 {
     return(IsCoreClr()
                ? string.Empty
                : $"{EnvironmentTools.GetOS()}-{EnvironmentTools.GetPlatform()}");
 }