accum-compile-times.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //=======================================================================
  2. // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //=======================================================================
  8. #include <boost/config.hpp>
  9. #include <fstream>
  10. #include <iostream>
  11. #include <numeric>
  12. #include <iterator>
  13. #include <string>
  14. #include <boost/graph/adjacency_list.hpp>
  15. #include <boost/graph/property_iter_range.hpp>
  16. namespace std
  17. {
  18. template < typename T >
  19. std::istream& operator >> (std::istream& in, std::pair < T, T > &p)
  20. {
  21. in >> p.first >> p.second;
  22. return in;
  23. }
  24. }
  25. namespace boost
  26. {
  27. enum vertex_compile_cost_t { vertex_compile_cost };
  28. BOOST_INSTALL_PROPERTY(vertex, compile_cost);
  29. }
  30. using namespace boost;
  31. typedef adjacency_list< listS, // Store out-edges of each vertex in a std::list
  32. listS, // Store vertex set in a std::list
  33. directedS, // The file dependency graph is directed
  34. // vertex properties
  35. property < vertex_name_t, std::string,
  36. property < vertex_compile_cost_t, float,
  37. property < vertex_distance_t, float,
  38. property < vertex_color_t, default_color_type > > > >,
  39. // an edge property
  40. property < edge_weight_t, float > >
  41. file_dep_graph2;
  42. typedef graph_traits<file_dep_graph2>::vertex_descriptor vertex_t;
  43. typedef graph_traits<file_dep_graph2>::edge_descriptor edge_t;
  44. int
  45. main(int argc, const char** argv)
  46. {
  47. std::ifstream file_in(argc >= 2 ? argv[1] : "makefile-dependencies.dat");
  48. typedef graph_traits<file_dep_graph2>::vertices_size_type size_type;
  49. size_type n_vertices;
  50. file_in >> n_vertices; // read in number of vertices
  51. #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
  52. // std::istream_iterator causes trouble with VC++
  53. std::vector<vertex_t> id2vertex;
  54. file_dep_graph2 g;
  55. for (std::size_t i = 0; i < n_vertices; ++i)
  56. id2vertex.push_back(add_vertex(g));
  57. std::pair<size_type, size_type> p;
  58. while (file_in >> p)
  59. add_edge(id2vertex[p.first], id2vertex[p.second], g);
  60. #else
  61. std::istream_iterator<std::pair<size_type, size_type> >
  62. input_begin(file_in), input_end;
  63. file_dep_graph2 g(input_begin, input_end, n_vertices);
  64. #endif
  65. typedef property_map < file_dep_graph2, vertex_name_t >::type name_map_t;
  66. typedef property_map < file_dep_graph2, vertex_compile_cost_t >::type
  67. compile_cost_map_t;
  68. name_map_t name_map = get(vertex_name, g);
  69. compile_cost_map_t compile_cost_map = get(vertex_compile_cost, g);
  70. std::ifstream name_in(argc >= 3 ? argv[2] : "makefile-target-names.dat");
  71. std::ifstream compile_cost_in(argc >= 4 ? argv[3] : "target-compile-costs.dat");
  72. graph_traits < file_dep_graph2 >::vertex_iterator vi, vi_end;
  73. for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
  74. name_in >> name_map[*vi];
  75. compile_cost_in >> compile_cost_map[*vi];
  76. }
  77. graph_property_iter_range < file_dep_graph2,
  78. vertex_compile_cost_t >::iterator ci, ci_end;
  79. boost::tie(ci, ci_end) = get_property_iter_range(g, vertex_compile_cost);
  80. std::cout << "total (sequential) compile time: "
  81. << std::accumulate(ci, ci_end, 0.0) << std::endl;
  82. return 0;
  83. }