main.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* #ident "$Id:$"
  2. * @author: Philippe Coval <rzr@gna.org> -- Rev: $Author: rzr $
  3. * Copyright: LGPL-3 (See README file that comes with this distribution)
  4. * -*- Mode: c++ -*-
  5. *****************************************************************************/
  6. #include <iostream>
  7. #define CONFIG_WANT_LIBTRAKO
  8. #include "trako/config.h"
  9. #include "trako/trako.h"
  10. #include "Context.h"
  11. using namespace std;
  12. class MyClass;
  13. /// sample class nothing special here, beside then lines marked @INFO
  14. class MyClass
  15. {
  16. public:
  17. void method() {
  18. TRAKO_FUNCT(); //<! @INFO: here a metaobject is injected in the function
  19. methodSub();
  20. }
  21. private:
  22. void methodSub() {
  23. TRAKO_FUNCT(); //<! @INFO: here a metaobject is injected in the function
  24. }
  25. TRAKO_CLASS(MyClass); //<! @INFO: here a metaobject is injected in the class
  26. };
  27. class MyOtherClass
  28. {
  29. public:
  30. void methodLong()
  31. {
  32. TRAKO_FUNCT(); //<! @INFO: here a metaobject is injected in the function
  33. for(int i=0;i<0xFFFF;i++){ 0xFFFFF / 42.;}
  34. }
  35. TRAKO_CLASS(MyOtherClass);
  36. };
  37. /// sample unit test programm
  38. int main(int argc, char* argv[])
  39. {
  40. TRAKO_FUNCT(); //<! @INFO:
  41. int status=0;
  42. cout<<endl<<"# Profiling classes instances"<<endl;
  43. MyClass sta;
  44. TRAKO_DIFF(); //<! @INFO:
  45. {
  46. {
  47. MyClass local;
  48. TRAKO_DIFF(); //<! @INFO:
  49. MyClass* ptr = new MyClass;
  50. TRAKO_DIFF(); //<! @INFO:
  51. delete( ptr );
  52. TRAKO_DIFF(); //<! @INFO:
  53. }
  54. //TRAKO_TYPE( MyClass ); //<! @INFO:
  55. }
  56. cout<<endl<<"# Profiling methods"<<endl;
  57. TRAKO_COUNT(); //<! @INFO
  58. {
  59. MyClass local;
  60. local.method();
  61. local.method();
  62. }
  63. TRAKO_DIFF(); //<! @INFO:
  64. MyOtherClass local;
  65. local.methodLong();
  66. TRAKO_TYPE_OF( local ); //<! @INFO:
  67. cout<<endl<<"# Profiling program"<<endl;
  68. {
  69. MyOtherClass local;
  70. }
  71. TRAKO_COUNT(); //<! @INFO:
  72. cout<<endl<<"# Profiling scopes"<<endl;
  73. for (int x=0;x<2;x++){
  74. TRAKO_SCOPE("row");
  75. for (int y=0;y<2;y++){
  76. TRAKO_SCOPE("col");
  77. }
  78. }
  79. cout<<endl<<"# Multithreading"<<endl;
  80. {
  81. MetaMutex<std::ostream> lock;
  82. TRAKO_SCOPE("mutex: this line wont be split"); //<! @INFO
  83. }
  84. cout<<endl<<"# Quitting"<<endl;
  85. return status;
  86. }