# Record time of samples

**URL:** <https://www.ruby-forum.com/t/record-time-of-samples/219038>\
**Category:** GNU Radio\
**Created:** [April 19, 2012, 7:44am UTC](https://www.ruby-forum.com/t/record-time-of-samples/219038 "2012-04-19T07:44:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 19, 2012, 7:44am UTC](https://www.ruby-forum.com/t/record-time-of-samples/219038/1 "2012-04-19T07:44:03Z")

</div>

Hi all,

Does anyone know how to record the exact arrival time of a package or  
the  
end of some samples using USRP? I used the following code in GRC:

if **name** == ‘ **main** ’:  
parser = OptionParser(option\_class=eng\_option, usage="%prog: [options]")  
(options, args) = parser.parse\_args()  
tb = flow\_graph()  
tb.Run(True)  
a = strftime("%Y-%m-%d %H:%M:%S", gmtime())  
print a

However, this only shows the end time when I stop the flow graph  
manually.  
Is there a way in gnuradio that can read the system time during the  
running  
of the program?

For example, the flow graph begins to run and receive --\> after 1000  
samples have been received, output system time --\> the program continues  
to  
run…

In addition, how to stop a grc flow graph automatically?

Any response will be appreciated.

Thanks in advance.

Jamie

---

<div class="post-metadata">

**Author:** ![Jamie\_Wo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@Jamie\_Wo](https://www.ruby-forum.com/u/Jamie_Wo)\
**Post date:** [April 19, 2012, 8:32am UTC](https://www.ruby-forum.com/t/record-time-of-samples/219038/2 "2012-04-19T08:32:28Z")

</div>

> Does anyone know how to record the exact arrival time of a package or the  
> end of some samples using USRP? I used the following code in GRC:

In a related note, you can use stream tags to get a precise timestamp of  
every sample in the stream:  
[http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr\_uhd\_usrp\_source.h#n59](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr_uhd_usrp_source.h#n59)

> However, this only shows the end time when I stop the flow graph manually.  
> Is there a way in gnuradio that can read the system time during the running  
> of the program?
> 
> For example, the flow graph begins to run and receive → after 1000  
> samples have been received, output system time → the program continues to  
> run…
> 
> In addition, how to stop a grc flow graph automatically?

In the non-gui mode, you can set the option “run to completion”. The  
flow graph will exit when the flow graph is “done”. Done can happen for  
example when gr\_head block sees all N inputs. See options block in grc.

-josh
