HPCToolkit
main.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // src/tool/hpctracedump/main.cpp
51 //
52 // Purpose:
53 // a program that dumps a trace file recorded by hpcrun
54 //
55 // Description:
56 // driver program that uses library functions to read a trace file
57 //
58 //***************************************************************************
59 
60 //***************************************************************************
61 // local include files
62 //***************************************************************************
63 
64 #include <lib/prof-lean/hpcfmt.h>
66 
67 
68 
69 //***************************************************************************
70 // interface functions
71 //***************************************************************************
72 
73 int
74 main(int argc, char **argv)
75 {
76  int ret;
77  if (argc < 2) {
78  fprintf(stderr, "usage: %s <filename>\n", argv[0]);
79  exit(-1);
80  }
81  char *fileName = argv[1];
82  char* infsBuf = new char[HPCIO_RWBufferSz];
83 
84  FILE* infs = hpcio_fopen_r(fileName);
85 
86  if (!infs) {
87  fprintf(stderr, "%s: error opening trace file %s\n", argv[0], fileName);
88  }
89 
90  ret = setvbuf(infs, infsBuf, _IOFBF, HPCIO_RWBufferSz);
91 
92  if (ret != 0) {
93  fprintf(stderr, "%s: setvbuf failed\n", argv[0]);
94  exit(-1);
95  }
96 
98 
99  ret = hpctrace_fmt_hdr_fread(&hdr, infs);
100 
101  if (ret != HPCFMT_OK) {
102  fprintf(stderr, "%s: unable to read header for %s\n", argv[0], fileName);
103  exit(-1);
104  }
105 
106  // read and dump trace records until EOF
107  while ( !feof(infs) ) {
108  hpctrace_fmt_datum_t datum;
109 
110  ret = hpctrace_fmt_datum_fread(&datum, hdr.flags, infs);
111 
112  if (ret == HPCFMT_EOF) {
113  break;
114  }
115  else if (ret == HPCFMT_ERR) {
116  fprintf(stderr, "%s: error reading trace file %s\n", argv[0], fileName);
117  exit(-1);
118  }
119 
120  printf("%d\n", datum.cpId);
121  }
122 
123  hpcio_fclose(infs);
124 
125  delete[] infsBuf;
126 
127  return 0;
128 }
exit
Definition: names.cpp:1
int main(int argc, char *argv[])
Definition: main.cpp:125
hpctrace_hdr_flags_t flags
Definition: hpcrun-fmt.h:668
FILE * hpcio_fopen_r(const char *fnm)
Definition: hpcio.c:134
int hpctrace_fmt_hdr_fread(hpctrace_fmt_hdr_t *hdr, FILE *infs)
Definition: hpcrun-fmt.c:795
int hpcio_fclose(FILE *fs)
Definition: hpcio.c:152
int hpctrace_fmt_datum_fread(hpctrace_fmt_datum_t *x, hpctrace_hdr_flags_t flags, FILE *fs)
Definition: hpcrun-fmt.c:901
#define HPCIO_RWBufferSz
Definition: hpcio.h:86