HPCToolkit
BaseDataFile.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL: https://hpctoolkit.googlecode.com/svn/branches/hpctoolkit-hpcserver/src/tool/hpcserver/BaseDataFile.cpp $
6 // $Id: BaseDataFile.cpp 4291 2013-07-09 22:25:53Z felipet1326@gmail.com $
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 // $HeadURL: https://hpctoolkit.googlecode.com/svn/branches/hpctoolkit-hpcserver/src/tool/hpcserver/BaseDataFile.cpp $
51 //
52 // Purpose:
53 // Another level of abstraction for the data from the file.
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #include "BaseDataFile.hpp"
61 #include "Constants.hpp"
62 #include "DebugUtils.hpp"
63 
64 using namespace std;
65 
67 {
68 //-----------------------------------------------------------
69 // Global variables
70 //-----------------------------------------------------------
71 
72 
73 
74 
75  BaseDataFile::BaseDataFile(string _filename, int _headerSize)
76  {
77 
78  DEBUGCOUT(1) << "Setting Data File: " << _filename << endl;
79 
80  if (_filename != "")
81  {
82  setData(_filename, _headerSize);
83  }
84 
85  }
86 
87  int BaseDataFile::getNumberOfFiles()
88  {
89  return numFiles;
90  }
91 
92  OffsetPair* BaseDataFile::getOffsets()
93  {
94  return offsets;
95  }
96 
97  LargeByteBuffer* BaseDataFile::getMasterBuffer()
98  {
99  return masterBuff;
100  }
101 
102  /***
103  * set the data to the specified file
104  */
105  void BaseDataFile::setData(string filename, int headerSize)
106  {
107  masterBuff = new LargeByteBuffer(filename, headerSize);
108 
109  FileOffset currentPos = 0;
110  type = masterBuff->getInt(currentPos);
111  currentPos += SIZEOF_INT;
112  numFiles = masterBuff->getInt(currentPos);
113  currentPos += SIZEOF_INT;
114 
115  processIDs = new int[numFiles];
116  threadIDs = new short[numFiles];
117  offsets = new OffsetPair[numFiles];
118 
119 
120 
121  offsets[numFiles-1].end = masterBuff->size()- SIZE_OF_TRACE_RECORD - SIZEOF_END_OF_FILE_MARKER;
122  // get the procs and threads IDs and build the table that maps rank to file position
123  for (int i = 0; i < numFiles; i++)
124  {
125  int proc_id = masterBuff->getInt(currentPos);
126  currentPos += SIZEOF_INT;
127  int thread_id = masterBuff->getInt(currentPos);
128  currentPos += SIZEOF_INT;
129 
130  offsets[i].start = masterBuff->getLong(currentPos);
131  //offset.end is the position of the last trace record that is a part of that line
132  if (i > 0)
133  offsets[i-1].end = offsets[i].start - SIZE_OF_TRACE_RECORD;
134  currentPos += SIZEOF_LONG;
135 
136 
137  //--------------------------------------------------------------------
138  // adding list of x-axis
139  //--------------------------------------------------------------------
140 
141 
142  if (isHybrid())
143  {
144  processIDs[i] = proc_id;
145  threadIDs[i] = thread_id;
146  }
147  else if (isMultiProcess())
148  {
149  processIDs[i] = proc_id;
150  threadIDs[i] = -1;
151  }
152  else
153  {
154  // If the application is neither hybrid nor multiproc nor multithreads,
155  // we just print whatever the order of file name alphabetically
156  // this is not the ideal solution, but we cannot trust the value of proc_id and thread_id
157  processIDs[i] = i;
158  threadIDs[i] = -1;
159  }
160 
161  }
162  }
163 
164 //Check if the application is a multi-processing program (like MPI)
165  bool BaseDataFile::isMultiProcess()
166  {
167  return (type & MULTI_PROCESSES) != 0;
168  }
169 //Check if the application is a multi-threading program (OpenMP for instance)
170  bool BaseDataFile::isMultiThreading()
171  {
172  return (type & MULTI_THREADING) != 0;
173  }
174 //Check if the application is a hybrid program (MPI+OpenMP)
175  bool BaseDataFile::isHybrid()
176  {
177  return (isMultiProcess() && isMultiThreading());
178 
179  }
180 
181  BaseDataFile::~BaseDataFile()
182  {
183  delete(masterBuff);
184  delete[] processIDs;
185  delete[] threadIDs;
186  delete[] offsets;
187  }
188 
189 } /* namespace TraceviewerServer */
#define SIZEOF_LONG
Definition: Constants.hpp:66
#define SIZEOF_END_OF_FILE_MARKER
Definition: Constants.hpp:75
#define SIZEOF_INT
Definition: Constants.hpp:67
#define SIZE_OF_TRACE_RECORD
Definition: Constants.hpp:74
uint64_t FileOffset
Definition: FileUtils.hpp:78
#define DEBUGCOUT(a)
Definition: DebugUtils.hpp:72