Skip to content

Commit e56ec66

Browse files
authored
Merge pull request #98430 from erhopf/obj-tracking
[CogSvcs] Obj tracking for Speech SDK
2 parents 2f5fc13 + e5b6081 commit e56ec66

File tree

2 files changed

+152
-1
lines changed

2 files changed

+152
-1
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
title: How to track Speech SDK memory usage - Speech service
3+
titleSuffix: Azure Cognitive Services
4+
description: The Speech Service SDK supports numerous programming languages for speech-to-text and text-to-speech conversion, along with speech translation. This article discusses memory management tooling built into the SDK.
5+
services: cognitive-services
6+
author: erhopf
7+
manager: nitinme
8+
ms.service: cognitive-services
9+
ms.subservice: speech-service
10+
ms.topic: conceptual
11+
ms.date: 12/10/2019
12+
ms.author: rhurey
13+
zone_pivot_groups: programming-languages-set-two
14+
---
15+
16+
# How to track Speech SDK memory usage
17+
18+
The Speech SDK is based on a native code base that's projected into multiple programming languages through a series of interoperability layers. Each language-specific projection has idiomatically correct features to manage the object lifecycle. Additionally, the Speech SDK includes memory management tooling to track resource usage with object logging and object limits.
19+
20+
## How to read object logs
21+
22+
If [Speech SDK logging is enabled](how-to-use-logging.md), tracking tags are emitted to enable historical object observation. These tags include:
23+
24+
* `TrackHandle` or `StopTracking`
25+
* The object type
26+
* The current number of objects that are tracked the type of the object, and the current number being tracked.
27+
28+
Here's a sample log:
29+
30+
```terminal
31+
(284): 8604ms SPX_DBG_TRACE_VERBOSE: handle_table.h:90 TrackHandle type=Microsoft::CognitiveServices::Speech::Impl::ISpxRecognitionResult handle=0x0x7f688401e1a0, ptr=0x0x7f688401e1a0, total=19
32+
```
33+
34+
## Set a warning threshold
35+
36+
You have the option to create a warning threshold, and if that threshold is exceeded (assuming logging is enabled), a warning message is logged. The warning message contains a dump of all objects in existence along with their count. This information can be used to better understand issues.
37+
38+
To enable a warning threshold, it must be specified on a `SpeechConfig` object. This object is checked when a new recognizer is created. In the following examples, let's assume that you've created an instance of `SpeechConfig` called `config`:
39+
40+
::: zone pivot="programming-language-csharp"
41+
42+
```csharp
43+
config.SetProperty("SPEECH-ObjectCountWarnThreshold", "10000");
44+
```
45+
46+
::: zone-end
47+
48+
::: zone pivot="programming-language-cpp"
49+
50+
```C++
51+
config->SetProperty("SPEECH-ObjectCountWarnThreshold", "10000");
52+
```
53+
54+
::: zone-end
55+
56+
::: zone pivot="programming-language-java"
57+
58+
```java
59+
config.setProperty("SPEECH-ObjectCountWarnThreshold", "10000");
60+
```
61+
62+
::: zone-end
63+
64+
::: zone pivot="programming-language-python"
65+
66+
```Python
67+
speech_config.set_property_by_name(“SPEECH-ObjectCountWarnThreshold", "10000")?
68+
```
69+
70+
::: zone-end
71+
72+
::: zone pivot="programming-language-more"
73+
74+
```ObjectiveC
75+
[config setPropertyTo:@"10000" byName:"SPEECH-ObjectCountWarnThreshold"];
76+
```
77+
78+
::: zone-end
79+
80+
> [!TIP]
81+
> The default value for this property is 10,000.
82+
83+
## Set an error threshold
84+
85+
Using the Speech SDK, you can set the maximum number of objects allowed at a given time. If this setting is enabled, when the maximum number is hit, attempts to create new recognizer objects will fail. Existing objects will continue to work.
86+
87+
Here's a sample error:
88+
89+
```terminal
90+
Runtime error: The maximum object count of 500 has been exceeded.
91+
The threshold can be adjusted by setting the SPEECH-ObjectCountErrorThreshold property on the SpeechConfig object.
92+
See http://https://docs.microsoft.com/azure/cognitive-services/speech-service/how-to-object-tracking-speech-sdk for more detailed information.
93+
Handle table dump by ojbect type:
94+
class Microsoft::CognitiveServices::Speech::Impl::ISpxRecognitionResult 0
95+
class Microsoft::CognitiveServices::Speech::Impl::ISpxRecognizer 0
96+
class Microsoft::CognitiveServices::Speech::Impl::ISpxAudioConfig 0
97+
class Microsoft::CognitiveServices::Speech::Impl::ISpxSpeechConfig 0
98+
```
99+
100+
To enable an error threshold, it must be specified on a `SpeechConfig` object. This object is checked when a new recognizer is created. In the following examples, let's assume that you've created an instance of `SpeechConfig` called `config`:
101+
102+
::: zone pivot="programming-language-csharp"
103+
104+
```csharp
105+
config.SetProperty("SPEECH-ObjectCountErrorThreshold", "10000");
106+
```
107+
108+
::: zone-end
109+
110+
::: zone pivot="programming-language-cpp"
111+
112+
```C++
113+
config->SetProperty("SPEECH-ObjectCountErrorThreshold", "10000");
114+
```
115+
116+
::: zone-end
117+
118+
::: zone pivot="programming-language-java"
119+
120+
```java
121+
config.setProperty("SPEECH-ObjectCountErrorThreshold", "10000");
122+
```
123+
124+
::: zone-end
125+
126+
::: zone pivot="programming-language-python"
127+
128+
```Python
129+
speech_config.set_property_by_name(“SPEECH-ObjectCountErrorThreshold", "10000")?
130+
```
131+
132+
::: zone-end
133+
134+
::: zone pivot="programming-language-more"
135+
136+
```objc
137+
[config setPropertyTo:@"10000" byName:"SPEECH-ObjectCountErrorThreshold"];
138+
```
139+
140+
::: zone-end
141+
142+
> [!TIP]
143+
> The default value for this property is the platform-specific maximum value for a `size_t` data type. A typical recognition will consume between 7 and 10 internal objects.
144+
145+
## Next steps
146+
147+
* [Get your Speech service trial subscription](get-started.md)
148+
* [Learn how to recognize speech using a microphone](quickstarts/speech-to-text-from-microphone.md)

articles/cognitive-services/Speech-Service/toc.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,11 @@
405405
href: quickstarts/setup-platform.md?pivots=programming-language-more
406406
- name: How-to guides
407407
items:
408-
- name: Enable logging
408+
- name: How to enable logging
409409
href: how-to-use-logging.md
410+
- name: How to track memory usage
411+
href: how-to-track-speech-sdk-memory-usage.md
412+
displayName: "memory usage, memory consumption, object logging, object tracking, memory"
410413
- name: Samples
411414
items:
412415
- name: Speech SDK Samples (GitHub)

0 commit comments

Comments
 (0)