mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 02:45:51 +00:00
first commit of duality
This commit is contained in:
parent
71275652a7
commit
8488ca24d2
14 changed files with 7305 additions and 5 deletions
201
src/duality/duality_profiling.cpp
Executable file
201
src/duality/duality_profiling.cpp
Executable file
|
@ -0,0 +1,201 @@
|
|||
/*++
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
duality_profiling.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
collection performance information for duality
|
||||
|
||||
Author:
|
||||
|
||||
Ken McMillan (kenmcmil)
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
// include "Windows.h"
|
||||
|
||||
|
||||
#if 0
|
||||
typedef __int64 clock_t;
|
||||
|
||||
static clock_t current_time(){
|
||||
LARGE_INTEGER lpPerformanceCount;
|
||||
lpPerformanceCount.QuadPart = 0;
|
||||
QueryPerformanceCounter(&lpPerformanceCount);
|
||||
return lpPerformanceCount.QuadPart;
|
||||
}
|
||||
|
||||
static void output_time(std::ostream &os, clock_t time){
|
||||
LARGE_INTEGER lpFrequency;
|
||||
lpFrequency.QuadPart = 1;
|
||||
QueryPerformanceFrequency(&lpFrequency);
|
||||
os << ((double)time)/lpFrequency.QuadPart;
|
||||
}
|
||||
#else
|
||||
|
||||
typedef double clock_t;
|
||||
|
||||
static clock_t current_time(){
|
||||
FILETIME lpCreationTime;
|
||||
FILETIME lpExitTime;
|
||||
FILETIME lpKernelTime;
|
||||
FILETIME lpUserTime;
|
||||
|
||||
GetProcessTimes( GetCurrentProcess(),
|
||||
&lpCreationTime, &lpExitTime, &lpKernelTime, &lpUserTime );
|
||||
|
||||
|
||||
double usr_time = ((double) lpUserTime.dwLowDateTime)/10000000. +
|
||||
((double) lpUserTime.dwHighDateTime)/(10000000. * pow(2.0,32.0));
|
||||
return usr_time;
|
||||
}
|
||||
|
||||
static void output_time(std::ostream &os, clock_t time){
|
||||
os << time;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/times.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
static clock_t current_time(){
|
||||
#if 0
|
||||
struct tms buf;
|
||||
times(&buf);
|
||||
return buf.tms_utime;
|
||||
#else
|
||||
struct rusage r;
|
||||
getrusage(RUSAGE_SELF, &r);
|
||||
return 1000 * r.ru_utime.tv_sec + r.ru_utime.tv_usec / 1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void output_time(std::ostream &os, clock_t time){
|
||||
#if 0
|
||||
os << ((double)time)/sysconf(_SC_CLK_TCK);
|
||||
#else
|
||||
os << ((double)time)/1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace Duality {
|
||||
|
||||
void show_time(){
|
||||
output_time(std::cout,current_time());
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
typedef std::map<const char*, struct node> nmap;
|
||||
|
||||
struct node {
|
||||
std::string name;
|
||||
clock_t time;
|
||||
clock_t start_time;
|
||||
nmap sub;
|
||||
struct node *parent;
|
||||
|
||||
node();
|
||||
} top;
|
||||
|
||||
node::node(){
|
||||
time = 0;
|
||||
parent = 0;
|
||||
}
|
||||
|
||||
struct node *current;
|
||||
|
||||
struct init {
|
||||
init(){
|
||||
top.name = "TOTAL";
|
||||
current = ⊤
|
||||
}
|
||||
} initializer;
|
||||
|
||||
struct time_entry {
|
||||
clock_t t;
|
||||
time_entry(){t = 0;};
|
||||
void add(clock_t incr){t += incr;}
|
||||
};
|
||||
|
||||
struct ltstr
|
||||
{
|
||||
bool operator()(const char* s1, const char* s2) const
|
||||
{
|
||||
return strcmp(s1, s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<const char*, time_entry, ltstr> tmap;
|
||||
|
||||
static std::ostream *pfs;
|
||||
|
||||
void print_node(node &top, int indent, tmap &totals){
|
||||
for(int i = 0; i < indent; i++) (*pfs) << " ";
|
||||
(*pfs) << top.name;
|
||||
int dots = 70 - 2 * indent - top.name.size();
|
||||
for(int i = 0; i <dots; i++) (*pfs) << ".";
|
||||
output_time(*pfs, top.time);
|
||||
(*pfs) << std::endl;
|
||||
if(indent != 0)totals[top.name.c_str()].add(top.time);
|
||||
for(nmap::iterator it = top.sub.begin(); it != top.sub.end(); it++)
|
||||
print_node(it->second,indent+1,totals);
|
||||
}
|
||||
|
||||
void print_profile(std::ostream &os) {
|
||||
pfs = &os;
|
||||
top.time = 0;
|
||||
for(nmap::iterator it = top.sub.begin(); it != top.sub.end(); it++)
|
||||
top.time += it->second.time;
|
||||
tmap totals;
|
||||
print_node(top,0,totals);
|
||||
(*pfs) << "TOTALS:" << std::endl;
|
||||
for(tmap::iterator it = totals.begin(); it != totals.end(); it++){
|
||||
(*pfs) << (it->first) << " ";
|
||||
output_time(*pfs, it->second.t);
|
||||
(*pfs) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void timer_start(const char *name){
|
||||
node &child = current->sub[name];
|
||||
if(child.name.empty()){ // a new node
|
||||
child.parent = current;
|
||||
child.name = name;
|
||||
}
|
||||
child.start_time = current_time();
|
||||
current = &child;
|
||||
}
|
||||
|
||||
void timer_stop(const char *name){
|
||||
if(current->name != name || !current->parent){
|
||||
std::cerr << "imbalanced timer_start and timer_stop";
|
||||
exit(1);
|
||||
}
|
||||
current->time += (current_time() - current->start_time);
|
||||
current = current->parent;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue