Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

decperf.cxx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* Copyright 2015 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. /*
  19. * This program reads files produced by TightVNC's/TurboVNC's
  20. * compare-encodings. It is basically a dump of the RFB protocol
  21. * from the server side from the ServerInit message and forward.
  22. * It is assumed that the client is using a bgr888 (LE) pixel
  23. * format.
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <math.h>
  28. #include <rdr/Exception.h>
  29. #include <rdr/FileInStream.h>
  30. #include <rfb/CConnection.h>
  31. #include <rfb/CMsgReader.h>
  32. #include <rfb/Decoder.h>
  33. #include <rfb/PixelBuffer.h>
  34. #include <rfb/PixelFormat.h>
  35. #include "util.h"
  36. // FIXME: Files are always in this format
  37. static const rfb::PixelFormat filePF(32, 24, false, true, 255, 255, 255, 0, 8, 16);
  38. class CConn : public rfb::CConnection {
  39. public:
  40. CConn(const char *filename);
  41. ~CConn();
  42. virtual void setDesktopSize(int w, int h);
  43. virtual void setPixelFormat(const rfb::PixelFormat& pf);
  44. virtual void setCursor(int, int, const rfb::Point&, void*, void*);
  45. virtual void dataRect(const rfb::Rect&, int);
  46. virtual void setColourMapEntries(int, int, rdr::U16*);
  47. virtual void bell();
  48. virtual void serverCutText(const char*, rdr::U32);
  49. public:
  50. double cpuTime;
  51. protected:
  52. rdr::FileInStream *in;
  53. rfb::Decoder *decoders[rfb::encodingMax+1];
  54. rfb::ManagedPixelBuffer pb;
  55. };
  56. CConn::CConn(const char *filename)
  57. {
  58. int i;
  59. cpuTime = 0.0;
  60. in = new rdr::FileInStream(filename);
  61. setStreams(in, NULL);
  62. memset(decoders, 0, sizeof(decoders));
  63. for (i = 0;i < rfb::encodingMax;i++) {
  64. if (!rfb::Decoder::supported(i))
  65. continue;
  66. decoders[i] = rfb::Decoder::createDecoder(i, this);
  67. }
  68. // Need to skip the initial handshake
  69. setState(RFBSTATE_INITIALISATION);
  70. // That also means that the reader and writer weren't setup
  71. setReader(new rfb::CMsgReader(this, in));
  72. }
  73. CConn::~CConn()
  74. {
  75. int i;
  76. delete in;
  77. for (i = 0;i < rfb::encodingMax;i++)
  78. delete decoders[i];
  79. }
  80. void CConn::setDesktopSize(int w, int h)
  81. {
  82. CConnection::setDesktopSize(w, h);
  83. pb.setSize(cp.width, cp.height);
  84. }
  85. void CConn::setPixelFormat(const rfb::PixelFormat& pf)
  86. {
  87. // Override format
  88. CConnection::setPixelFormat(filePF);
  89. pb.setPF(cp.pf());
  90. }
  91. void CConn::setCursor(int, int, const rfb::Point&, void*, void*)
  92. {
  93. }
  94. void CConn::dataRect(const rfb::Rect &r, int encoding)
  95. {
  96. if (!decoders[encoding])
  97. throw rdr::Exception("Unknown encoding");
  98. startCpuCounter();
  99. decoders[encoding]->readRect(r, &pb);
  100. endCpuCounter();
  101. cpuTime += getCpuCounter();
  102. }
  103. void CConn::setColourMapEntries(int, int, rdr::U16*)
  104. {
  105. }
  106. void CConn::bell()
  107. {
  108. }
  109. void CConn::serverCutText(const char*, rdr::U32)
  110. {
  111. }
  112. static double runTest(const char *fn)
  113. {
  114. CConn *cc;
  115. double time;
  116. try {
  117. cc = new CConn(fn);
  118. } catch (rdr::Exception e) {
  119. fprintf(stderr, "Failed to open rfb file: %s\n", e.str());
  120. exit(1);
  121. }
  122. try {
  123. while (true)
  124. cc->processMsg();
  125. } catch (rdr::EndOfStream e) {
  126. } catch (rdr::Exception e) {
  127. fprintf(stderr, "Failed to run rfb file: %s\n", e.str());
  128. exit(1);
  129. }
  130. time = cc->cpuTime;
  131. delete cc;
  132. return time;
  133. }
  134. static void sort(double *array, int count)
  135. {
  136. bool sorted;
  137. int i;
  138. do {
  139. sorted = true;
  140. for (i = 1;i < count;i++) {
  141. if (array[i-1] > array[i]) {
  142. double d;
  143. d = array[i];
  144. array[i] = array[i-1];
  145. array[i-1] = d;
  146. sorted = false;
  147. }
  148. }
  149. } while (!sorted);
  150. }
  151. static const int runCount = 9;
  152. int main(int argc, char **argv)
  153. {
  154. int i;
  155. double times[runCount], dev[runCount];
  156. double median, meddev;
  157. if (argc != 2) {
  158. printf("Syntax: %s <rfb file>\n", argv[0]);
  159. return 1;
  160. }
  161. // Warmup
  162. runTest(argv[1]);
  163. // Multiple runs to get a good average
  164. for (i = 0;i < runCount;i++)
  165. times[i] = runTest(argv[1]);
  166. // Calculate median and median deviation
  167. sort(times, runCount);
  168. median = times[runCount/2];
  169. for (i = 0;i < runCount;i++)
  170. dev[i] = fabs((times[i] - median) / median) * 100;
  171. sort(dev, runCount);
  172. meddev = dev[runCount/2];
  173. printf("CPU time: %g s (+/- %g %%)\n", median, meddev);
  174. return 0;
  175. }