source: examples/tutorial/createdemo.c @ ee0805a

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since ee0805a was 8835f5a, checked in by Shane Alcock <salcock@…>, 11 years ago
  • Added the code examples from the PDCAT tutorial to the bundled examples
  • Property mode set to 100644
File size: 1.2 KB
Line 
1/* Skeleton libtrace program that demonstrates how to create, start and
2 * destroy a trace in a nice clean manner with full error-checking (because
3 * error handling is good!)
4 */
5
6/* All libtrace programs require libtrace.h to be included */
7#include "libtrace.h"
8#include <stdio.h>
9
10int main(int argc, char *argv[])
11{
12        libtrace_t *trace;
13       
14        /* Ensure we have at least one argument after the program name */
15        if (argc < 2) {
16                fprintf(stderr, "Usage: %s inputURI\n", argv[0]);
17                return 1;
18        }
19       
20        /* trace_create initialises our trace structure */
21        trace = trace_create(argv[1]);
22
23        /* Check if an error occurred, i.e. the URI was incorrect or the file
24         * does not exist */
25        if (trace_is_err(trace)) {
26                trace_perror(trace,"Opening trace file");
27                return 1;
28        }
29
30        /* Start the trace, being sure to check if any error occurs during the
31         * starting phase */
32        if (trace_start(trace) == -1) {
33                trace_perror(trace,"Starting trace");
34                trace_destroy(trace);
35                return 1;
36        }
37
38        /* Now our trace is open and ready for reading, but that is beyond
39         * the scope of this example */
40
41        /* Program is over, so destroy the trace structure */
42        trace_destroy(trace);
43        return 0;
44}
Note: See TracBrowser for help on using the repository browser.