Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
add flag to enable memory and cpu profilers
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Sep 6, 2022
1 parent c175b46 commit 4f0b11e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/deployment/azuredeploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ param app_func_issuer string
param app_func_audiences array
param multi_tenant_domain string
param enable_remote_debugging bool = false
param enable_profiler bool = false

param location string = resourceGroup().location

Expand Down Expand Up @@ -315,6 +316,7 @@ module pythonFunctionSettings 'bicep-templates/function-settings.bicep' = {
multi_tenant_domain: multi_tenant_domain
functions_disabled: python_functions_disabled
use_dotnet_agent_functions: use_dotnet_agent_functions
enable_profiler: false
all_function_names: [
'agent_can_schedule' //0
'agent_commands' //1
Expand Down Expand Up @@ -380,6 +382,7 @@ module netFunctionSettings 'bicep-templates/function-settings.bicep' = {
multi_tenant_domain: multi_tenant_domain
functions_disabled: dotnet_functions_disabled
use_dotnet_agent_functions: false // this doesn’t do anything on the .NET service
enable_profiler: enable_profiler
all_function_names: [
'AgentCanSchedule' //0
'AgentCommands' //1
Expand Down
9 changes: 8 additions & 1 deletion src/deployment/bicep-templates/function-settings.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ param use_dotnet_agent_functions bool

param all_function_names array

param enable_profiler bool

var disabledFunctionName = 'disabledFunctions-${functions_worker_runtime}'

var telemetry = 'd7a73cf4-5a1a-4030-85e1-e5b25867e45a'
Expand All @@ -47,6 +49,11 @@ module disabledFunctions 'function-settings-disabled-apps.bicep' = {
}
}

var enable_profilers = enable_profiler ? {
APPINSIGHTS_PROFILERFEATURE_VERSION : '1.0.0'
DiagnosticServices_EXTENSION_VERSION: '~3'
} : {}

resource functionSettings 'Microsoft.Web/sites/config@2021-03-01' = {
parent: function
name: 'appsettings'
Expand All @@ -72,5 +79,5 @@ resource functionSettings 'Microsoft.Web/sites/config@2021-03-01' = {
ONEFUZZ_OWNER: owner
ONEFUZZ_CLIENT_SECRET: client_secret
ONEFUZZ_USE_DOTNET_AGENT_FUNCTIONS: use_dotnet_agent_functions ? '1' : '0'
}, disabledFunctions.outputs.appSettings)
}, disabledFunctions.outputs.appSettings, enable_profilers)
}
14 changes: 14 additions & 0 deletions src/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __init__(
cli_app_id: str,
auto_create_cli_app: bool,
host_dotnet_on_windows: bool,
enable_profiler: bool,
):
self.subscription_id = subscription_id
self.resource_group = resource_group
Expand Down Expand Up @@ -199,6 +200,7 @@ def __init__(
self.cli_app_id = cli_app_id
self.auto_create_cli_app = auto_create_cli_app
self.host_dotnet_on_windows = host_dotnet_on_windows
self.enable_profiler = enable_profiler

self.cli_config: Dict[str, Union[str, UUID]] = {
"client_id": self.cli_app_id,
Expand Down Expand Up @@ -637,6 +639,10 @@ def deploy_template(self) -> None:
self.host_dotnet_on_windows,
)

logger.info(
"template parameter enable_profiler is set to: %s", self.enable_profiler
)

params = {
"app_func_audiences": {"value": app_func_audiences},
"name": {"value": self.application_name},
Expand All @@ -649,6 +655,7 @@ def deploy_template(self) -> None:
"workbookData": {"value": self.workbook_data},
"use_dotnet_agent_functions": {"value": self.use_dotnet_agent_functions},
"enable_remote_debugging": {"value": self.host_dotnet_on_windows},
"enable_profiler" : {"value": self.enable_profiler},
}
deployment = Deployment(
properties=DeploymentProperties(
Expand Down Expand Up @@ -1422,6 +1429,12 @@ def main() -> None:
action="store_true",
help="Use windows runtime for hosting dotnet Azure Function",
)

parser.add_argument(
"--enable_profiler",
action="store_true",
help="Enable CPU and memory profiler in dotnet Azure Function",
)
args = parser.parse_args()

if shutil.which("func") is None:
Expand Down Expand Up @@ -1456,6 +1469,7 @@ def main() -> None:
cli_app_id=args.cli_app_id,
auto_create_cli_app=args.auto_create_cli_app,
host_dotnet_on_windows=args.host_dotnet_on_windows,
enable_profiler=args.enable_profiler,
)
if args.verbose:
level = logging.DEBUG
Expand Down

0 comments on commit 4f0b11e

Please sign in to comment.