Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2016 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarsource.sonarqube.perf;
  21. import org.apache.commons.lang.StringUtils;
  22. import java.util.List;
  23. import java.util.regex.Matcher;
  24. import java.util.regex.Pattern;
  25. public class MavenLogs {
  26. /**
  27. * Total time: 6.015s
  28. * Total time: 3:14.025s
  29. */
  30. public static Long extractTotalTime(String logs) {
  31. Pattern pattern = Pattern.compile(".*Total time: (\\d*:)?(\\d+).(\\d+)s.*");
  32. Matcher matcher = pattern.matcher(logs);
  33. if (matcher.matches()) {
  34. String minutes = StringUtils.defaultIfBlank(StringUtils.removeEnd(matcher.group(1), ":"), "0");
  35. String seconds = StringUtils.defaultIfBlank(matcher.group(2), "0");
  36. String millis = StringUtils.defaultIfBlank(matcher.group(3), "0");
  37. return (Long.parseLong(minutes) * 60000) + (Long.parseLong(seconds) * 1000) + Long.parseLong(millis);
  38. }
  39. return null;
  40. }
  41. /**
  42. * Final Memory: 68M/190M
  43. */
  44. public static Long extractEndMemory(String logs) {
  45. return extractLong(logs, ".*Final Memory: (\\d+)M/[\\d]+M.*");
  46. }
  47. public static Long extractMaxMemory(String logs) {
  48. return extractLong(logs, ".*Final Memory: [\\d]+M/(\\d+)M.*");
  49. }
  50. private static Long extractLong(String logs, String format) {
  51. Pattern pattern = Pattern.compile(format);
  52. Matcher matcher = pattern.matcher(logs);
  53. if (matcher.matches()) {
  54. String s = matcher.group(1);
  55. return Long.parseLong(s);
  56. }
  57. return null;
  58. }
  59. /**
  60. * 2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
  61. */
  62. public static Long extractComputationTotalTime(List<String> logs) {
  63. Pattern pattern = Pattern.compile(".*INFO.*Executed task.* \\| time=(\\d+)ms.*");
  64. for (int i = logs.size() - 1; i >= 0; i--) {
  65. String line = logs.get(i);
  66. Matcher matcher = pattern.matcher(line);
  67. if (matcher.matches()) {
  68. String duration = matcher.group(1);
  69. return Long.parseLong(duration);
  70. }
  71. }
  72. return null;
  73. }
  74. }