gem5  v20.1.0.0
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 <unistd.h>
30 
31 #include <csignal>
32 #include <iostream>
33 #include <list>
34 #include <sstream>
35 #include <string>
36 
37 #include "base/cprintf.hh"
38 
39 using namespace std;
40 
41 volatile int stop = false;
42 
43 void
44 handle_alarm(int signal)
45 {
46  stop = true;
47 }
48 
49 void
50 do_test(int seconds)
51 {
52  stop = false;
53  alarm(seconds);
54 }
55 
56 int
58 {
59  stringstream result;
60  int iterations = 0;
61 
62  signal(SIGALRM, handle_alarm);
63 
64  do_test(10);
65  while (!stop) {
66  stringstream result;
67  ccprintf(result,
68  "this is a %s of %d iterations %3.2f %p\n",
69  "test", iterations, 51.934, &result);
70 
71  iterations += 1;
72  }
73 
74  cprintf("completed %d iterations of ccprintf in 10s, %f iterations/s\n",
75  iterations, iterations / 10.0);
76 
77  do_test(10);
78  while (!stop) {
79  char result[1024];
80  sprintf(result,
81  "this is a %s of %d iterations %3.2f %p\n",
82  "test", iterations, 51.934, &result);
83 
84  iterations += 1;
85  }
86 
87  cprintf("completed %d iterations of sprintf in 10s, %f iterations/s\n",
88  iterations, iterations / 10.0);
89 
90  return 0;
91 }
do_test
void do_test(int seconds)
Definition: cprintftime.cc:50
stop
volatile int stop
Definition: cprintftime.cc:41
cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
cprintf.hh
main
int main()
Definition: cprintftime.cc:57
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
handle_alarm
void handle_alarm(int signal)
Definition: cprintftime.cc:44

Generated on Wed Sep 30 2020 14:02:18 for gem5 by doxygen 1.8.17