self.fs_chance.dir_chances[upper_dir].addFile(path) self.cache.check(path) ##miss or hit it #hit the file requested self.fs_chance.dir_chances[upper_dir].hitFile(path) #miss all of the others self.fs_chance.dir_chances[upper_dir].missExcept(path) highest_chancer = self.get_highest_chancer(upper_dir) self.ticks += 1 def exit(self): for dc_path in self.fs_chance.dir_chances: dc = self.fs_chance.dir_chances[dc_path] for fname in dc.file_chances: if dc.file_chances[fname][0] > 5: pass #print dc print str(self.clear_rate) + ": " + str(self.cache) sr = pardus_stats.StrategyRunner(os.getcwd() + "/..") for i in range(1, 1000): ps = PrintStrategy(i * 100) sr.start(ps)
class NaiveStrategy(pardus_stats.Strategy): def __init__(self, clear_rate): self.clear_rate = clear_rate self.cache = Cache(clear_rate) def start(self, fs_chance): self.ticks = 0 self.cache.clear() self.fs_chance = fs_chance self.shutoff_switch = False def tick(self, record): path = record.syscall.arg upper_dir = self.fs_chance.get_dir_from_path(path) syscall = record.syscall.syscall program_path = record.program_path if (not (syscall in ["open", "execve", "stat" ])) or self.is_nonsense(path): return self.cache.check(path) return (self.cache.hits, self.cache.misses) if __name__ == "__main__": sr = pardus_stats.StrategyRunner(os.getcwd() + "/..", "/seer-data/small-sample") for i in range(1, 2): ps = NaiveStrategy(i * 10) sr.start(ps) print " Hits: ", ps.cache.hits, "Misses: ", ps.cache.misses