-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Profiling tool for running test scripts. (#3243)
* Profiling tool for running test scripts. * Merge with master and fix bug in ask.
- Loading branch information
Showing
4 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...uilder.Dialogs.Adaptive.Profiling/Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DebugType>portable</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libraries\Microsoft.Bot.Builder.Dialogs.Adaptive\Microsoft.Bot.Builder.Dialogs.Adaptive.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
97 changes: 97 additions & 0 deletions
97
tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Licensed under the MIT License. | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing; | ||
using Microsoft.Bot.Builder.Dialogs.Declarative; | ||
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; | ||
using Microsoft.Bot.Builder.Dialogs.Declarative.Types; | ||
using Microsoft.Bot.Builder.MockLuis; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling | ||
{ | ||
public class Program | ||
{ | ||
public static void Help() | ||
{ | ||
Console.Error.WriteLine("[-secret <id=profile>] [-luis <luisDir>] testscripts..."); | ||
Console.Error.WriteLine("-secret This is your secret id for luis keys."); | ||
Console.Error.WriteLine("-luis This is the directory where luis settings arg."); | ||
System.Environment.Exit(-1); | ||
} | ||
|
||
public static void Main(string[] args) | ||
{ | ||
var secret = "profile"; | ||
string luis = null; | ||
if (args.Length == 0) | ||
{ | ||
Help(); | ||
} | ||
|
||
for (var i = 0; i < args.Length; ++i) | ||
{ | ||
var arg = args[i]; | ||
if (arg.StartsWith("-")) | ||
{ | ||
if (arg == "-secret") | ||
{ | ||
if (++i < args.Length) | ||
{ | ||
secret = args[i]; | ||
} | ||
else | ||
{ | ||
throw new System.ArgumentException("Missing --secret value"); | ||
} | ||
} | ||
else if (arg == "-luis") | ||
{ | ||
if (++i < args.Length) | ||
{ | ||
luis = args[i]; | ||
} | ||
else | ||
{ | ||
throw new System.ArgumentException("Missing --luis value"); | ||
} | ||
} | ||
else | ||
{ | ||
Console.Error.WriteLine($"Unknown arg {arg}"); | ||
Help(); | ||
} | ||
} | ||
else | ||
{ | ||
var cd = Directory.GetCurrentDirectory(); | ||
var dir = Path.GetDirectoryName(arg); | ||
var name = Path.GetFileName(arg); | ||
var config = new ConfigurationBuilder() | ||
.AddInMemoryCollection() | ||
.UseLuisSettings(luis ?? dir, secret) | ||
.Build(); | ||
var explorer = new ResourceExplorer().AddFolder(dir); | ||
DeclarativeTypeLoader.Reset(); | ||
TypeFactory.Configuration = config; | ||
DeclarativeTypeLoader.AddComponent(new DialogComponentRegistration()); | ||
DeclarativeTypeLoader.AddComponent(new AdaptiveComponentRegistration()); | ||
DeclarativeTypeLoader.AddComponent(new LanguageGenerationComponentRegistration()); | ||
DeclarativeTypeLoader.AddComponent(new QnAMakerComponentRegistration()); | ||
DeclarativeTypeLoader.AddComponent(new MockLuisComponentRegistration()); | ||
var script = explorer.LoadType<TestScript>(name); | ||
var timer = new System.Diagnostics.Stopwatch(); | ||
Console.Write($"Executing {arg}"); | ||
timer.Start(); | ||
script.ExecuteAsync(testName: name, configuration: config, resourceExplorer: explorer).Wait(); | ||
timer.Stop(); | ||
Console.WriteLine($" took {timer.ElapsedMilliseconds} ms"); | ||
} | ||
} | ||
} | ||
} | ||
} |