HPCToolkit
Communication-SingleThreaded.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/Communication-SingleThreaded.cpp $
6 // $Id: Communication-SingleThreaded.cpp 4307 2013-07-18 17:04:52Z 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/Communication-SingleThreaded.cpp $
51 //
52 // Purpose:
53 // The single-threaded implementation of the methods in Communication.hpp
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #include <stdint.h> // for uint64_t
61 #include <iostream> // for operator<<, basic_ostream, etc
62 #include <string> // for string
63 #include <vector> // for vector, vector<>::iterator
64 
65 #include "Communication.hpp" // for Communication
66 #include "DataCompressionLayer.hpp" // for DataCompressionLayer
67 #include "DataSocketStream.hpp" // for DataSocketStream
68 #include "DebugUtils.hpp" // for DEBUGCOUT
69 #include "Filter.hpp"
70 #include "ImageTraceAttributes.hpp" // for ImageTraceAttributes
71 #include "ProcessTimeline.hpp" // for ProcessTimeline
72 #include "ProgressBar.hpp" // for ProgressBar
73 #include "Server.hpp" // for Server
74 #include "SpaceTimeDataController.hpp" // for SpaceTimeDataController
75 #include "TimeCPID.hpp" // for TimeCPID, Time
76 #include "TraceDataByRank.hpp" // for TraceDataByRank
77 
78 
79 using namespace std;
80 namespace TraceviewerServer {
81 
82 void Communication::sendParseInfo(uint64_t minBegTime, uint64_t maxEndTime, int headerSize)
83 {//Do nothing
84 }
85 
86 void Communication::sendParseOpenDB(string pathToDB) {}
87 
88 void Communication::sendStartGetData(SpaceTimeDataController* contr, int processStart, int processEnd,
89  Time timeStart, Time timeEnd, int verticalResolution, int horizontalResolution)
90 {
91 
92  ImageTraceAttributes* correspondingAttributes = contr->attributes;
93 
94  correspondingAttributes->begProcess = processStart;
95  correspondingAttributes->endProcess = processEnd;
96  correspondingAttributes->numPixelsH = horizontalResolution;
97  correspondingAttributes->numPixelsV = verticalResolution;
98  correspondingAttributes->begTime = timeStart;
99  correspondingAttributes->endTime = timeEnd;
100  correspondingAttributes->lineNum = 0;
101 
102 
103 }
104 void Communication::sendEndGetData(DataSocketStream* stream, ProgressBar* prog, SpaceTimeDataController* controller)
105 {
106  // TODO: Make this so that the Lines get sent as soon as they are
107  // filled.
108 
109  controller->fillTraces();
110  for (int i = 0; i < controller->tracesLength; i++)
111  {
112 
113  ProcessTimeline* timeline = controller->traces[i];
114  stream->writeInt( timeline->line());
115  vector<TimeCPID> data = *timeline->data->listCPID;
116  stream->writeInt( data.size());
117  // Begin time
118  stream->writeLong( data[0].timestamp);
119  //End time
120  stream->writeLong( data[data.size() - 1].timestamp);
121 
122  DataCompressionLayer comprStr;
123 
124  vector<TimeCPID>::iterator it;
125  DEBUGCOUT(2) << "Sending process timeline with " << data.size() << " entries" << endl;
126 
127 
128  Time currentTime = data[0].timestamp;
129  for (it = data.begin(); it != data.end(); ++it)
130  {
131  comprStr.writeInt( (int)(it->timestamp - currentTime));
132  comprStr.writeInt( it->cpid);
133  currentTime = it->timestamp;
134  }
135  comprStr.flush();
136  int outputBufferLen = comprStr.getOutputLength();
137  char* outputBuffer = (char*)comprStr.getOutputBuffer();
138 
139  stream->writeInt(outputBufferLen);
140 
141  stream->writeRawData(outputBuffer, outputBufferLen);
142  prog->incrementProgress();
143  }
144  stream->flush();
145 }
146 
147 void Communication::sendStartFilter(int count, bool excludeMatches)
148 {//Do nothing
149 }
150 
151 void Communication::sendFilter(BinaryRepresentationOfFilter filt)
152 {
153 }
154 
155 bool Communication::basicInit(int argc, char** argv)
156 {
157  return true;
158 }
159 void Communication::run()
160 {
162 }
163 void Communication::closeServer()
164 {
165  cout<<"Server done, closing..."<<endl;
166 }
167 }
#define DEBUGCOUT(a)
Definition: DebugUtils.hpp:72