gem5  v20.0.0.3
cprintftime.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <iostream>
30 #include <list>
31 #include <sstream>
32 #include <string>
33 
34 #include "base/cprintf.hh"
35 
36 using namespace std;
37 
38 volatile int stop = false;
39 
40 void
41 handle_alarm(int signal)
42 {
43  stop = true;
44 }
45 
46 void
47 do_test(int seconds)
48 {
49  stop = false;
50  alarm(seconds);
51 }
52 
53 int
55 {
56  stringstream result;
57  int iterations = 0;
58 
59  signal(SIGALRM, handle_alarm);
60 
61  do_test(10);
62  while (!stop) {
63  stringstream result;
64  ccprintf(result,
65  "this is a %s of %d iterations %3.2f %#x\n",
66  "test", iterations, 51.934, &result);
67 
68  iterations += 1;
69  }
70 
71  cprintf("completed %d iterations of ccprintf in 10s, %f iterations/s\n",
72  iterations, iterations / 10.0);
73 
74  do_test(10);
75  while (!stop) {
76  char result[1024];
77  sprintf(result,
78  "this is a %s of %d iterations %3.2f %#x\n",
79  "test", iterations, 51.934, &result);
80 
81  iterations += 1;
82  }
83 
84  cprintf("completed %d iterations of sprintf in 10s, %f iterations/s\n",
85  iterations, iterations / 10.0);
86 
87  return 0;
88 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
void handle_alarm(int signal)
Definition: cprintftime.cc:41
void do_test(int seconds)
Definition: cprintftime.cc:47
volatile int stop
Definition: cprintftime.cc:38
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
int main()
Definition: cprintftime.cc:54

Generated on Fri Jul 3 2020 15:53:08 for gem5 by doxygen 1.8.13