Skip to content

Commit

Permalink
Move out of ConsoleProfiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ww898 committed May 17, 2024
1 parent 06a35c8 commit de27a41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions JetBrains.Profiler.SelfApi/src/DotMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ private static Session RunConsole(string command, Config config)

Trace.Info("DotMemory.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine);

// Note(ww898): Process architecture is inherited by default in macOS ARM64. Here we turn off this behavior!!!
if (HabitatInfo.Platform == JetPlatform.MacOsX &&
HabitatInfo.OSArchitecture == JetArchitecture.Arm64 &&
HabitatInfo.ProcessArchitecture == JetArchitecture.X64)
{
commandLine.Insert(0, $"-arm64 \"${runnerPath}\" ");
runnerPath = "/usr/bin/arch";

Trace.Info("DotMemory.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine);
}

var consoleProfiler = new ConsoleProfiler(
runnerPath,
commandLine.ToString(),
Expand Down
11 changes: 11 additions & 0 deletions JetBrains.Profiler.SelfApi/src/DotTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,17 @@ private static Session RunProfiler(Config config)

Trace.Info("DotTrace.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine);

// Note(ww898): Process architecture is inherited by default in macOS ARM64. Here we turn off this behavior!!!
if (HabitatInfo.Platform == JetPlatform.MacOsX &&
HabitatInfo.OSArchitecture == JetArchitecture.Arm64 &&
HabitatInfo.ProcessArchitecture == JetArchitecture.X64)
{
commandLine.Insert(0, $"-arm64 \"${runnerPath}\" ");
runnerPath = "/usr/bin/arch";

Trace.Info("DotMemory.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine);
}

var collectedSnapshots = new CollectedSnapshots();
var consoleProfiler = new ConsoleProfiler(
runnerPath,
Expand Down
8 changes: 0 additions & 8 deletions JetBrains.Profiler.SelfApi/src/Impl/ConsoleProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.RegularExpressions;
using System.Threading;
using JetBrains.Annotations;
using JetBrains.HabitatDetector;

namespace JetBrains.Profiler.SelfApi.Impl
{
Expand All @@ -28,13 +27,6 @@ public ConsoleProfiler(string executable, string arguments, string messageServic
_presentableName = presentableName;
_isApiReady = isApiReady;

// Note(ww898): Process architecture is inherited by default in macOS ARM64. Here we turn off this behavior!!!
var isX64ProcessUnderMacOsArm64 = HabitatInfo.Platform == JetPlatform.MacOsX &&
HabitatInfo.OSArchitecture == JetArchitecture.Arm64 &&
HabitatInfo.ProcessArchitecture == JetArchitecture.X64;
var effectiveExecutable = isX64ProcessUnderMacOsArm64 ? "/usr/bin/arch" : executable;
var effectiveArguments = isX64ProcessUnderMacOsArm64 ? $"-arm64 \"${executable}\" ${arguments}" : arguments;

var commandRegex = BuildCommandRegex("([a-zA-Z-]*)", "(.*)");
var si = new ProcessStartInfo
{
Expand Down

0 comments on commit de27a41

Please sign in to comment.