erlang各种有用的函数包括一些有用nif封装,还有一些性能测试case。
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

179 rader
4.7 KiB

5 år sedan
  1. -module(utTestTrace).
  2. -compile([export_all, nowarn_unused_function, nowarn_unused_vars, nowarn_export_all]).
  3. t1() ->
  4. Pid = spawn(fun() -> do_t1(1) end),
  5. send_msg(Pid, 100000).
  6. t2() ->
  7. Pid = spawn(fun() -> do_t2(1) end),
  8. send_msg(Pid, 100000).
  9. send_msg(Pid, 0) ->
  10. io:format("IMY***********send_msg over ~p ~n ~p ~n", [0, Pid]),
  11. ok;
  12. send_msg(Pid, N) ->
  13. Pid ! <<2:(N)>>,
  14. % timer:sleep(1),
  15. send_msg(Pid, N - 1).
  16. do_t1(N) ->
  17. case N == 1 orelse N == 90000 of
  18. true ->
  19. erlang:garbage_collect(),
  20. Result = erlang:process_info(self(), [memory, garbage_collection]),
  21. io:format("IMY************************* ~p~n ~w ~n", [N, Result]);
  22. %io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p~n backtrace:~p~n~n", [N, erlang:process_display(self(), backtrace)]);
  23. _ ->
  24. ignore
  25. end,
  26. try
  27. receive
  28. _ ->
  29. ok
  30. %% do_t1(N + 1)
  31. end,
  32. do_t1(N + 1)
  33. catch
  34. _:_ ->
  35. do_t1(N + 1)
  36. end.
  37. do_t2(N) ->
  38. case N == 1 orelse N == 90000 of
  39. true ->
  40. erlang:garbage_collect(),
  41. Result = erlang:process_info(self(), [memory, garbage_collection]),
  42. io:format("IMY************************* ~p ~n ~w ~n", [N, Result]),
  43. io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p ~n backtrace:~w~n~n", [N, erlang:process_display(self(), backtrace)]);
  44. _ ->
  45. %io:format("IMY************************* ~p ~n", [N]),
  46. ignore
  47. end,
  48. receive
  49. _ ->
  50. do_t2(N + 1)
  51. end.
  52. desult3(N, State) ->
  53. %io:format("IMy*********************desult3 ~p~n",[N]),
  54. do_t3(N).
  55. desult4(N, State) ->
  56. do_t4(N).
  57. t3() ->
  58. Pid = spawn(fun() -> do_t3(100000) end).
  59. t4() ->
  60. Pid = spawn(fun() -> do_t4(100000) end).
  61. do_t3(0) ->
  62. io:format("IMy*********************dfdfdffd33333333");
  63. do_t3(N) ->
  64. case N == 1 orelse N == 99999 of
  65. true ->
  66. erlang:garbage_collect(),
  67. Result = erlang:process_info(self(), [memory, garbage_collection]),
  68. io:format("IMY************************* ~p~n ~w ~n", [N, Result]),
  69. io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p~n backtrace:~p~n~n", [N, erlang:process_display(self(), backtrace)]);
  70. _ ->
  71. ignore
  72. end,
  73. try test:tt9(2) of
  74. Ret ->
  75. desult3(N - 1, Ret)
  76. catch
  77. _:_ ->
  78. desult3(N - 1, error)
  79. end.
  80. do_t4(0) ->
  81. io:format("IMy*********************dfdfdffd44444444444");
  82. do_t4(N) ->
  83. case N == 1 orelse N == 99999 of
  84. true ->
  85. erlang:garbage_collect(),
  86. Result = erlang:process_info(self(), [memory, garbage_collection]),
  87. io:format("IMY************************* ~p ~n ~w ~n", [N, Result]),
  88. io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p ~n backtrace:~w~n~n", [N, erlang:process_display(self(), backtrace)]);
  89. _ ->
  90. %io:format("IMY************************* ~p ~n", [N]),
  91. ignore
  92. end,
  93. Ret1 = try test:tt9(2) of
  94. Ret ->
  95. Ret
  96. catch
  97. _:_ ->
  98. error
  99. end,
  100. do_t4(N - 1).
  101. do_t5(0) ->
  102. io:format("IMy*********************dfdfdffd55555555555555");
  103. do_t5(N) ->
  104. case N == 1 orelse N == 99999 of
  105. true ->
  106. erlang:garbage_collect(),
  107. Result = erlang:process_info(self(), [memory, garbage_collection]),
  108. io:format("IMY************************* ~p ~n ~w ~n", [N, Result]),
  109. io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p ~n backtrace:~w~n~n", [N, erlang:process_display(self(), backtrace)]);
  110. _ ->
  111. %io:format("IMY************************* ~p ~n", [N]),
  112. ignore
  113. end,
  114. try test:tt9(2) of
  115. Ret ->
  116. do_t5(N - 1)
  117. catch
  118. _:_ ->
  119. error
  120. end.
  121. do_t6(0) ->
  122. io:format("IMy*********************dfdfdffd55555555555555");
  123. do_t6(N) ->
  124. case N == 1 orelse N == 99999 of
  125. true ->
  126. erlang:garbage_collect(),
  127. Result = erlang:process_info(self(), [memory, garbage_collection]),
  128. io:format("IMY************************* ~p ~n ~w ~n", [N, Result]);
  129. %io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p ~n backtrace:~w~n~n", [N, erlang:process_display(self(), backtrace)]);
  130. _ ->
  131. %io:format("IMY************************* ~p ~n", [N]),
  132. ignore
  133. end,
  134. try test:tt9(2) of
  135. Ret ->
  136. do_t6(N - 1)
  137. catch
  138. _:_ ->
  139. error
  140. %after
  141. % ok
  142. end.
  143. do_t7(0) ->
  144. io:format("IMy********************11111");
  145. do_t7(N) ->
  146. io:format("IMy********************22222"),
  147. try test:tt9(2) of
  148. _Ret ->
  149. io:format("IMy********************3333"),
  150. do_t7(N - 1)
  151. catch
  152. throw:ret ->
  153. io:format("IMy********************4444"),
  154. do_t7(N - 1);
  155. _:_ ->
  156. io:format("IMy********************5555"),
  157. error
  158. end.