gem5  v22.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 volatile int stop = false;
40 
41 void
42 handle_alarm(int signal)
43 {
44  stop = true;
45 }
46 
47 void
48 do_test(int seconds)
49 {
50  stop = false;
51  alarm(seconds);
52 }
53 
54 int
56 {
57  std::stringstream result;
58  int iterations = 0;
59 
60  signal(SIGALRM, handle_alarm);
61 
62  do_test(10);
63  while (!stop) {
64  std::stringstream result;
65  gem5::ccprintf(result,
66  "this is a %s of %d iterations %3.2f %p\n",
67  "test", iterations, 51.934, &result);
68 
69  iterations += 1;
70  }
71 
73  "completed %d iterations of ccprintf in 10s, %f iterations/s\n",
74  iterations, iterations / 10.0);
75 
76  do_test(10);
77  while (!stop) {
78  char result[1024];
79  int dummy;
80  sprintf(result,
81  "this is a %s of %d iterations %3.2f %p\n",
82  "test", iterations, 51.934, &dummy);
83 
84  iterations += 1;
85  }
86 
88  "completed %d iterations of sprintf in 10s, %f iterations/s\n",
89  iterations, iterations / 10.0);
90 
91  return 0;
92 }
volatile int stop
Definition: cprintftime.cc:39
void do_test(int seconds)
Definition: cprintftime.cc:48
int main()
Definition: cprintftime.cc:55
void handle_alarm(int signal)
Definition: cprintftime.cc:42
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1