GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tracepoint.cpp
1 /*
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #include <limits>
25 #include <string>
26 #include <graphlab/logger/assertions.hpp>
27 #include <graphlab/util/tracepoint.hpp>
28 #include <graphlab/parallel/pthread_tools.hpp>
29 #include <boost/unordered_map.hpp>
30 
31 
32 namespace graphlab {
33 
34 void trace_count::print(std::ostream& out, unsigned long long tpersec) const {
35  if (tpersec == 0) {
36  out << name << ": " << description << "\n";
37  out << "Events:\t" << count.value << "\n";
38  out << "Total:\t" << total.value << "ticks \n";
39  if (count.value > 0) {
40  out << "Mean:\t" << (double)total.value / count.value << "ticks \n";
41  out << "Min:\t" << minimum << "ticks \n";
42  out << "Max:\t" << maximum << "ticks \n";
43  }
44  }
45  else {
46  double tperms = (double)tpersec / 1000;
47  out << name << ": " << description << "\n";
48  out << "Events:\t" << count.value << "\n";
49  out << "Total:\t" << (double)total.value / tperms << " ms \n";
50  if (count.value > 0) {
51  out << "Mean:\t" << (double)total.value / count.value / tperms << " ms \n";
52  out << "Min:\t" << (double)minimum / tperms << " ms \n";
53  out << "Max:\t" << (double)maximum / tperms << " ms \n";
54  }
55  }
56 }
57 
58 
59 static mutex printlock;
60 
61 trace_count::~trace_count() {
62 #ifdef USE_TRACEPOINT
63  printlock.lock();
64  print(std::cout, estimate_ticks_per_second());
65  std::cout.flush();
66  printlock.unlock();
67 #endif
68 }
69 
70 } // namespace graphlab
71