Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4. #include <fstream>
  5. #include <sstream>
  6. #define c 29
  7. using namespace std;
  8. string fSplit(const string& fString, int which)
  9. {
  10.  
  11. istringstream iss; string val;
  12. iss.str(fString);
  13. for (int i = 0; i < which; i++) {
  14.  
  15. iss >> val;
  16.  
  17. }return val;
  18. }
  19. int main()
  20. {
  21. int i = 0, j = 0, k = 0, linecount = 0, line = 0, pick = 0, skip = 0;
  22. string testline;
  23. string store[c];
  24. string node[c];
  25. string word[49];
  26. string temp;
  27. string cpus[c];
  28. string used[c];
  29. string mem[c];
  30. string state[c];
  31.  
  32. string total[4];
  33. int cputot[5], usedtot[5], memtot[5];
  34. int jobcount = 0;
  35. string *storejobs;
  36. string *jobid;
  37. string *username;
  38. string *queue;
  39. string *jobname;
  40. string *ssid;
  41. string *nds;
  42. string *tsk;
  43. string *reqmem;
  44. string *reqtime;
  45. string *s;
  46. string *elaptime;
  47. string *nodelist;
  48. fstream Test;
  49. Test.open("pbs_output.txt", fstream::in);
  50.  
  51. if (!Test)
  52. {
  53. cout << "There was a problem opening the file. Press any key to close.\n";
  54. getchar();
  55. return 0;
  56. }
  57. //store words in array
  58. while (getline(Test, testline))
  59. {
  60. if (testline != "")
  61. {
  62. word[i] = testline;
  63. i++;
  64. }
  65. }
  66. Test.close();
  67. for (int k = 0; k < i; k++)
  68. {
  69. if (word[k] == "Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time") {
  70. k = k + 2;
  71. while (word[k] != "NODE CPUS USED MEM STATE") {
  72. jobcount++;
  73. k++;
  74. }
  75. }
  76. }
  77. storejobs = new string[jobcount];
  78. jobid = new string[jobcount];
  79. username = new string[jobcount];
  80. queue = new string[jobcount];
  81. jobname = new string[jobcount];
  82. ssid = new string[jobcount];
  83. nds = new string[jobcount];
  84. tsk = new string[jobcount];
  85. reqmem = new string[jobcount];
  86. reqtime = new string[jobcount];
  87. s = new string[jobcount];
  88. elaptime = new string[jobcount];
  89. nodelist = new string[jobcount];
  90. for (int k = 0; k < i; k++)
  91. {
  92. if (word[k] == "Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time") {
  93. k = k + 2;
  94. while (word[k] != "NODE CPUS USED MEM STATE") {
  95. storejobs[j] = word[k];
  96. k++;
  97. j++;
  98. }
  99. }
  100. }
  101. for (k = 0; k < jobcount; k++)
  102. {
  103. jobid[k] = fSplit(storejobs[k], 1);
  104. username[k] = fSplit(storejobs[k], 2);
  105. queue[k] = fSplit(storejobs[k], 3);
  106. jobname[k] = fSplit(storejobs[k], 4);
  107. ssid[k] = fSplit(storejobs[k], 5);
  108. nds[k] = fSplit(storejobs[k], 6);
  109. tsk[k] = fSplit(storejobs[k], 7);
  110. reqmem[k] = fSplit(storejobs[k], 8);
  111. reqtime[k] = fSplit(storejobs[k], 9);
  112. s[k] = fSplit(storejobs[k], 10);
  113. elaptime[k] = fSplit(storejobs[k], 11);
  114. nodelist[k] = fSplit(storejobs[k], 12);
  115. //cout <<endl << jobid[k] << endl << queue[k] << endl << jobname[k] << endl << ssid[k] << endl << nds[k] << endl << tsk[k] << endl << reqmem[k] << endl << reqtime[k] << endl << elaptime[k] << endl << jobid[k] << endl << nodelist[k] << endl << endl;
  116. }
  117. for (int k = 0; k < i; k++)
  118. {
  119. if (word[k] == "NODE CPUS USED MEM STATE") {
  120. line++;
  121. if (line == 1)//occurence one
  122. {
  123. pick = 1;//line counter
  124. while (pick < 5) //take first five lines of following the first occurence
  125. {
  126. temp = word[k + pick];
  127. store[linecount] = temp;//store each line
  128. linecount++;
  129. pick++;
  130. }
  131. if (pick >= 5)
  132. {
  133. total[3] = word[k + pick + 1];
  134. }
  135. }
  136. else if (line == 2)
  137. {
  138. pick = 1;
  139. while (pick < 10)
  140. {
  141. temp = word[k + pick];
  142. store[linecount] = temp;
  143. linecount++;
  144. pick++;
  145. }
  146. if (pick >= 10)
  147. {
  148. total[0] = word[k + pick + 1];
  149. }
  150. }
  151. else if (line == 3)
  152. {
  153. pick = 1;
  154. while (pick < 11)
  155. {
  156. temp = word[k + pick];
  157. store[linecount] = temp;
  158. linecount++;
  159. pick++;
  160. }
  161. if (pick >= 11)
  162. {
  163. total[1] = word[k + pick + 1];
  164. }
  165. }
  166. else if (line == 4)
  167. {
  168. pick = 1;
  169. while (pick < 7)
  170. {
  171. temp = word[k + pick];
  172. store[linecount] = temp;
  173. linecount++;
  174. pick++;
  175. }
  176. if (pick >= 7)
  177. {
  178. total[2] = word[k + pick + 1];
  179. }
  180. }
  181.  
  182. }
  183. }
  184. cout << linecount << endl;
  185.  
  186. for (j = 0; j < linecount; j++)
  187. {
  188. node[j] = fSplit(store[j], 1);
  189. cpus[j] = fSplit(store[j], 2);
  190. used[j] = fSplit(store[j], 3);
  191. mem[j] = fSplit(store[j], 4);
  192. state[j] = fSplit(store[j], 5);
  193. }
  194. for (i = 0; i < 4; i++)
  195. {
  196. stringstream(fSplit(total[i], 2)) >> cputot[i];
  197. stringstream(fSplit(total[i], 3)) >> usedtot[i];
  198. stringstream(fSplit(total[i], 4)) >> memtot[i];
  199. }
  200. cputot[4] = cputot[0] + cputot[1] + cputot[2];
  201. usedtot[4] = usedtot[0] + usedtot[1] + usedtot[2];
  202. memtot[4] = memtot[0] + memtot[1] + memtot[2];
  203. //for (i = 0; i < linecount; i++) {
  204.  
  205. //cout << node[i] << endl << cpus[i] << endl << used[i] << endl << mem[i] << endl << state[i] << endl;
  206. //}
  207. //cout << memtot[3]<<endl<< usedtot[3]<<endl<< cputot[3];
  208. fstream json;
  209. json.open("data.json", fstream::out);
  210. if (!json)
  211. {
  212. cout << "There was a problem opening the file. Press any key to close.\n";
  213. getchar();
  214. return 0;
  215. }
  216. json << "{" << endl << "\t\"jobs\": [" << endl << endl;
  217. for (i = 0; i < jobcount - 1; i++)
  218. {
  219. json << "\t\t{" << endl << endl << "\t\t\t\"jobid\": " << "\"" << jobid[i] << "\"," << endl;
  220. json << "\t\t\t\"username\": " << "\"" << username[i] << "\"," << endl;
  221. json << "\t\t\t\"queue\": " << "\"" << queue[i] << "\"," << endl;
  222. json << "\t\t\t\"jobname\": " << "\"" << jobname[i] << "\"," << endl;
  223. json << "\t\t\t\"ssid\": " << "\"" << ssid[i] << "\"," << endl;
  224. json << "\t\t\t\"nds\": " << "\"" << nds[i] << "\"," << endl;
  225. json << "\t\t\t\"tsk\": " << "\"" << tsk[i] << "\"," << endl;
  226. json << "\t\t\t\"reqmem\": " << "\"" << reqmem[i] << "\"," << endl;
  227. json << "\t\t\t\"reqtime\": " << "\"" << reqtime[i] << "\"," << endl;
  228. json << "\t\t\t\"s\": " << "\"" << s[i] << "\"," << endl;
  229. json << "\t\t\t\"elaptime\": " << "\"" << elaptime[i] << "\"," << endl;
  230. json << "\t\t\t\"nodelist\": " << "\"" << nodelist[i] << "\"" << endl << "\t\t}," << endl;
  231. }
  232. for (i = jobcount - 1; i < jobcount; i++)
  233. {
  234. json << "\t\t{" << endl << endl << "\t\t\t\"jobid\": " << "\"" << jobid[i] << "\"," << endl;
  235. json << "\t\t\t\"username\": " << "\"" << username[i] << "\"," << endl;
  236. json << "\t\t\t\"queue\": " << "\"" << queue[i] << "\"," << endl;
  237. json << "\t\t\t\"jobname\": " << "\"" << jobname[i] << "\"," << endl;
  238. json << "\t\t\t\"ssid\": " << "\"" << ssid[i] << "\"," << endl;
  239. json << "\t\t\t\"nds\": " << "\"" << nds[i] << "\"," << endl;
  240. json << "\t\t\t\"tsk\": " << "\"" << tsk[i] << "\"," << endl;
  241. json << "\t\t\t\"reqmem\": " << "\"" << reqmem[i] << "\"," << endl;
  242. json << "\t\t\t\"reqtime\": " << "\"" << reqtime[i] << "\"," << endl;
  243. json << "\t\t\t\"s\": " << "\"" << s[i] << "\"," << endl;
  244. json << "\t\t\t\"elaptime\": " << "\"" << elaptime[i] << "\"," << endl;
  245. json << "\t\t\t\"nodelist\": " << "\"" << nodelist[i] << "\"" << endl << "\t\t}" << endl << "],";
  246. }
  247. json << endl << "\t\"nodes\": [" << endl << endl;
  248. for (i = 0; i < 28; i++)
  249. {
  250. json << "\t\t{" << endl << endl << "\t\t\t\"NODE\": " << "\"" << node[i] << "\"," << endl;
  251. json << "\t\t\t\"CPU\": " << "\"" << cpus[i] << "\"," << endl;
  252. json << "\t\t\t\"USED\": " << "\"" << used[i] << "\"," << endl;
  253. json << "\t\t\t\"MEM\": " << "\"" << mem[i] << "\"," << endl;
  254. json << "\t\t\t\"STATE\": " << "\"" << state[i] << "\"" << endl << "\t\t}," << endl;
  255. }
  256.  
  257. for (i = 28; i < 29; i++)
  258. {
  259. json << "\t\t{" << endl << endl << "\t\t\t\"NODE\": " << "\"" << node[i] << "\"," << endl;
  260. json << "\t\t\t\"CPU\": " << "\"" << cpus[i] << "\"," << endl;
  261. json << "\t\t\t\"USED\": " << "\"" << used[i] << "\"," << endl;
  262. json << "\t\t\t\"MEM\": " << "\"" << mem[i] << "\"," << endl;
  263. json << "\t\t\t\"STATE\": " << "\"" << state[i] << "\"" << endl << "\t\t}" << endl << "]," << endl;
  264. }
  265. json << endl << "\t\"node9tot\": [" << endl << endl;
  266. json << "\t\t{" << endl << endl << "\t\t\t\"cputot\": " << "\"" << cputot[3] << "\"," << endl;
  267. json << "\t\t\t\"usedtot\": " << "\"" << usedtot[3] << "\"," << endl;
  268. json << "\t\t\t\"memtot\": " << "\"" << memtot[3] << "\"" << endl << "\t\t}" << endl << "],"<<endl;
  269.  
  270. json << endl << "\t\"node0-2tot\": [" << endl << endl;
  271. json << "\t\t{" << endl << endl << "\t\t\t\"cputot\": " << "\"" << cputot[4] << "\"," << endl;
  272. json << "\t\t\t\"usedtot\": " << "\"" << usedtot[4] << "\"," << endl;
  273. json << "\t\t\t\"memtot\": " << "\"" << memtot[4] << "\"" << endl << "\t\t}" << endl << "]" << endl << "}";
  274. json.close();
  275. delete[]storejobs;
  276. system("pause"); return 0;
  277. system("pause");
  278.  
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement