# How to access Deepstream latency informations in python

**URL:** <https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588>\
**Category:** DeepStream SDK\
**Tags:** python\
**Created:** [October 6, 2023, 7:12am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588 "2023-10-06T07:12:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex6s](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alex6s](https://forums.developer.nvidia.com/u/Alex6s)\
**Post date:** [October 6, 2023, 7:12am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/1 "2023-10-06T07:12:51Z")

</div>

Please provide complete information as applicable to your setup.

**• Hardware Platform (Jetson / GPU)** Jetson Orin AGX  
**• DeepStream Version** 6.2  
**• JetPack Version (valid for Jetson only)** 5.1.1  
**• TensorRT Version**  
**• NVIDIA GPU Driver Version (valid for GPU only)**  
**• Issue Type( questions, new requirements, bugs)** question  
**• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)**  
**• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)**

I want to get the latency of a (or multiple) component(s) of my pipeline. My code is in python, using the python bindings.

I understand that in C++, we would use the function _nvds\_measure\_buffer\_latency()_, but since there is no binding in python for it, I am trying to get NVDS\_LATENCY\_MEASUREMENT\_META user meta from NvDsMetaType, as explained by Fiona.Chen here : [How to get the latency from deepstream python apps - #13 by Fiona.Chen](https://forums.developer.nvidia.com/t/how-to-get-the-latency-from-deepstream-python-apps/197227/13)

Taking example on this [NvDsUserMeta — Deepstream Deepstream Version: 6.3 documentation (nvidia.com)](https://docs.nvidia.com/metropolis/deepstream/dev-guide/python-api/PYTHON_API/NvDsMeta/NvDsUserMeta.html), I presume it would look something like this :

```auto
def latency_measurement_probe(self,pad, info, u_data):
	buffer = info.get_buffer()
	if not buffer:
	    self.logger.info('Unable to get GstBuffer')
	    return

	batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(buffer))
	l_user = batch_meta.batch_user_meta_list
	while l_user is not None:
	    try:
		user_meta=pyds.NvDsUserMeta.cast(l_user.data)
	    except StopIteration:
		break
	    if(user_meta and user_meta.base_meta.meta_type == pyds.NvDsMetaType.NVDS_LATENCY_MEASUREMENT_META):
		try:
		    latency_meta = pyds.NvDsFrameLatencyInfo.cast(user_meta.user_meta_data)
		    #or latency_meta = pyds.NvDsMetaCompLatency.cast(user_meta.user_meta_data)
		except StopIteration:
		    break
		latency_ms = latency_meta.latency

		print("Latency :",latency_ms,"ms")
	    
	return Gst.PadProbeReturn.OK

```

But neither NvDsFrameLatencyInfo nor NvDsMetaCompLatency exist in the binding. So the question is how can I access latency informations that are in the user metadata in python ?

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [October 7, 2023, 8:41am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/3 "2023-10-07T08:41:38Z")

</div>

You need to bind the structures by referring the [BINDINGSGUIDE.md](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/blob/master/bindings/BINDINGSGUIDE.md).

---

<div class="post-metadata">

**Author:** ![Alex6s](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alex6s](https://forums.developer.nvidia.com/u/Alex6s)\
**Post date:** [October 9, 2023, 3:09pm UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/5 "2023-10-09T15:09:53Z")

</div>

Thank you for the answer. I followed the guide to create binding for the NvDsFrameLatencyInfo struct, but when i look at the latency I get an absurd value (1.145327…93e+243). Am I missing something with my probe code ?

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [October 10, 2023, 2:03am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/6 "2023-10-10T02:03:14Z")

</div>

Yes. You can refer to our C demo code : `latency_info[i].latency`. The latency\_meta should be a list.

---

<div class="post-metadata">

**Author:** ![Alex6s](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alex6s](https://forums.developer.nvidia.com/u/Alex6s)\
**Post date:** [October 10, 2023, 8:37am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/7 "2023-10-10T08:37:30Z")

</div>

I see, but currently my variable latency\_meta is non iterable, maybe i’m casting it wrong ?  
here is my binding code (I also added binding for the nvds\_measure\_buffer\_latency function but didn’t get more success with it, I just don’t get how to call the function in python)

```auto
    void bindnvds_latency_meta(py::module &m) {
        py::class_<NvDsFrameLatencyInfo>(m, "NvDsFrameLatencyInfo",
                                pydsdoc::nvds_latency_metadoc::NvDsFrameLatencyInfoDoc::descr)
        .def(py::init<>()) // Constructor wrapper, empty for struct
        .def_readwrite("source_id", &NvDsFrameLatencyInfo::source_id)
        .def_readwrite("frame_num", &NvDsFrameLatencyInfo::frame_num)
        .def_readwrite("comp_in_timestamp", &NvDsFrameLatencyInfo::comp_in_timestamp)
        .def_readwrite("latency", &NvDsFrameLatencyInfo::latency)
        .def("cast",
            [](void *data) { // Function definition
                return (NvDsFrameLatencyInfo *) data; // Cast void* to NvDsLatencyInfo*
            },
            py::return_value_policy::reference, // Ownership of return object must remain with C++
            pydsdoc::nvds_latency_metadoc::NvDsFrameLatencyInfoDoc::cast); // Docstring
        m.def("nvds_measure_buffer_latency",
        &nvds_measure_buffer_latency,
        "buf"_a,
        "latency_info"_a,
        py::return_value_policy::reference,
        pydsdoc::methodsDoc::nvds_measure_buffer_latency);
    } // Define the bindings function declared in the header file

```

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [October 11, 2023, 7:48am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/8 "2023-10-11T07:48:11Z")

</div>

OK. We will try adding this feature next version and notify you once it is completed.

---

<div class="post-metadata">

**Author:** ![Alex6s](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alex6s](https://forums.developer.nvidia.com/u/Alex6s)\
**Post date:** [October 11, 2023, 8:08am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/10 "2023-10-11T08:08:17Z")

</div>

Thank you very much, i’m sure it will help a lot of peoples

---

<div class="post-metadata">

**Author:** ![omarabdallah300](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@omarabdallah300](https://forums.developer.nvidia.com/u/omarabdallah300)\
**Post date:** [October 23, 2023, 4:32pm UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/11 "2023-10-23T16:32:30Z")

</div>

Hi there, I came across this thread when I was looking for a method to get latency info for the pipeline in python, I wanted to ask is there any update on the availability of the feature anytime soon? @yuweiw

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [October 24, 2023, 3:07am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/12 "2023-10-24T03:07:58Z")

</div>

We will release this feature in our next version.

---

<div class="post-metadata">

**Author:** ![omhaimov](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@omhaimov](https://forums.developer.nvidia.com/u/omhaimov)\
**Post date:** [January 7, 2025, 5:01pm UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/13 "2025-01-07T17:01:56Z")

</div>

Hi, I came across this thread as well.  
Is there news regarding exposing the latency information in python? @yuweiw

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [January 8, 2025, 3:12am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/14 "2025-01-08T03:12:34Z")

</div>

Yes. Please refer to our latest [deepstream-test3](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/tree/master/apps/deepstream-test3) sample.

---

<div class="post-metadata">

**Author:** ![Fiona.Chen](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fiona.chen/32/15508_2.png) [@Fiona.Chen](https://forums.developer.nvidia.com/u/Fiona.Chen)\
**Post date:** [March 10, 2025, 6:41am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/15 "2025-03-10T06:41:44Z")

</div>

**There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks**

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [March 24, 2025, 6:42am UTC](https://forums.developer.nvidia.com/t/how-to-access-deepstream-latency-informations-in-python/268588/16 "2025-03-24T06:42:35Z")

</div>

Closed on March 24, 2025, 6:42am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
