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 setCheckpointDir(cpt_dir);
431 string dir = Checkpoint::dir();
432 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
433 fatal("couldn't mkdir %s\n", dir);
434
435 string cpt_file = dir + Checkpoint::baseFilename;
436 ofstream outstream(cpt_file.c_str());
437 time_t t = time(NULL);
438 if (!outstream.is_open())
439 fatal("Unable to open file %s for writing\n", cpt_file.c_str());
440 outstream << "## checkpoint generated: " << ctime(&t);
441
442 globals.serialize(outstream);
443 SimObject::serializeAll(outstream);
444}
445
446void
447Serializable::unserializeAll(const string &cpt_dir)
448{
449 setCheckpointDir(cpt_dir);
450 string dir = Checkpoint::dir();
451 string cpt_file = dir + Checkpoint::baseFilename;
452 string section = "";
453
454 DPRINTFR(Config, "Loading checkpoint dir '%s'\n",
455 dir);
456 Checkpoint *cp = new Checkpoint(dir, section);
457 unserializeGlobals(cp);
458 SimObject::unserializeAll(cp);
459}
460
461void
462Serializable::unserializeGlobals(Checkpoint *cp)
463{
464 globals.unserialize(cp);
465}
466
467const char *Checkpoint::baseFilename = "m5.cpt";
468
469static string checkpointDirBase;
470
471void
472setCheckpointDir(const string &name)
473{
474 checkpointDirBase = name;
475 if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
476 checkpointDirBase += "/";
477}
478
479string
480Checkpoint::dir()
481{
482 // use csprintf to insert curTick into directory name if it
483 // appears to have a format placeholder in it.
484 return (checkpointDirBase.find("%") != string::npos) ?
485 csprintf(checkpointDirBase, curTick) : checkpointDirBase;
486}
487
488void
489debug_serialize(const string &cpt_dir)
490{
491 Serializable::serializeAll(cpt_dir);
492}
493
494
495////////////////////////////////////////////////////////////////////////
496//

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

549Serializable::create(Checkpoint *cp, const string &section)
550{
551 Serializable *object = SerializableClass::createObject(cp, section);
552 object->unserialize(cp, section);
553 return object;
554}
555
556
557Checkpoint::Checkpoint(const string &cpt_dir, const string &path)
558 : db(new IniFile), basePath(path), cptDir(cpt_dir)
559{
560 string filename = cpt_dir + "/" + Checkpoint::baseFilename;
561 if (!db->load(filename)) {
562 fatal("Can't load checkpoint file '%s'\n", filename);
563 }
564}
565
566
567bool

--- 25 unchanged lines hidden ---