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

Generated on Tue Sep 21 2021 12:24:56 for gem5 by doxygen 1.8.17