Deleted Added
sdiff udiff text old ( 7490:1803e46ddf57 ) new ( 7491:e8ff1fb26dbc )
full compact
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;

--- 413 unchanged lines hidden (view full) ---

422void
423Serializable::unserialize(Checkpoint *cp, const string &section)
424{
425}
426
427void
428Serializable::serializeAll(const string &cpt_dir)
429{
430 string dir = Checkpoint::setDir(cpt_dir);
431 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
432 fatal("couldn't mkdir %s\n", dir);
433
434 string cpt_file = dir + Checkpoint::baseFilename;
435 ofstream outstream(cpt_file.c_str());
436 time_t t = time(NULL);
437 if (!outstream.is_open())
438 fatal("Unable to open file %s for writing\n", cpt_file.c_str());
439 outstream << "## checkpoint generated: " << ctime(&t);
440
441 globals.serialize(outstream);
442 SimObject::serializeAll(outstream);
443}
444
445void
446Serializable::unserializeAll(const string &cpt_dir)
447{
448 string dir = Checkpoint::setDir(cpt_dir);
449
450 DPRINTFR(Config, "Loading checkpoint dir '%s'\n", dir);
451 Checkpoint *cp = new Checkpoint(dir);
452 unserializeGlobals(cp);
453 SimObject::unserializeAll(cp);
454}
455
456void
457Serializable::unserializeGlobals(Checkpoint *cp)
458{
459 globals.unserialize(cp);
460}
461
462void
463debug_serialize(const string &cpt_dir)
464{
465 Serializable::serializeAll(cpt_dir);
466}
467
468
469////////////////////////////////////////////////////////////////////////
470//

--- 52 unchanged lines hidden (view full) ---

523Serializable::create(Checkpoint *cp, const string &section)
524{
525 Serializable *object = SerializableClass::createObject(cp, section);
526 object->unserialize(cp, section);
527 return object;
528}
529
530
531const char *Checkpoint::baseFilename = "m5.cpt";
532
533string Checkpoint::currentDirectory;
534
535string
536Checkpoint::setDir(const string &name)
537{
538 // use csprintf to insert curTick into directory name if it
539 // appears to have a format placeholder in it.
540 currentDirectory = (name.find("%") != string::npos) ?
541 csprintf(name, curTick) : name;
542 if (currentDirectory[currentDirectory.size() - 1] != '/')
543 currentDirectory += "/";
544 return currentDirectory;
545}
546
547string
548Checkpoint::dir()
549{
550 return currentDirectory;
551}
552
553
554Checkpoint::Checkpoint(const string &cpt_dir)
555 : db(new IniFile), cptDir(cpt_dir)
556{
557 string filename = cpt_dir + "/" + Checkpoint::baseFilename;
558 if (!db->load(filename)) {
559 fatal("Can't load checkpoint file '%s'\n", filename);
560 }
561}
562
563
564bool

--- 25 unchanged lines hidden ---