Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
perf-counters-test.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <iostream>
18 #include <gtest/gtest.h>
19 #include "common/init.h"
20 #include "util/disk-info.h"
21 #include "util/perf-counters.h"
22 
23 #include "common/names.h"
24 
25 namespace impala {
26 
27 TEST(PerfCounterTest, Basic) {
28  PerfCounters counters;
29  EXPECT_TRUE(counters.AddDefaultCounters());
30 
31  counters.Snapshot("Before");
32  double result = 0;
33  for (int i = 0; i < 1000000; i++) {
34  double d1 = rand() / (double) RAND_MAX;
35  double d2 = rand() / (double) RAND_MAX;
36  result = d1*d1 + d2*d2;
37  }
38  counters.Snapshot("After");
39 
40  for (int i = 0; i < 1000000; i++) {
41  double d1 = rand() / (double) RAND_MAX;
42  double d2 = rand() / (double) RAND_MAX;
43  result = d1*d1 + d2*d2;
44  }
45  counters.Snapshot("After2");
46  counters.PrettyPrint(&cout);
47 }
48 
49 TEST(CpuInfoTest, Basic) {
50  cout << CpuInfo::DebugString();
51 }
52 
53 TEST(DiskInfoTest, Basic) {
54  cout << DiskInfo::DebugString();
55  cout << "Device name for disk 0: " << DiskInfo::device_name(0) << endl;
56 
57  int disk_id_home_dir = DiskInfo::disk_id("/home");
58  cout << "Device name for '/home': " << DiskInfo::device_name(disk_id_home_dir) << endl;
59 }
60 
61 }
62 
63 int main(int argc, char **argv) {
64  InitCommonRuntime(argc, argv, false);
65  ::testing::InitGoogleTest(&argc, argv);
66  return RUN_ALL_TESTS();
67 }
68 
static const std::string & device_name(int disk_id)
Returns the device name (e.g. sda) for disk_id.
Definition: disk-info.h:64
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
Definition: init.cc:122
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
void PrettyPrint(std::ostream *out) const
Prints out the names and results for all snapshots to 'out'.
int main(int argc, char **argv)
void Snapshot(const std::string &name="")
static std::string DebugString()
Definition: disk-info.cc:127
static std::string DebugString()
Definition: cpu-info.cc:155
static int disk_id(const char *path)
Definition: disk-info.cc:119