TraceUtils.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // StarPU --- Runtime system for heterogeneous multicore architectures.
  2. //
  3. // Copyright (C) 2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. //
  5. // StarPU is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation; either version 2.1 of the License, or (at
  8. // your option) any later version.
  9. //
  10. // StarPU is distributed in the hope that it will be useful, but
  11. // WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. //
  14. // See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. //
  16. package starpu.handlers;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19. import java.io.BufferedReader;
  20. import java.io.FileReader;
  21. import java.io.IOException;
  22. import java.io.InputStreamReader;
  23. import java.util.Arrays;
  24. import java.util.Random;
  25. import javax.swing.BoxLayout;
  26. import javax.swing.JButton;
  27. import javax.swing.JFrame;
  28. import javax.swing.JLabel;
  29. import javax.swing.JPanel;
  30. public class TraceUtils {
  31. private static int x = 1000 + new Random().nextInt(9999);
  32. public static void runCommand(String[] command) throws Exception
  33. {
  34. System.out.println("Running command " + Arrays.toString(command));
  35. Process p = Runtime.getRuntime().exec(command);
  36. String line;
  37. BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
  38. while ((line = in.readLine()) != null) {
  39. System.out.println(line);
  40. }
  41. in.close();
  42. }
  43. public static String getRandomDirectoryName()
  44. {
  45. return "traces_" + x;
  46. }
  47. public static void displayMessage(String message)
  48. {
  49. final JFrame f = new JFrame("StarPU Message");
  50. JLabel l = new JLabel(message);
  51. JButton b19 = new JButton("OK");
  52. b19.addActionListener(new ActionListener()
  53. {
  54. public void actionPerformed(ActionEvent evt)
  55. {
  56. f.setVisible(false);
  57. }
  58. });
  59. JPanel p = new JPanel();
  60. p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  61. p.add(l);
  62. p.add(b19);
  63. f.add(p);
  64. f.pack();
  65. f.setVisible(true);
  66. }
  67. public static String readFileToString(String filename) throws IOException
  68. {
  69. BufferedReader reader = new BufferedReader(new FileReader(filename));
  70. StringBuilder stringBuilder = new StringBuilder();
  71. char[] buffer = new char[10];
  72. while (reader.read(buffer) != -1) {
  73. stringBuilder.append(new String(buffer));
  74. buffer = new char[10];
  75. }
  76. reader.close();
  77. return stringBuilder.toString();
  78. }
  79. }