Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / rst / example / rstexample.C
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: rstexample.C
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/types.h>
24#include <string.h>
25
26#include "rstf/rstf.h"
27#include "rstzip/Rstzip.H"
28
29const char usage[] = "rstexample <input-trace-file>";
30
31
32int main(int argc, char **argv)
33{
34 // argv[1] must be input file
35 const char * ifname = NULL;
36
37 int i=1;
38 while(i<argc) {
39 const char * arg = argv[i++];
40 if (strcmp(arg, "-h") == 0) {
41 printf("Usage: %s\n", usage);
42 exit(0);
43 } else if (ifname != NULL) {
44 fprintf(stderr, "ERROR: rstexample: input file %s already specified\nUsage: %s\n", ifname, usage);
45 exit(1);
46 } else {
47 ifname = arg;
48 }
49 }
50
51 if (ifname == NULL) {
52 printf("Usage: %s\n", usage);
53 exit(0);
54 }
55
56 // create an rstzip instance
57 Rstzip * rz = new Rstzip;
58 int rv=rz->open(ifname, "r", "verbose=0");
59 if (rv != RSTZIP_OK) {
60 fprintf(stderr, "ERROR: rstexample: Rstzip error opening input file %s\n", ifname);
61 exit(1);
62 }
63
64 const int max_ncpu=1<<10; // RST supports 10-bit cpuids
65 int64_t icounts[max_ncpu];
66 memset(icounts, 0, max_ncpu*sizeof(int64_t));
67 int64_t total_icount = 0;
68
69 int nrecs;
70 rstf_unionT buf[rstzip_opt_buffersize];
71 while((nrecs = rz->decompress(buf, rstzip_opt_buffersize)) != 0) {
72 int i;
73 for (i=0; i<nrecs; i++) {
74 rstf_unionT * rp = buf+i;
75 if (rp->proto.rtype == INSTR_T) {
76 total_icount++;
77 int cpuid = rstf_instrT_get_cpuid(&(rp->instr));
78 icounts[cpuid]++;
79 }
80 }
81 }
82 rz->close();
83 delete rz;
84 rz=NULL;
85
86 printf("Total icount=%lld\n", total_icount);
87 for (i=0; i<max_ncpu; i++) {
88 if (icounts[i] > 0) {
89 printf("cpu%d: icount=%lld\n", i, icounts[i]);
90 }
91 }
92} // main()