Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gearama/profile debug #5464

Merged
merged 32 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions tools/perf-automation/Azure.Sdk.Tools.PerfAutomation/Cpp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class Cpp : LanguageBase
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions)
IDictionary<string, string> packageVersions,
bool debug = false)
{
var buildDirectory = Path.Combine(WorkingDirectory, _buildDirectory);

Expand All @@ -42,8 +43,8 @@ public class Cpp : LanguageBase
await UpdatePackageVersions(packageVersions);

// Windows and Linux require different arguments to build Release config
var additionalGenerateArguments = Util.IsWindows ? "-DDISABLE_AZURE_CORE_OPENTELEMETRY=ON" : "-DCMAKE_BUILD_TYPE=Release";
var additionalBuildArguments = Util.IsWindows ? "--config MinSizeRel" : String.Empty;
var additionalGenerateArguments = Util.IsWindows ? "-DDISABLE_AZURE_CORE_OPENTELEMETRY=ON" : (debug ? "-DCMAKE_BUILD_TYPE=Debug" : "-DCMAKE_BUILD_TYPE=Release");
gearama marked this conversation as resolved.
Show resolved Hide resolved
var additionalBuildArguments = Util.IsWindows ? (debug ? "--config Debug" : "--config MinSizeRel") : String.Empty;

await Util.RunAsync(
"cmake", $"-DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON {additionalGenerateArguments} ..",
Expand All @@ -68,11 +69,46 @@ public override async Task<IterationResult> RunAsync(
string testName,
string arguments,
bool profile,
object context)
object context
)
gearama marked this conversation as resolved.
Show resolved Hide resolved
{
var perfExe = (string)context;
var profiling = profile;
string perfExe;
string profileOptions = "";
if (context is string)
{
perfExe = (string)context;
}
else
{
perfExe = (context as Dictionary<string, object>)["context"] as string;
profileOptions = (context as Dictionary<string, object>)["profileOptions"] as string;
}

var profiledExe = perfExe;

if (profile)
{
if (Util.IsWindows)
{
Console.WriteLine("Profiling available on linux alone at the moment");
profiling = false;
gearama marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
profiledExe = perfExe;
perfExe = "valgrind";
profiling = true;
}
}

string finalParams = $"{testName} {arguments}";
if (profiling)
{
finalParams = $"{profileOptions} {profiledExe} {finalParams}";
}

var result = await Util.RunAsync(perfExe, $"{testName} {arguments}", WorkingDirectory);
var result = await Util.RunAsync(perfExe, finalParams, WorkingDirectory);

IDictionary<string, string> reportedVersions = new Dictionary<string, string>();

Expand Down Expand Up @@ -113,7 +149,7 @@ public override async Task CleanupAsync(string project)
var fullVcpkgPath = Path.Combine(WorkingDirectory, _vcpkgFile);
var buildDirectory = Path.Combine(WorkingDirectory, _buildDirectory);
Util.DeleteIfExists(buildDirectory);
//cleanup the vcpkg file
//cleanup the vcpkg file by restoring from git
await Util.RunAsync("git", $"checkout -- {fullVcpkgPath}", WorkingDirectory);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface ILanguage
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions);
IDictionary<string, string> packageVersions,
bool debug = false);
gearama marked this conversation as resolved.
Show resolved Hide resolved

Task<IterationResult> RunAsync(
string project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class Java : LanguageBase
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions)
IDictionary<string, string> packageVersions,
bool debug = false)
{
var projectFile = Path.Combine(WorkingDirectory, project, "pom.xml");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class JavaScript : LanguageBase
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions)
IDictionary<string, string> packageVersions,
bool debug = false)
{
var outputBuilder = new StringBuilder();
var errorBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public abstract class LanguageBase : ILanguage
{
protected abstract Language Language { get; }

protected string ProfileDirectory => Path.GetFullPath(Path.Combine(WorkingDirectory, Language + "-profile"));
gearama marked this conversation as resolved.
Show resolved Hide resolved

public string WorkingDirectory { get; set; }

public abstract Task CleanupAsync(string project);
Expand All @@ -30,6 +32,7 @@ public abstract Task<IterationResult> RunAsync(
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions);
IDictionary<string, string> packageVersions,
bool debug = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class Net : LanguageBase
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions)
IDictionary<string, string> packageVersions,
bool debug = false)
{
var projectFile = Path.Combine(WorkingDirectory, project);

Expand Down
16 changes: 13 additions & 3 deletions tools/perf-automation/Azure.Sdk.Tools.PerfAutomation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class Options
[Option("profile", HelpText = "Enables capture of profiling data")]
public bool Profile { get; set; }

[Option("profilerOpt", HelpText = "Provides additional profiler parameters")]
public string ProfilerOptions { get; set; }

[Option("repo-root", Required = true, HelpText = "Path to root of repository in which to run tests")]
public string RepoRoot { get; set; }

Expand Down Expand Up @@ -131,7 +134,8 @@ static Task DisplayHelp<T>(ParserResult<T> result)

private static async Task Run(Options options)
{
if (options.Language == Language.JS) {
if (options.Language == Language.JS)
{
// JS is async-only
options.NoSync = true;
}
Expand Down Expand Up @@ -266,7 +270,7 @@ private static async Task RunPackageVersion(
try
{
(setupOutput, setupError, context) = await _languages[language].SetupAsync(
project, languageVersion, primaryPackage, packageVersions);
project, languageVersion, primaryPackage, packageVersions, options.Debug);
}
catch (Exception e)
{
Expand Down Expand Up @@ -342,6 +346,12 @@ private static async Task RunPackageVersion(
IterationResult iterationResult;
try
{
Dictionary<string, object> contextWrapper = new Dictionary<string, object>();
if (!String.IsNullOrWhiteSpace(options.ProfilerOptions))
{
contextWrapper.Add("context", context);
contextWrapper.Add("profileOptions", options.ProfilerOptions);
}
Console.WriteLine($"RunAsync({project}, {languageVersion}, " +
$"{test.Class}, {allArguments}, {context}, {options.Profile})");
Console.WriteLine();
Expand All @@ -354,7 +364,7 @@ private static async Task RunPackageVersion(
test.Class,
allArguments,
options.Profile,
context
contextWrapper.Count() != 0 ? contextWrapper : context
gearama marked this conversation as resolved.
Show resolved Hide resolved
);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Python : LanguageBase
string project,
string languageVersion,
string primaryPackage,
IDictionary<string, string> packageVersions)
IDictionary<string, string> packageVersions,
bool debug = false)
{
var projectDirectory = Path.Combine(WorkingDirectory, project);
var env = Path.Combine(projectDirectory, _env);
Expand Down